On Fri, Jan 21, 2011 at 01:12, Ophenix <[email protected]> wrote: > I still get the nearest key frame... > Let's say i want to seek to the middle of the video. I'm using this code to > get the length of the video and divided by 2. > > int64_t targetPos = (int64_t)(pFormatCtx->streams[videoStream]->duration / > 2 > * AV_TIME_BASE); > > > Next i do the seek stuff. > > av_seek_frame(pFormatCtx, videoStream, targetPos, AVSEEK_FLAG_BACKWARD); > > do {av_read_frame(pFormatCtx, &packet); > > avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,packet.data, > packet.size); > > if (packet.pts = targetPos) > { > if(frameFinished) > { > break; > } > } > > av_free_packet(&packet); > > } while(1); > > > Am i missing something here? > > > Best regards >
I see two bugs in the following line in your code if (packet.pts = targetPos) I believe it should be like this instead: if (packet.pts >= targetPos) you might also like the following frame-accurate-seeking library https://github.com/lbrandy/ffmpeg-fas or the ffmpeg source library http://code.google.com/p/ffmpegsource/ both should give you frame accurate seeking built-in _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
