[Ffmpeg-devel] [RFC] av_seek_frame behaviour

Baptiste Coudurier baptiste.coudurier
Mon Apr 23 13:28:45 CEST 2007

Michael Niedermayer wrote:
> Hi
> On Mon, Apr 23, 2007 at 12:30:13AM +0200, Baptiste Coudurier wrote:
> [...]
>> I run a p3 1ghz here and av_seek_frame_generic is clearly not 
>> acceptable, only for small files mainly FLV (for which that 
>> av_seek_frame_generic behaviour changed). Now every seeking failure with 
>> a format that has no read_timestamp function will be parsed from the 
>> beginning.
> theres one thing i dont understand and that is, if the user wants to seek
> then seeking should happen and if theres no other way supported than
> av_seek_frame_generic then so be it

Yes, I agree with that

> also av_seek_frame_generic() just 
> reads the file linearly from the last position to the point to which the
> user wants to seek so even with huge files a little forward/backward
> seeking should be ok


    if(index < 0 || index==st->nb_index_entries-1){
        int i;
        AVPacket pkt;

        if(st->index_entries && st->nb_index_entries){
            ie= &st->index_entries[st->nb_index_entries-1];
            url_fseek(&s->pb, ie->pos, SEEK_SET);
            av_update_cur_dts(s, st, ie->timestamp);
            url_fseek(&s->pb, 0, SEEK_SET);

In fact av_seek_frame_generic seek back to the beginning of file if no
index is there, maybe it is not wanted ? Or see below.

> that is unless the demuxer doesnt use av_add_index_entry() properly

Ok, so demuxer should use av_add_index_entry ? Im not against that, it
just needs to check all demuxers.

> also iam not opposed to add some flags so that the user can indicate
> the amount of accuracy/speed she wants but first we actually need
> to have multiple working seek variants before a API to access them
> makes sense ...

Agree. I began to check some seek functions:

TS seems to use av_seek_frame_binary internally and returning -1 which
will make av_seek_frame to call av_seek_frame_binary again. Twice try in
case of failure.

PS has read_timestamp, so av_seek_frame_binary is called.

GXF seems to work modified to use av_seek_frame_binary internally.

FLV seems to work removing seek function and letting av_seek_frame
calling av_seek_frame_generic.

MOV has perfect seeking since whole index is built, and use
av_index_search_timestamps internally.

MXF has rudimentary byte seek based on global bitrate (not that elegant
I agree)

ASF seems to use av_seek_binary internally if index is not present, else
using av_index_search_timestamps.

Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA
SMARTJOG S.A.                                    http://www.smartjog.com
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
Phone: +33 1 49966312

More information about the ffmpeg-devel mailing list