I'm producing several versions of a clip (320x180 24 fps and aprox 2Mbps) compressed with h.264 with ffmpeg using Avanti. Each version has different framerate. The video output has a slightly different duration than source:

source - 24 fps - 01:52
10 fps - 01:53
5 fps - 01:53
1 fps - 01:56
0.5 fps - 02:04

Results are the same if use Handbrake. Why is this happening? I'm aware that there are several kind of frames in h.264, what is then ffmpeg doing when I set framerate? Is it setting keyframe interval?

  • 1
    How are you measuring the input and output durations? Also, without your actual ffmpeg commands and the complete console outputs it is impossible to provide an accurate answer.
    – llogan
    Jun 11 '14 at 17:34
  • I'm using Avanti, so I'm not sure of all the actual ffmpeg commands it uses internally, but I am only selecting codec, container, frame size, frame rate and bitrate.
    – jmm
    Jun 12 '14 at 8:11
  • I'm getting durations from player information and from how long does it actually take the player complete reproduction.
    – jmm
    Jun 12 '14 at 8:21

My best guess is that this is due to the length of a group of pictures. h.264 streams are composed of 3 different types of frames. I frames, which contain the full frame, P frames which contain the information that has changed since the previous frame and B frames which are bi-directional and contain information about the changes between previous and future frames.

These frames are used in a fixed order that is repeated. That repeated set is known as a group of pictures. Typical GOP lengths are generally somewhere around 15 frames. At 15 or more FPS, you'll always finish your GOP within one second. At half a frame per second though, it can take up to 7 seconds after your last normal frame for the GOP to finish.

That still doesn't seem to fully explain your 12 extra seconds, but it is possible you are using a longer GOP. I can't think of any other potential causes.

It is also worth noting that under the hood, Handbrake is just a UI for other encoding libraries, one of which is FFMPEG, so that may also help explain the consistent behavior as well.

  • 1
    I don't know the mechanics of it (how ffmpeg handles it), but you can encode using a 'closed GOP' structure or an unclosed one. If you opt that every GOP is closed, the last GOP may be padded out to its native length. In some situations it's mandatory to end with a closed GOP, so this may be the default here.
    – Jim Mack
    Jun 11 '14 at 20:25
  • I've realized that there is somewhat of "starting offset", i.e. video starts with black and there is a soft transition to an image of earth from space, if first non-black frame is aprox at 00:03 in source video, it does not appear until 00:23 in 0.5 fps version and its content come from a frame from 00:04. Maybe this confirms the "GOP-completness theory"... I will do more tests.
    – jmm
    Jun 12 '14 at 8:19
  • 1
    I've performed more tests and GOP size has apparently nothing to do whith my problem. I set -g 0 that, according to ffmpeg.org/ffmpeg.html (section 6. Tips), means an all I-frames video and keep getting extra seconds in output.
    – jmm
    Jun 13 '14 at 10:34
  • @jmm that's unfortunate. I'm out of other ideas.
    – AJ Henderson
    Jun 13 '14 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.