[FFmpeg-user] Cutting video at i-frames to avoid recoding
Andy Civil
andycivil at gmail.com
Sun Sep 2 07:15:40 CEST 2012
On 2012-08-19 11:08 AM, Francois Visagie wrote:
>
> Experiment? You came up with some pretty decent-looking suggestions
> yourself. I suspect your concern is whether ffmpeg will ensure that start
> time and duration coincide in some way with I-frames.
In the end, that's what I did. I'm reporting back, for anyone who searches the
archives for the same information.
Things got a bit easier when I found that 'ffprobe -show_frames' would give tons
of information about frame types and times.
My source file had i-frames at regular 0.5s intervals, and only p-frames
otherwise, so I didn't have the complication of b-frames.
To create an artificially bad situation, I used FFmpeg to produce a 30s file
with a GOP of 300 (an i-frame every 10s at 30fps). I then asked it to 'copy' the
file starting at 5 seconds in.
What I got out was very interesting. The sound frames started at the beginning
of the file at 0s, from 5s into the original just as I had asked. There were NO
video frames at all until the first i-frame, which was originally timed at 10s,
but was now timed at 5s in the new file because of my cut. In a way, this makes
perfect sense, but it seemed odd that I now had a video file which had five
seconds of sound with no picture at the start!
(As a side issue, I noticed that FFmpeg had re-ordered the frames, the original
had a bunch of audio frames, followed by a bunch of video frames; FFmpeg
interleaved them more chronologically.)
I was curious to know how this file would play. VLC obediently played the sound
right from the start (at the 5s point of the original, of course) and continued
to show its orange cone logo on the screen. At the 5s point when the first
i-frame came along, the logo was replaced with the video. It was perfectly
synchronised. This is obviously a good result.
My only remaining concern was that my video editor (I use Vegas) would mess up,
and ignore the frame times, leaving me with audio and video that were 5s out of
synch. When I loaded the file in, I noticed that there was no missing 5s of
video, as there had been on VLC. However, Vegas did not go out of synch, nor did
it cut off the first five seconds of sound: what it did do was to grab that
first i-frame and stretch it back to the start of the file. So the video was
'freeze framed' for five seconds while the audio was playing, then at the 5s
point it continued perfectly.
After these experiments, I'm confident to use FFmpeg to cut the garbage out of
my 'original' footage, but knowing how this works, and having observed the 0.5s
GOP on my original, I will also specify a start time that causes an i-frame to
occur at the start of the cut file, for the cleanest result.
--
Andy
More information about the ffmpeg-user
mailing list