I would like to cut a video at the beginning at any particular timestamp, and it need to be precise, so the nearest key frame is not good enough.
Also, these videos are rather long - an hour or longer - so I would like to avoid re-encoding this altogether if possible, or otherwise only re-encode a minimal fraction of the total duration. Thus, would like to maximise the use of -vcodec copy
.
How can I accomplish this using ffmpeg
?
NOTE: See scenario, and my own rough idea for a possible solution below.
Scenario:
- Original video
- Length of 1:00:00
- Has a key frame every 10s
- Desired cut:
- From 0:01:35 through till the end
- Attempt #1:
- Using
-ss 0:01:35 -i blah.mp4 -vcodec copy
, what results is a file where: - audio starts at 0:01:30
- video also starts at 0:01:30
- this starts both the audio and the video too early
- Using
- using
-i blah.mp4 -ss 0:01:35 -vcodec copy
, what results is a file where:- audio starts at 0:01:35,
- but the video is blank/ black for the first 5 seconds,
- until 0:01:40, when the video starts
- this starts the audio on time, but the video starts too late
Rough idea
- (1) cut 0:01:30 to 0:01:40
- re-encode this to have new key frames, including one at the target time of 0:01:35
- then cut this to get the 5 seconds from 0:01:35 through 0:01:40
- (2) cut 0:01:40 through till the end
- without re-encoding, using
-vcodec copy
- without re-encoding, using
- (3)
ffmpeg concat
the first short clip (the 5 second one) with the second long clip
I know/ can work out the commands for (2) and (3), but am unsure about what commands are needed for (1).