[Libav-user] Reading correct frame rate (fps) of input video

Taha Ansari mtaha.ansari at gmail.com
Tue May 21 17:04:06 CEST 2013


Hi!

I am trying to read exact values for frame rate (fps) from any input video
file. I have been trying to debug different structures like AVFormatCtx,
etc. but cannot seem to figure it out. For a test case, here is the code I
have managed (just the source snippet, include files etc. are all
understandable):

//---------------------------------------------------------------------------------------------------------------------------------------------------
    // ++ test code begins ++//
    av_register_all();
    avcodec_register_all();
    avformat_network_init();
    avdevice_register_all();
    AVFormatContext *pFormatCtx = NULL;
    pFormatCtx = avformat_alloc_context();
    string finalInputName = "test_input.3gp";
    avformat_open_input(&pFormatCtx, finalInputName.c_str(), NULL, NULL);
    if ( pFormatCtx == NULL            ||
        pFormatCtx->iformat == NULL    )
    {
        return -1;
    }
    // Retrieve stream information
    if(avformat_find_stream_info(pFormatCtx, NULL)<0)
        return -1; // Couldn't find stream information

    // Dump information about file onto standard error
    av_dump_format(pFormatCtx, 0, finalInputName.c_str(), 0);
    // -- test code ends --//
//---------------------------------------------------------------------------------------------------------------------------------------------------

The output it gives me is (in debug console):

//---------------------------------------------------------------------------------------------------------------------------------------------------
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_input.3gp':
  Metadata:
    major_brand     : 3gp4
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2013-05-20 11:54:39
  Duration: 00:00:23.77, start: 0.000000, bitrate: 5882 kb/s
    Stream #0:0(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v /
0x7634706D)
, yuv420p, 640x480 [SAR 1:1 DAR 4:3], 5752 kb/s, 30.08 fps, 30.08 tbr, 90k
tbn,
300 tbc
    Metadata:
      creation_time   : 2013-05-20 11:54:39
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 16000 Hz, stereo,
s16, 127
 kb/s
    Metadata:
      creation_time   : 2013-05-20 11:54:39
      handler_name    : SoundHandle
//---------------------------------------------------------------------------------------------------------------------------------------------------

Like in above example, I can read that video is recorded at 30.08 fps,
question is: it is apparently very simple for FFmpeg to figure this out,
but how can I use this information from my own program? I was trying to
follow code from FFmpeg source file (utils.c): [void
av_dump_format(AVFormatContext *ic,  int index, const char *url, int
is_output)], but was easily lost there.

Can anyone kindly guide me how to intercept this problem?

Thanks in advance for your time...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130521/e50674c0/attachment.html>


More information about the Libav-user mailing list