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

Ivan Schreter schreter
Sun Aug 2 11:41:05 CEST 2009

Hi Baptiste,

Baptiste Coudurier wrote:
> On 07/26/2009 10:48 AM, Ivan Schreter wrote:
>> 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).
> Yes I think this partial frame must be discarded and it's easy to do 
> that by checking headers.

Sorry, I wasn't able to look at ML last week.

Could you please elaborate which headers you meant? I can surely find 
them myself, but it would help if you give me (or Zhentan) some pointers...

Thanks & regards,


More information about the ffmpeg-devel mailing list