[Libav-user] Building an index for arbitrary-frame-accurate VBR seeking use byte offset

rin tec tecrin705 at gmail.com
Fri Dec 17 20:18:04 EET 2021


<stelefx at gmail.com>

> I have various videos that are VBR and don't have an accurate duration
> or frame rate.
>
> I wrote some code to index the files by reading through the whole thing
> by packet and recording the pts, byte offset, and duration for each
> frame, and recording which ones are I-frames. This also allows getting
> an accurate duration for the files that didn't have one too.
>
> Now I'm attempting to use the index to jump to any arbitrary frame, by
> first seeking to the byte offset of the I-frame before the desired
> frame, and then decoding packets until the desired number of
> non-I-frames are processed.
>
> I've tried this both using the byte offset and with the pts of that
> reference I-frame, but in many cases I'm getting repeating "loops" in
> the video.
>
> This is probably my misunderstanding of what the fields in the AVFrame
> are. While building the index, I'm using a loop of av_read_frame() and
> avcodec_decode_video2(). When I get a picture, and if key_frame is set,
> I record the frame's pkt_pos, pts, and pkt_dts values in a dictionary
> keyed by the frame number.
>
> When I seek to an arbitrary frame, I look up the first entry in the
> dictionary with the frame # I'm looking for, and then to:
>
> av_seek_frame(context, video_stream_index, pkt_pos_for_nearest_iframe,
> AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_BYTES);
>
> Then if the frame I'm looking for is not an I-frame, I repeat the
> av_frame_read/avcodec_decode_video2 loop until I get to that frame number.
>
> Does anyone have any experience with this kind of thing who could tell
> me what I'm doing wrong?
>
>
> ______________________________


Check the video stream first? Sometimes the video stream were already
broken so the codec cannot decode the stream.

Or you also can use other codec(such as libx264 or libx265). And check the
others codec output.

> _________________
> 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".
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20211218/6f14410c/attachment.htm>


More information about the Libav-user mailing list