[Ffmpeg-devel] seeking to a precise frame

Mathieu CARNEC Mathieu.Carnec
Thu Apr 12 18:53:47 CEST 2007


Hello,

My application needs to be able to seek a video file (of any format: MPEG,
TS, AVI, MOV, H264...) at a precise frame. I have read many information on
this problem on the internet but i couldn't find a solution.

Since video files are made with timestamps and not with frames number, I
use pts information.

I have tried using av_seek_frame to seek to a given position. This
function is supposed to seek to the last key frame before the asked
position.

Then I would decode the frames following the seeked key frame to get the
exact frame I want (which is not necessary a key frame).

Since I wanted to make sure that av_seek_frame had found the right
position, I tried to check this position using packet.pts (since
pFrame.pts is not always correctly set).

Then problems have begun: by testing my application with different video
formats (mainly MPEG TS containing MPEG2 or H.264, and AVI), it seems that
packet.pts could contain useful values with some video formats but also
"apparently useless" values with some others. More, when a frame needs
several packets to be decoded, it seems these packets can have different
pts values. Is it normal ? Then which pts should be used : the pts of the
first packet or the pts of the last packet ?

My question is :
Does anyone knows a reliable way to seek to a given file and determine
exactly the exact timestamp of the seeked position ? A sample of code
would be greatly appreciated.

It seems that MPlayer can do that : when you seek to a given position
(using left click in MPUI), the displayed elapsed time is updated to the
correct value, so MPlayer knows the timestamp of where it has seeked.

Best regards,

MC.





More information about the ffmpeg-devel mailing list