[FFmpeg-user] Cutting video at i-frames to avoid recoding

Andy Civil andycivil at gmail.com
Sat Aug 18 23:30:21 CEST 2012


Context: I have some home movies of animals doing cute things, where I left the 
camera running so a good portion is garbage. I want to cut out and keep the good 
parts, but I don't want to re-encode because then it wouldn't feel like the 
'original' footage, as it were. I know that you can't cut a H.264 movie just 
anywhere, because the output file has to start with an i-frame.

I know that FFmpeg can "-vcodec copy" and I know that you can also set "-ss" 
start time and duration; but I don't know if you can do both at once, and if you 
can, how does it behave? (I'm thinking that the GOP could be as many as 300 
frames, and I believe FFmpeg 'only goes forwards' so it is not reasonable to 
think that you could specify a start time and expect it to go BACK in the stream 
to the previous i-frame; that's just not how it works, right?)

So my basic question is: how can I cut a h.264 movie without recoding anything, 
specifying a start and stop time?

It would be perfectly acceptable if the first frames were simply grey, 
containing only the differences - I know this is possible because sometimes on 
youtube, you see videos that have been cut this way; here's an example:
(watch just the first few seconds "are about to perform" before an i-frame comes 
along and clears things up).
It would also be acceptable for FFmpeg to count to the specified time, then wait 
for the next i-frame to arrive before doing the stream copy (I can find my GOP 
and ensure that I add at least that time prior to the cute parts).
It would also be acceptable if I had to use a tool like "FFprobe" with "show 
frames" to locate the exact time of an i-frame, and then use that as my "-ss" time.

Thank you for any insight into this. I know it's similar to Gregory1234's 
question, but I don't think that thread really came to a conclusion.


More information about the ffmpeg-user mailing list