[FFmpeg-devel] Seek problem with ffmpeg-mt

Thomas Worth thomas
Tue Mar 1 00:58:40 CET 2011

On Mon, Feb 28, 2011 at 3:42 PM, Thomas Worth <thomas at rarevision.com> wrote:
> On Sun, Feb 27, 2011 at 01:12:47AM -0800, Thomas Worth wrote:
>> for(;;){
>> ? ? ? av_read_frame(formatCtx, &packet);
>> ? ? ? if(packet.stream_index == videoStream){
>> ? ? ? ? ? ? ? avcodec_decode_video2(codecCtx, frameIn, &frameFinished, &packet);
>> ? ? ? ? ? ? ? if(frameFinished){
>> ? ? ? ? ? ? ? ? ? ? ? fprintf(stderr,"pts:%05d seekpos:%05d\n",packet.pts,seekpos);
>> ? ? ? ? ? ? ? }
> This is complete nonsense, you are printing the input pts whenever
> you get some output.
> If you print packet.pts unconditionally before calling decode it
> might actually make some sense.
> Or printing frameIn->pkt_pts in that condition.

Okay, I moved my fprintf before the decode, and here's what I get. I
also added a check to see if the frame is a keyframe or not, and the
error always occurs right after a keyframe.

Note that when "seekpos" shows the same seek value twice in a row
(right after keyframes), the first value is not marked by
avcodec_decode_video2() with *got_picture_ptr. Only on the second
iteration of the loop is it marked. If I _force_ frameFinished to be 1
every time, it works but the frame returned is black. Interestingly
though, avcodec_decode_video2() still returns the decode result value,
which differs for each black frame! So, even though it seems to be
returning the size of the decompressed frame, it is not copying it
into frameIn nor setting *got_picture_ptr.

pts:00000 seekpos:00000 (keyframe)
pts:01001 seekpos:01001
pts:02002 seekpos:01001
pts:02002 seekpos:02002
pts:03003 seekpos:03003
pts:04004 seekpos:04004
pts:05005 seekpos:05005
pts:06006 seekpos:06006
pts:07007 seekpos:07007
pts:08008 seekpos:08008
pts:09009 seekpos:09009
pts:10010 seekpos:10010
pts:11011 seekpos:11011
pts:12012 seekpos:12012 (keyframe)
pts:13013 seekpos:13013
pts:14014 seekpos:13013
pts:14014 seekpos:14014
pts:15015 seekpos:15015
pts:16016 seekpos:16016
pts:17017 seekpos:17017
pts:18018 seekpos:18018
pts:19019 seekpos:19019
pts:20020 seekpos:20020
pts:21021 seekpos:21021
pts:22022 seekpos:22022
pts:23023 seekpos:23023
pts:24024 seekpos:24024 (keyframe)
pts:25025 seekpos:25025
pts:26026 seekpos:25025
pts:26026 seekpos:26026
pts:27027 seekpos:27027

More information about the ffmpeg-devel mailing list