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

Moritz Barsnick barsnick at gmx.net
Fri Apr 26 01:40:30 EEST 2019


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


More information about the ffmpeg-user mailing list