[Ffmpeg-devel] Seeking and keyframes

Michel Bardiaux mbardiaux
Mon Jun 20 12:21:43 CEST 2005

M?ns Rullg?rd wrote:
> Steve Willis <steve at stevewillis.net> writes:
>>Please pardon my novice question. I'm working on a project where the
>>user needs to analyze video frame by frame, and possibly cut video at
>>any arbitrary frame (not necessarily a keyframe.) This is not the same
>>as a typical video player...video does not have to be "played" in
>>real-time, just stepped through frame by frame. More importantly, I
>>need a way to get a frame for a particular time accurate to the frame
>>(not to the closest keyframe.)
>>I've been looking at the documentation for av_seek_frame(), and I see
>>that it seeks to the first keyframe before the given timestamp by
>>default. Is there a simple way to change this behavior so it finds the
>>previous keyframe and then regenerates the forward intra-frame to
>>exactly match the timestamp?
> No.  Libavformat doesn't have access to the decoder to perform the
> decoding of the frames after the keyframe up to the requested frame.
>>Alternatively, is there a simple way to use ffmpeg to transcode the
>>video such that every frame is a keyframe?
> You could use mjpeg.
>>A final (very beginner) question: why is seeking only to keyframes the
>>default? Is it very inefficient to actually generate the exact frame
>>for a given timestamp each time a user seeks?
> It's somewhat inefficient, but also impossible.
Would it be possible to have av_seek_frame also return a set of 
instructions to follow to obtain the specified frame? E.g. for a GOP of 
structure IBBP in display order, if you specified seek to the 2nd B 
frame, seek_frame would tell you back "read_frame+decode, 
read_frame+skip, read_frame+decode, read_frame+decode" (Correct?)

Michel Bardiaux
Peaktime Belgium S.A.  Bd. du Souverain, 191  B-1160 Bruxelles
Tel : +32 2 790.29.41

More information about the ffmpeg-devel mailing list