<div dir="ltr">I saw many threads about seeking in video files with FFMPEG. But still it is not clear for me how to seek to specific location (in milliseconds) with good accuracy. I know that to seek in video file it is needed to seek than decode frames and check where we are, than seek again decode frames etc. till we reach the exact moment we need. The best result with seeking I have using this code:<div><br></div><div>







<p class=""><span class="">AVRational</span> timeBase = video_stream-><span class="">time_base</span>;</p><p class=""><span class="">int64_t</span> seek_pos = (<span class="">int64_t</span>)(((<span class="">float</span>)tsms)/1000 * (<span class="">float</span>)AV_TIME_BASE);</p><p class=""><span class="">int64_t</span> seek_target = av_rescale_q(seek_pos, AV_TIME_BASE_Q, timeBase);</p><p class="">










</p><p class="">av_seek_frame(format_context, <span class="">video_stream_id</span>, seek_target, <span class="">AVFMT_SEEK_TO_PTS);</span></p><p class="">But still in some videos and some places in this videos seeking is not working perfectly. The question is if seeking to AVFMT_SEEK_TO_PTS makes this complex algorithm of seeking in video file to have hight accuracy? Maybe there is better implementation of seeking which considers all video formats?</p><p class="">For example seeking is not working with MPEG-4 Visual file. I am using FFMPEG 2.1. Thanks!</p></div></div>