[FFmpeg-user] How to determine length of animation using C++ API?

Mark McKay mark at kitfox.com
Fri Apr 26 03:51:06 EEST 2019

 On Fri, 26 Apr 2019 00:40:30 +0200, Moritz Barsnick <barsnick at gmx.net> 
> On Thu, Apr 25, 2019 at 15:38:22 -0400, Mark McKay wrote:
>> I'm using the C++ API
> To my knowledge, ffmpeg has no C++ API - apart from the fact that a C
> API, which it has, is compatible with C++. (Sorry for being petty.)
> Furthermore, for questions regarding the use of the ffmpeg-libav* 
> APIs,
> please refer to the mailing list "libav-user":
> https://ffmpeg.org/mailman/listinfo/libav-user
>> I'd like to be able to load a video and determine how many seconds
>> long it is. I thought I would be able to calculate this time by
>> looking at AVFormatContext->duration in the header and that
> [...]
>> However, if I scan through all my packets to the end, my final 
>> packet
>> has a presentation time of 3580928 and my codec context has a
>> timebase of 1 / 50.
> The length of a video as indicated in its header and its actual 
> length
> can differ. There's nothing much you can do about this, except to 
> demux
> / decode a file to its end to check for the actual timestamps (and
> possible discontinuities).
> On this mailing list, we can show you how to use the ffmpeg command
> line tool to
> expose this difference.
> Cheers,
> Moritz

 Thanks.  For the record, it turned out I was using the format's 
 time_base instead of the stream's time_base.  In the future I'll post to 
 the libav list.


More information about the ffmpeg-user mailing list