Take the 2-minute tour ×
Video Production Stack Exchange is a question and answer site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation. It's 100% free, no registration required.

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?

share|improve this question
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. –  LordNeckbeard Jun 11 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 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 at 8:21

1 Answer 1

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.

share|improve this answer
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 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 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 at 10:34
    
@jmm that's unfortunate. I'm out of other ideas. –  AJ Henderson Jun 13 at 13:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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