The docs in the header file say that the AVSEEK_FLAG_BACKWARD is ignored, and the tests I've run seem to work even when I leave it out.<br /><br />Mark<br /><br /><br /><hr /><strong>Subject:</strong> Re: [Libav-user] How to seek to a given frame?<br /><strong>Date:</strong> Wed, 8 May 2019 13:20:17 -0700<br /><strong>From:</strong> Michael Armes <michael.armes@gmail.com><br /><strong>To:</strong> "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter." <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 -->
<div dir="ltr">Use <a style="margin: 0px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Arial; font-size: 15px; vertical-align: baseline; box-sizing: inherit; color: #005999;" href="http://ffmpeg.org/doxygen/trunk/avformat_8h.html#ac736f8f4afc930ca1cda0b43638cc678"><code style="margin: 0px; padding: 1px 5px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas; font-size: 13px; vertical-align: baseline; box-sizing: inherit; background-color: #eff0f1; white-space: pre-wrap;">AVSEEK_FLAG_BACKWARD</code></a> to seek to the closest <em>keyframe</em> having a smaller pts than the one you are seeking. You must then iterate through reading frames until you reach your desired position (if you are not seeking to a keyframe).
<div> </div>
<div>--michael</div>
</div>
<br />
<div class="gmail_quote">
<div class="gmail_attr" dir="ltr">On Wed, May 8, 2019 at 10:53 AM Mark McKay <<a href="mailto:mark@kitfox.com">mark@kitfox.com</a>> wrote:</div>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;">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>
<pre style="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>---
<a href="http://www.kitfox.com">http://www.kitfox.com</a></pre>
</div>
_______________________________________________<br /> Libav-user mailing list<br /><a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br /><a href="https://ffmpeg.org/mailman/listinfo/libav-user">https://ffmpeg.org/mailman/listinfo/libav-user</a><br /><br /> To unsubscribe, visit link above, or email<br /><a href="mailto:libav-user-request@ffmpeg.org">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".</blockquote>
</div>
<p> </p>
<div>
<pre>---
http://www.kitfox.com</pre>
</div>