[Libav-user] How to get max/min frame rate from variable frame rate video?

Jason C jason.cipriani at gmail.com
Tue Nov 1 18:23:37 EET 2016

On Mon, Oct 31, 2016 at 10:07 PM, YIRAN LI <mrfun.china at gmail.com> wrote:

> MediaInfo can show max/min frame rate for a variable frame rate video
> ‚Äč
> Can I get these info from AVCodec, AVCodecContext or AVFormatContext?

>From what I can see in the source, MediaInfo can only calculate min/max
frame rate in two situations:

For MPEG4 containers, in Source/MediaInfo/Multiple/File_Mpeg4.cpp, in very
specific situations:

    if (Temp->second.stts_Max)
        Fill(Stream_Video, StreamPos_Last, Video_FrameRate_Minimum,
((float)Temp->second.mdhd_TimeScale)/Temp->second.stts_Max, 3, true);
    if (Temp->second.stts_Min)
        Fill(Stream_Video, StreamPos_Last, Video_FrameRate_Maximum,
((float)Temp->second.mdhd_TimeScale)/Temp->second.stts_Min, 3, true);

For AVI containers, in Source/MediaInfo/Multiple/File_Riff.cpp, it appears
to just make something up; logic that is probably justified but beyond my
personal understanding:

    float32 FrameRateF=FrameRate.To_float32();
    Fill(Stream_Video, StreamPos_Last, Video_FrameRate_Minimum,
FrameRateF/5, 3, true);
    Fill(Stream_Video, StreamPos_Last, Video_FrameRate_Maximum,
FrameRateF/4, 3, true);

In the MPEG4 case, stts_Min and stts_Max are filled by scanning the entire
file in File_Mpeg4_Elements.cpp.

In the AVI case, FrameRate is filled in various places in
File_Riff_Elements.cpp, I think by just reading a value from the file

So you would have to do something similar. To accurately determine the
value in all cases you'll have to demux the stream and examine all the PTS
values. Other than that, there are no ffmpeg struct fields that give this
information and no way for it to know without reading stream timestamps.

You can probably get away with just demuxing and taking a look at packet
PTS values, rather than decoding fully, if you want to do as quick of an
analysis as possible, although don't quote me on that, just test it: a lot
of video decoding things are beyond my understanding. Some confirmation
from somebody else here would be nice.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20161101/4fe2e8ae/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Capture.PNG
Type: image/png
Size: 3356 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20161101/4fe2e8ae/attachment.png>

More information about the Libav-user mailing list