I was able to get something working. Now when I load, I search the entire file looking for the presentation time stamps for each keyframe. I can then use those to start my seeking. Didn't need the use AVSEEK_FLAG_BYTE after all.<br /><br />Mark<br /><br /><hr /><strong>Subject:</strong> [Libav-user] How to seek to a given frame?<br /><strong>Date:</strong> Wed, 08 May 2019 13:52:53 -0400<br /><strong>From:</strong> Mark McKay <mark@kitfox.com><br /><strong>To:</strong> <libav-user@ffmpeg.org><br /><strong>Reply-To:</strong> "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter." <libav-user@ffmpeg.org><br /><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<p>I'm trying to create a video player with the ability to seek whereever I want. I'm having some trouble with <span style="color: #008000;">av_seek_frame()</span>, which seems to keep returning the first keyframe after the timestamp I'm looking for:<br /><br /><br /><span style="color: #000000;"> int timestamp = av_rescale_q(timeMs, AV_TIME_BASE_Q,</span></p>
<pre style="-qt-block-indent: 0; text-indent: 0px; margin: 0px;"><span style="color: #000000;"> pFormatCtx->streams[videoStream]->time_base);</span></pre>
<span style="color: #000000;"> int err = av_seek_frame(pFormatCtx, videoStream, timestamp, 0);<br /><br /></span>Unfortunately, if it puts me at a position /after/ the frame where I'm seeking, I have already passed the frame I want and can't scan forward to find it. I've also tried seeking with <span style="color: #008000;">AVSEEK_FLAG_ANY</span>, but this it not returning frames with valid data. I'm guessing that you need to jump to the correct keyframe and then scan forward so that the frame buffers are built correctly.<br /><br />I'm also considering scanning the entire video when I first load it to build an index of packet information. <span style="color: #000080;">AVSEEK_FLAG_BYTE</span> looks like it could be useful to jump directly to the packet I want - however, I don't know where to find the byte value I would need to pass to the seek function.<br /><br />How can I scan to the frame that I want?<br /><br />Cheers,<br />Mark<br /><br />
<div>
<pre>---
http://www.kitfox.com</pre>
</div>