[FFmpeg-user] about index_entries in AVStream

Robert Krüger krueger at lesspain.de
Tue Sep 10 09:02:33 CEST 2013


On Tue, Sep 10, 2013 at 4:53 AM, YIRAN LI <mrfun.china at gmail.com> wrote:
> Hi,
>
> I met a problem when doing seek in a mpeg file (MPEG2 encoded MPEG-PS
> video).
>
> After the file is opened using avformat_open_input, seems the index_entries
> of video stream is populated with incorrect values (the comment says these
> index_entries are only used if format does not support seeking natively). I
> can directly call av_seek_frame and it succeeded on this file. But I don't
> understand if those index_entries are not valid, why they get populated
> when file is opend
>
> So I'd like to know if there's a way to judge if the index_entries are
> valid, or if there's a list telling me what format natively doesn't support
> seek (So if I know which format supports direct seek, I can ignore
> index_entries and seek directly)

I don't think such a list exists.

>
> the index_entries of that mpeg files has following timestamps:
>
> 00:00:19.267  MAIN  entry[0].time = 21600
> 00:00:20.109  MAIN  entry[1].time = 57600
> 00:00:20.842  MAIN  entry[2].time = 100800
> 00:00:20.842  MAIN  entry[3].time = 144000
> 00:00:20.842  MAIN  entry[4].time = 187200
> 00:00:20.842  MAIN  entry[5].time = 230400
> 00:00:20.842  MAIN  entry[6].time = 273600
> 00:00:20.842  MAIN  entry[7].time = 316800
> 00:00:20.842  MAIN  entry[8].time = 360000
> 00:00:20.842  MAIN  entry[9].time = 403200
> 00:00:20.842  MAIN  entry[10].time = 446400
> 00:00:20.842  MAIN  entry[11].time = 489600
> 00:00:20.842  MAIN  entry[12].time = 532800
> 00:00:20.842  MAIN  entry[13].time = 576000
> 00:00:20.842  MAIN  entry[14].time = 619200
> 00:00:20.842  MAIN  entry[15].time = 662400
> 00:00:20.842  MAIN  entry[16].time = 705600
> 00:00:20.842  MAIN  entry[17].time = 285264000
>
> the last timestamp is quite close to the end of video so the first 17 are
> quite close to the beginning. So if I seek based on these indexes, it
> always goes to the the very beginning first.

You could dump packet timestamps using ffprobe and compare these with
index timestamps to see if the entries make sense (i.e. to check if
packets marked as keyframes have timestamps corresponding to index
entries marked as keyframes). You should also be aware that the
timestamps in the index may be pts or dts. It is not defined in the
API but a decision the implementor of a demuxer makes.

BTW, this kind of question probably belongs in the libav-user mailing
list as it is about api use and not command line tools.


More information about the ffmpeg-user mailing list