[Ffmpeg-devel] Problem seeking frames
kant1304 at free.fr
Mon Jun 19 19:45:09 CEST 2006
I would like to use avformat to seek frames (keyframes but also normal frames)
in various ways, forward, backward, by giving a frame number... I'm using
av_seek_frame(), and for a normal video file I have no problem.
Now I want to work on a raw video file, with all frames being keyframes. The
forward search still works flawlessly, but once I want to search backwards, say
frame 20 when I'm at frame 21, the decoder always gives me frame 21...
Here is the code I'm using:
int decoded, length, gotPicture;
codecContext = videoStream->codec;
while ( 1 )
decoded = av_read_frame(formatContext, &packet);
if (packet.stream_index == videoStreamIndex)
length = avcodec_decode_video(codecContext, context->curFrame, &gotPicture,
if ( gotPicture )
/* If we need to perform any kind of complex search */
ret = av_seek_frame(stream, frameNumber, searchFlag);
/* currentFrameNumber is initialized when opening the video file and decoding
the 1st frame, then updated when needed */
while (currentFrameNumber < frameNumber)
This code works for a normal video file (avi container, mpeg4 video, mp3 audio,
keyframes are irregularly placed), but for the same video file type (avi
container, mpeg4 video, mp3 audio) where every frame is a keyframe, the
backwards search always returns the current frame...
I'm quite a newbie to avcodec/avformat, so I apologize if the question seems
dumb, but if someone knows about this problem or could give me some advice on
where I went wrong, I would appreciate...
Thanks in advance
More information about the ffmpeg-devel