[Libav-user] How to control ffmpeg's key-frame generation?

Quy Pham Sy phamsyquybk at gmail.com
Wed Jan 2 07:30:39 CET 2013


I'm making a segmenter that intervene ffmpeg's write_frame function and
write output data to separate files. Each segmented file contains segment
of about 3 seconds video.

The code does following:

1 - Get transcoded packet
2 - Check if it contains key frame data, if yes goto 3.
3 - Check the duration of current segment, if it exceed 3 seconds, goto 4
4 - Close file, and create new segment, write packet to segment file, goto-1

General speaking, every segment contains at least 3 seconds video data, and
it starts with a key frame.

The problem is that the output video's duration are very different, some
contain 3 seconds, some contain 5 or 6.

I suspect that the problem due to how ffmpeg generate key frames during
transcoding. If the "distance" between two adjacent keyframes are 6s, i got
6 seconds segment.

Here is my questions:

   1.

   is that true that ffmpeg generate keyframes at irregular intervals (and
   interval time can be up to few second (eg. 6)?
   2.

   How can we control the ffmpeg key frame generation? (i guess there
   should be a ffmpeg command's argument for this, -force_key_frames maybe,
   but I'm not sure)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130102/a94a0fa5/attachment.html>


More information about the Libav-user mailing list