I'm trying to retrieve the duration and number of frames from a WebM file using FFMPEG and libavformat. I'm adapting some code that was initially written to work with MP4s, and when passing an MP4 it seems to work fine.
I have FFMPEG 2.1 compiled with the vp8 parser and decoder and the matroska demuxer.
I have an AVStream
pointer to the video stream, *video_st
. The code looks for the number of frames in video_st->nb_frames
, and for the duration in video_st->duration
. These both appear to be 0.
The API docs for for video_st->duration
(https://ffmpeg.org/doxygen/trunk/structAVStream.html#a4e04af7a5a4d8298649850df798dd0b) say that "If a source file does not specify a duration, but does specify a bitrate, this value will be estimated from bitrate and file size." I can confirm that that this file does specify a duration and a bitrate (as I tested it on my desktop with ffmpeg -i
). So it seems odd that this is returning 0. Perhaps my FFMPEG build configuration is incorrect?
As for nb_frames
, the docs say "number of frames in this stream if known or 0". Is there anything I can do if this returns 0? Again, ffmpeg -i
does return an estimate for fps; that would be good enough, as I could estimate the number of frames with that and the duration.
Thanks!