[Libav-user] How to get a video with the actual total length?

Jean-Yves Avenard jyavenard at gmail.com
Thu Jun 5 15:35:00 CEST 2014


On 5 June 2014 19:02, Object <leachong at qq.com> wrote:
> I have a video with actual total length over 10 seconds. But when I opened
> it with VFormatContext.duration, it showed that it is only 10 seconds long.
> And then I tried to get the pts of final frame via seek, but unfortunately,
> the got_picture is always 0.

short of counting all video frames , you will never get a 100% accurate answer.

The especially true with FTA broadcast, where you find that they often
use different pts series between the main program and their ads.
So you could have something like

7-8-9-1-2-3-10-11-12

where 1-2-3 is your ad.

Then you have the issue where the file could have variable framerate
and variable bitrates.

So in mythtv, when we record a file, we count the frames and keep a
map frames/duration. This allows perfect seek (and very fast) and very
accurate duration calculation.

Seeking to the last frame may not always be possible, especially if
it's not a reference frame


More information about the Libav-user mailing list