[FFmpeg-devel] [RFC] Many formats return wrong position => seeking problems

Ivan Schreter schreter
Sat Mar 7 21:38:38 CET 2009

Hi Michael,

Michael Niedermayer wrote:
> On Sat, Mar 07, 2009 at 05:28:41PM +0100, Ivan Schreter wrote:
>> Reimar D?ffinger wrote:
>>> On Sat, Mar 07, 2009 at 03:43:12PM +0100, Ivan Schreter wrote:
>>>> I'm writing some low-level support for new seeking API. In principle, it 
>>>> works OK now, but many format demuxers in lavf are broken in the sense 
>>>> that they don't return correct packet positions. This is mandatory for 
>>>> new seeking API and for corrections to current seeking API as well.
>>> Can you please define what "correct position" means? That would make it
>>> easier to know which are broken and how to fix them (or alternatively
>>> flame you if the requirements are too restrictive ;-) ).
>> Well, quite easy:
>> av_read_frame() returns an AVPacket, containing file position in member 
>> pos. If I reposition the file pointer to this position in the file, I 
>> expect next av_read_frame() to return exactly the same packet (also with 
>> same DTS/PTS, single exception being undefined DTS/PTS after repositioning).
> in that sense most formats do not have a position, as they will never work
> once you touch the file pointer, their demuxers rather need various parts
> of their internal state updated
> and code that does this exists and works.
But how do you want to implement the new seeking API then? The algorithm 
you described _requires_ to be able to restart reading from a given 
position. Namely, after we find keyframes in all streams of interest, we 
have to reposition the file pointer to the frame with lowest file 
position and start reading from there.  But this requires that positions 
returned from av_read_frame() are valid (transitively requiring demuxers 
to return correct position of packets returned from them).

I think this should not be that big problem, since those formats in 
question also have the notion of keyframes, when they do synchronize the 
internal state. But at least these keyframes must return correct file 
position and timestamps from av_read_frame(). And this is missing.

As for the code in demuxer to update internal state after file position 
change: currently the seeking routine does this (it seems to usually 
first call the generic seek and then update the state). But I didn't 
find any other means of updating the state. Possibly, a new demuxer 
function is needed to update state after position change during backward 
search for keyframes (we need to reposition the file offset and start 
from that position) and after all keyframes found.

BTW, I still didn't get any comments from you to the seeking patch I 
posted for pre-review already twice... It effectively implements your 
algorithm for searching for keyframes in several streams.



More information about the ffmpeg-devel mailing list