[Libav-user] How to seek to a given frame?
Philippe Gorley
philippe.gorley at savoirfairelinux.com
Thu May 9 16:00:13 EEST 2019
On 2019-05-08 10:27 p.m., Mark McKay wrote:
> 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.
AVSEEK_FLAG_BACKWARD is ignored in avformat_seek_file, not in av_seek_frame.
>
> Mark
>
>
> ------------------------------------------------------------------------
> *Subject:* Re: [Libav-user] How to seek to a given frame?
> *Date:* Wed, 8 May 2019 13:20:17 -0700
> *From:* Michael Armes <michael.armes at gmail.com>
> *To:* "This list is about using libavcodec, libavformat, libavutil,
> libavdevice and libavfilter." <libav-user at ffmpeg.org>
> *Reply-To:* "This list is about using libavcodec, libavformat,
> libavutil, libavdevice and libavfilter." <libav-user at ffmpeg.org>
> Use |AVSEEK_FLAG_BACKWARD|
> <http://ffmpeg.org/doxygen/trunk/avformat_8h.html#ac736f8f4afc930ca1cda0b43638cc678> to
> seek to the closest /keyframe/ 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).
> --michael
>
> On Wed, May 8, 2019 at 10:53 AM Mark McKay <mark at kitfox.com
> <mailto:mark at kitfox.com>> wrote:
>
> I'm trying to create a video player with the ability to seek
> whereever I want. I'm having some trouble with av_seek_frame(),
> which seems to keep returning the first keyframe after the timestamp
> I'm looking for:
>
>
> int timestamp = av_rescale_q(timeMs, AV_TIME_BASE_Q,
>
> pFormatCtx->streams[videoStream]->time_base);
>
> int err = av_seek_frame(pFormatCtx, videoStream, timestamp, 0);
>
> 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 AVSEEK_FLAG_ANY,
> 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.
>
> I'm also considering scanning the entire video when I first load it
> to build an index of packet information. AVSEEK_FLAG_BYTE 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.
>
> How can I scan to the frame that I want?
>
> Cheers,
> Mark
>
> ---
> http://www.kitfox.com
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org <mailto:Libav-user at ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org <mailto:libav-user-request at ffmpeg.org>
> with subject "unsubscribe".
>
> ---
> http://www.kitfox.com
>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
--
Philippe Gorley
Free Software Consultant | Montréal, Qc
Savoir-faire Linux
More information about the Libav-user
mailing list