[Libav-user] Seeking, timestamps, AVFrame, AVStream

Don Moir donmoir at comcast.net
Mon Sep 16 20:33:46 CEST 2013


>>> Yes, I looked at avcodec.h and could not find what I wanted.  When I was

>>
>>You wrote:
>>
>>    pts
>>    pkt_pts
>>    pkt_dts
>>    coded_picture_number
>>    display_picture_number
>>    best_effort_timestamp (the name of this one really worries me)
>>    pkt_pos
>>    pkt_duration
>>What do those all mean?  Can I use those to figure out which frame this is?
>>
>>All of these are documented there. That's why I thought you hadn't
>>looked at the docs.

>Actually, none of them (except pts) are defined there.  Most aren't
>even mentioned.  But they are mentioned in AVFrame.h

>>My gut feeling is that the biggest problem is that you probably need
>>to read up on some basics, so the docs (which are quite OK IMHO) make
>>sense to you, so you know what a timebase, presentation timestamp,

>Yes, I definitely prefer reading docs then asking for help.  But what docs
>are you talking about?  I'm not aware of anything other than the source code.

>Anyway, it sounds like pts and best_effort_timestamp are really frame numbers
>(not time values) and to get the actual time value, you multiple them by the
>time base.  Is that correct?  I'm actually starting with frame numbers and I
>don't really need the time values, per se.  Can I merely use the pts or
>best_effort_timestamp and assume they equal the frame number?

>Also, will the libs do anything behind the scenes to duplicate frames for
>whatever reason (like to meet some CFR rate)?  I don't want that.

In principle, seeking is easy in ffmpeg, but it practice over a broad range of file types, it's complicated. This is due sometimes 
to behavior differences, sync issues, timestamp issues, start times, and other things but over the last couple years seeking has 
gotten a lot better.

I have found that seeking by timestamps is the most reliable over a broad range of file types.

In your case, there should be a way to esitmate the timestamp given a frame number. Timestamps are in AVStream.time_base units.

To convert a timestamp to seconds you could do this:

int64_t some_timestamp = some value;

double seconds = some_timestamp * av_q2d (pStream->time_base);

This is just an example and there is more to it. Timestamp can be AV_NOPTS_VALUE and timestamp can be relative to some start value.

Now like I said you should be able to estimate the timestamp given a frame number in your case since it's consistent.

There is also something called AVStream.index_entries that is your case should contain all the frame offsets starting with 0 and 
their associated timestamps.

The thing is it varies when this table is completed. It might be done on first seek, it might be done on the fly as frames are read 
and so on.

This should help you a bit, but like others have said, you need to read. It takes awhile to get familiar with all this.



More information about the Libav-user mailing list