<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>I'm working on a movie playback library but I'm getting issues with seeking. I'm using av_seek_frame() and FFmpeg 0.10.</div><div><b>The problem is that the audio stream is correctly sought but not the video stream</b>, except for H.264 video stream (not working for DivX, MPEG4v2 or Theora video streams).</div><div><br></div><div><b>Here is what I get:</b></div><div><br></div><div>When seeking I print these debug messages:</div><div>REQUESTED SEEK to 276.794s<br>video seek pos = 276793952<br>video seek target = 6643<br>video seek as seconds = 276.794<br>audio seek pos = 276793952<br>audio seek target = 11533<br>audio seek as seconds = 276.794</div><div><br></div><div>Where 'video seek target' and 'audio seek target' are the values given to av_seek_frame() for both streams.</div><div>But right after this, after calling av_decode_* for the first time, here is what I get for the packet that has just been decoded:</div><div>audio pts = 276792ms</div><div>video pts = 271583ms</div><div><br></div><div>As you can see, the gathered audio PTS is fine : 276.792s. Whereas the video one isn't : 271.583s. I do not know why this is happening, especially as it's working fine with H.264 streams. Note that the time gap isn't fixed, I sometimes get a 2 or 8 seconds difference for example.</div><div><br></div><div><br></div><div>So that you can understand how I got these results, <b>here is what I did</b>:</div><div><br></div><div>When seeking:</div><div><i>flush the queued video AVPackets</i></div><div>AVRational timeBase = m_avFormatCtx->streams[videoStreamID]->time_base;<br>int flags = (<i>targetPosition is before currentPosition</i>) ? AVSEEK_FLAG_BACKWARD : 0;<br><span class="Apple-tab-span" style="white-space:pre"> </span><br>int64_t seek_pos = (int64_t)(targetPosition.asSeconds() * AV_TIME_BASE); // ::asSeconds() returns a float value<br>int64_t seek_target = av_rescale_q(seek_pos, AV_TIME_BASE_Q, timeBase);</div><div>av_seek_frame(m_avFormatCtx, videoStreamID, seek_target, flags)</div><div>avcodec_flush_buffers(m_videoCodecCtx);</div><div><br></div><div>When decoding:</div><div><i>check if there are available video packets (but since we flushed everything there are none)</i></div><div><i>read the movie file until we get video packets</i></div><div>avcodec_decode_video2(m_codecCtx, m_rawFrame, &didDecodeFrame, videoPacket);</div><div>int64_t seek_target = av_rescale_q(videoPacket->pts, videoTimeBase, AV_TIME_BASE_Q) / 1000;</div><div>std::cout << "video pts = " << seek_target << "ms" << std::endl;</div><div><br></div><div><br></div><div>So I don't think I did anything fancy, but I still can't find out why the video seeking is inaccurate. I would be really grateful if someone had ideas about this issue.</div><div><br></div><div>Regards,</div><div>Lucas SOLTIC</div></body></html>