[Libav-user] How do I seek to the very beginning of a file?

Don Moir donmoir at comcast.net
Wed Oct 17 03:24:16 CEST 2012


> On Tue, Oct 16, 2012 at 5:10 PM, Don Moir <donmoir at comcast.net> wrote:
>> I use avformat_seek_file and so does ffplay etc. I always use a valid stream
>> index and not -1. I don't leave it up to ffmpeg to determine what stream to
>> seek on.
>>
>> I always take the first_dts for the stream into account. The first_dts will
>> be the zero mark for the stream. first_dts can be zero, less than zero, or
>> greater than zero.
>>
>> I use AVSEEK_FLAG_BACKWARD (regardless if seeking to zero or not).
>>
>> With above logic, I can't remember the last time I had a problem seeking to
>> zero (first_dts).
>>
>> Should I have to do the above ?  probably not...
>
> Ugh, seems complex. It's complicated by the fact that not all formats
> seek by DTS (some seek by PTS, like nut). I may have to do that, but
> I'm hoping there's a better alternative... Heck, even seeking by byte
> to the first packet position seems preferable (though I can't see why
> seeking to a byte index of 0 shouldn't work). It's not that the above
> is super complex and overly hard... it's just that for such a basic,
> frequently used operation (seeking to the beginning), it seems...
> wrong.
>
>> Also not to say there isn't a few problem files here and there but these
>> just need to be reported so it can be fixed.
>>
>> Do you have a particular file that is a problem and can be posted ?
>
> I've got a bunch of files that seem to completely ignore
> AVSEEK_FLAG_BYTE and seeking to 0, despite returning "success." I can
> also write some sample code if needed to demonstrate. Shall I?
>

Oh yeah you can't use AV_SEEK_BYTE in general because a lot of formats don't support it.

With seek by PTS they just added more confusion to the mix.

Don't need any sample code but if you have a nut sample or another file that is a particular problem I would like to see it if it's 
easy for you to post.

When I first started using ffmpeg most of the learning curve was in timestamps and why seeking didn't work as expected. Over time 
seeking has been much improved but I can see now why it didn't make sense in the first place. (Because it was incorrect in many 
cases)

I think in the ideal case, you would just seek from 0 to duration in ms or us and be done with it. My interface to ffmpeg does 
exactly that.




More information about the Libav-user mailing list