[FFmpeg-devel] base av_read_frame() function for seeking in mpegps files

zhentan feng spyfeng
Thu Jul 9 11:36:48 CEST 2009


I am implementing a seek api for mpegps demuxer.
Index entries are already built before seeking, the frame pos is set as PES
header pos.

so when seek target timestamp,
1) look up the index and get the frame pos in the index entries.
2) use url_fseek() seek to the pos and call av_read_frame() until get the
target frame

here I have an error: the target frame size is not correct for some
situation, ie not same with the actual frame size, but the pts/dts value is

for example:
there is one frame in the sample file.

[mpeg @ 0x8b63420]av_read_packet stream=1, pts=129534, dts=129534,
size=2016,  flags=0, pos = 1327118
[mpeg @ 0x8b63420]av_read_frame_internal stream=1, pts=129534, dts=129534,
size=1536, flags=1, pos=1327118

I seek to 1327118 and want to get the frame (pts = 129534, size = 1536)
using av_read_frame(), however the returned frame is:
ret: 0 st: 1 dts:129534 pts:129534 pos:1327118 size:867 flags:1
the size changed from 1536 to 867.

I debug it and found that the size is parsed by ff_aac_ac3_parse(), the
returned size (867) is not same with the target frame size (1536).
I checked the pos of the PES packet is set correctly, anyone know what's the
problem maybe?
or I misuse the av_read_frame()?

thanks a lot.
Best wishes~

More information about the ffmpeg-devel mailing list