<div dir="ltr">Use 

<a href="http://ffmpeg.org/doxygen/trunk/avformat_8h.html#ac736f8f4afc930ca1cda0b43638cc678" rel="noreferrer" 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,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit;color:rgb(0,89,153)"><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,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-size:13px;vertical-align:baseline;box-sizing:inherit;background-color:rgb(239,240,241);white-space:pre-wrap">AVSEEK_FLAG_BACKWARD</code></a>  to seek to the closest <i>keyframe</i> 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><br></div><div>--michael</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 8, 2019 at 10:53 AM Mark McKay <<a href="mailto:mark@kitfox.com">mark@kitfox.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);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:rgb(0,128,0)">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:rgb(0,0,0)">    int timestamp = av_rescale_q(timeMs, AV_TIME_BASE_Q,</span>
<pre style="text-indent:0px;margin:0px"><span style="color:rgb(0,0,0)">                              pFormatCtx->streams[videoStream]->time_base);</span></pre>
<span style="color:rgb(0,0,0)">    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:rgb(0,128,0)">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:rgb(0,0,128)">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" target="_blank">http://www.kitfox.com</a></pre>
</div>_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">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" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".</blockquote></div>