<div dir="ltr">Hello Everyone,<br><br>I am trying to seek my audio ogg file with the following: <br><br><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Consolas,monospace;font-size:12pt"></pre><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Consolas,monospace;font-size:12pt"><span style="color:rgb(185,188,209)">int64_t </span>targetPts = av_rescale_q(seekTimeMicro<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">AV_TIME_BASE_Q</span><span style="color:rgb(204,120,50)">, </span>streamTimeBase)<span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)"><br></span>av_seek_frame(avFormatContext<span style="color:rgb(204,120,50)">, </span>streamInfoIndex<span style="color:rgb(204,120,50)">, </span>targetPts<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">AVSEEK_FLAG_BACKWARD</span>)<span style="color:rgb(204,120,50)">;</span></pre></div><div><br></div><div>This works all fine. Most of the time AVSEEK_FLAG_BACKWARD makes sure that the stream is seeked to a time before targetPts. However, there are times the opposite happens, seeking a time after 

targetPts. I can see this with the first frame I request from avcodec_receive_frame() having pts (avFrame->pts) greater than my targetPts. I need to ensure that the first frame I receive is always smaller than my targetPts. (it's an overhead in my system, long story).<br><br>I read it that <a href="https://stackoverflow.com/questions/20734814/ffmpeg-av-seek-frame-with-avseek-flag-any-causes-grey-screen">here</a>: "It appears that, for some reason, av_seek_frame() using AVSEEK_FLAG_BACKWARD returns the next keyframe when the frame that I am seeking is the one directly before this keyframe. Otherwise it returns the previous keyframe (which is what I want).". I suspect that this is the case. However, this post is too old so it might be outdated.<br><br>Could you help me?<br>Thank you!</div><div><br></div><div><br></div></div>