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

Ivan Schreter schreter
Sun Jul 26 19:48:19 CEST 2009

zhentan feng wrote:
> [...]
> I am not clear why the parser return the wrong frame size when fist call
> av_read_frame() after seek.
> anyone explain it futher?
I looked at the code. Consider following example: A PES packet contains 
some rest of previous frame and start of a new frame. In normal case, 
the rest of the previous frame is simply glued to the data in the buffer 
and returned as whole frame with PTS of the previous frame during 
processing of this PES packet in the parser.

However, after a seek, parser is reset. Instead of ignoring the portion 
of previous frame, it returns it back as a frame with PTS of the current 
frame. Beginning of current frame (to which PTS actually belongs) is put 
into the buffer and when the frame is completed, it is returned back 
without PTS.

So, we have one corrupted frame with the timestamp of the actual frame 
before actual frame (most probably of correct size, but I didn't check), 
which is returned without timestamp.

Code in mpegvideo_parser.c and possibly in ff_combine_frame() must be 
fixed to take this case into account (i.e., newly-initialized parser and 
rest of old frame in the first packet received from the stream).



More information about the ffmpeg-devel mailing list