Hi All,

I'm having some real difficulty with seeking in an MPEG2 file. My aim is to
capture some specific frames from the file, which correspond to some
timestamps that I know. Because the frames I require are a while apart, I
don't want to have to decode the whole file, I want to seek to a point close
to the frame i'm looking for and then grab it.

I'm using a mingw build from the SVN which I took a snapshot of yesterday,
and working in windows. My pVideoCodecContext indicates that the codec in
use is "MPEG-2 video".

pVideoStream->start_time is 14518800, the frame rate is 25 fps, and the
first frame I want is #142, which results in a target PTS of 15030000. The
code for how I work this out is not important, suffice to say that I want a
frame with that PTS.

So, I call av_seek_frame as follows:-
    av_seek_frame(pFormatContext,video_stream_index, 15030000,
AVSEEK_FLAG_BACKWARD);

It's my understanding that AVSEEK_FLAG_BACKWARD means seek the the I-frame
prior to the target PTS, which, if my understanding of I and P frames is
correct, ought to mean that after the seek, the next video packet should be
immediately decodable (it should be an I-frame).

After the seek, I enter a decode loop. I dump the pts and dts from the
packet, and they come out as follows:-

pts: -9223372036854775808 dts: 15027919
pts: 15044400 dts: 15044400
pts: 15058800 dts: 15048000
pts: 15051600 dts: 15051600
pts: 15055200 dts: 15055200
pts: 15069600 dts: 15058800
pts: 15062400 dts: 15062400
pts: 15066000 dts: 15066000
pts: 15080400 dts: 15069600
pts: 15073200 dts: 15073200
pts: 15076800 dts: 15076800
pts: 15091200 dts: 15080400 decoded (this is the first packet which
avcodec_decode_video indicated was frame finished)

Note that it's the 12th packet which resulted in the first "frame finished",
and that frame's PTS is 15091200, which is 17 frames later than the frame I
required.

In fact, whilst the PTS of the first frame after the seek is clearly wrong,
the DTS of that frame is before the target PTS, but then every subsequent
packet is later than my requirements?

What am I doing wrong? How can I seek to an appropriate distance before my
target frame so that I can be sure that it will soon be decoded in my decode
loop?

I'd be extremely grateful for some guidance on this, i'm really tearing my
hair out here.

Thanks

slip
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to