[Libav-user] Libavformat - Guranteed seeking before keyframe

ilkercan Kaya canilkerkaya at gmail.com
Wed Mar 3 18:31:03 EET 2021

In case this got lost, I'm kindly replying to this thread.

On Sun, Feb 21, 2021, 04:20 ilkercan Kaya <canilkerkaya at gmail.com> wrote:

> Hello Everyone,
> I am trying to seek my audio ogg file with the following:
> int64_t targetPts = av_rescale_q(seekTimeMicro, AV_TIME_BASE_Q, streamTimeBase);
> av_seek_frame(avFormatContext, streamInfoIndex, targetPts, AVSEEK_FLAG_BACKWARD);
> 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).
> I read it that here
> <https://stackoverflow.com/questions/20734814/ffmpeg-av-seek-frame-with-avseek-flag-any-causes-grey-screen>:
> "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.
> Could you help me?
> Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210303/f74804f3/attachment.html>

More information about the Libav-user mailing list