[Libav-user] Encoding with variable frame rate

Thomas Worth dev at rarevision.com
Tue May 21 18:40:07 CEST 2013


> 1. Does FFmpeg support variable frame rate, or not?

If you can playback or re-encode an iPhone video, then yes. MOV/MP4 is
_not_ a fixed frame rate format. In other words, there is no "FPS"
field/atom in MOV. You set some arbitrary timebase, and the stts atom
contains the durations for each of the frames/samples per this
timebase. If the frames happen to be all the same timing, then
congratulations! Your video has a "fixed" frame rate. However, since
the iPhone's MOV writer for some reason uses a timebase of 600, it is
impossible to get enough precision to represent "29.97" for each frame
perfectly. The only thing to do in this case is to vary each frame's
timing slightly to achieve a "nominal" rate of 29.97 (which is what
QuickTime Player is always showing). This is why sometimes QuickTime
player shows "30.01" or some stupid number for FPS because it's
arrived at that figure after doing its math on the timing values in
stts. For editing apps, usually there is only one entry in stts, so
all frames play at the same rate (fixed). But, all apps reading the
file are still showing a nominal frame rate, not a fixed one.

> 2. If I set the time_base.den on the video codec (let's say to 30 fps), can I fire  say 12fps at the encoder and compensate for that by setting pts/dts such that the timing won't be incorrect?

The timescale in MOV is just a timing reference, not a frame rate.
Your individual frame timing values determine the playback rate, and
the frame rate value shown in any reader. Again, the frame rate can't
be read like a field in a header. It has to be calculated by averaging
all the timing values in stts. I'm not sure what this means for
someone writing with FFmpeg. I've only ever written files for editing
purposes, so I don't use variable timing.

Have you tried varying the "duration" parameter for each frame rather
than only DTS/PTS?


More information about the Libav-user mailing list