Plans a frame-accurate trim without re-encoding the full clip.
Only the start of a cut needs a keyframe: decoding can't begin mid-GOP without one.
The end of a cut has no such requirement — stream-copying can stop at any frame,
since every frame already copied has everything it needs to decode correctly. That
asymmetry is why this plan never needs more than one encoded segment: re-encode the
head up to the next keyframe, then stream-copy everything after that keyframe straight
through to the requested end, however far away it is.
Parameters
startSeconds: number
Desired trim start in seconds within the source file.
endSeconds: number
Desired trim end in seconds within the source file.
keyframes: number[]
Known keyframe timestamps in seconds within the source file.
Plans a frame-accurate trim without re-encoding the full clip.
Only the start of a cut needs a keyframe: decoding can't begin mid-GOP without one. The end of a cut has no such requirement — stream-copying can stop at any frame, since every frame already copied has everything it needs to decode correctly. That asymmetry is why this plan never needs more than one encoded segment: re-encode the head up to the next keyframe, then stream-copy everything after that keyframe straight through to the requested end, however far away it is.