[Libav-user] Building an index for arbitrary-frame-accurate VBR seeking use byte offset
stelefx at gmail.com
stelefx at gmail.com
Fri Dec 17 23:02:41 EET 2021
Replying to myself here-
Looks like the looping was caused because I didn't
avcodec_flush_buffers() between frame seeks. Also the
AVSEEK_FLAG_BACKWARD is unnecessary when using AVSEEK_FLAG_BYTES.
I've still got one AVR file that has an odd jump near the beginning,
even though the index seems to be doing the right thing.
On 12/17/21 12:18 PM, rin tec wrote:
>
>
> <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".
>
>
> _______________________________________________
> 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/20211217/ddce699f/attachment.htm>
More information about the Libav-user
mailing list