<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Replying to myself here- <br>
</p>
<p>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.</p>
<p>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.<br>
</p>
<div class="moz-cite-prefix">On 12/17/21 12:18 PM, rin tec wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAM2fLaSpwH923rzFe6Af3dh2b68MVK7u3GQdRCQzgsbf4xGuXA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="auto">
<div><br>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr"> <<a
href="mailto:stelefx@gmail.com" target="_blank"
rel="noreferrer" moz-do-not-send="true"
class="moz-txt-link-freetext">stelefx@gmail.com</a>> <br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">I have
various videos that are VBR and don't have an accurate
duration <br>
or frame rate.<br>
<br>
I wrote some code to index the files by reading through
the whole thing <br>
by packet and recording the pts, byte offset, and duration
for each <br>
frame, and recording which ones are I-frames. This also
allows getting <br>
an accurate duration for the files that didn't have one
too.<br>
<br>
Now I'm attempting to use the index to jump to any
arbitrary frame, by <br>
first seeking to the byte offset of the I-frame before the
desired <br>
frame, and then decoding packets until the desired number
of <br>
non-I-frames are processed.<br>
<br>
I've tried this both using the byte offset and with the
pts of that <br>
reference I-frame, but in many cases I'm getting repeating
"loops" in <br>
the video.<br>
<br>
This is probably my misunderstanding of what the fields in
the AVFrame <br>
are. While building the index, I'm using a loop of
av_read_frame() and <br>
avcodec_decode_video2(). When I get a picture, and if
key_frame is set, <br>
I record the frame's pkt_pos, pts, and pkt_dts values in a
dictionary <br>
keyed by the frame number.<br>
<br>
When I seek to an arbitrary frame, I look up the first
entry in the <br>
dictionary with the frame # I'm looking for, and then to:<br>
<br>
av_seek_frame(context, video_stream_index,
pkt_pos_for_nearest_iframe, <br>
AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_BYTES);<br>
<br>
Then if the frame I'm looking for is not an I-frame, I
repeat the <br>
av_frame_read/avcodec_decode_video2 loop until I get to
that frame number.<br>
<br>
Does anyone have any experience with this kind of thing
who could tell <br>
me what I'm doing wrong?<br>
<br>
<br>
______________________________</blockquote>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">Check the video stream first? Sometimes the
video stream were already broken so the codec cannot decode
the stream.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Or you also can use other codec(such as libx264
or libx265). And check the others codec output.</div>
<div dir="auto">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" rel="noreferrer
noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user"
rel="noreferrer noreferrer noreferrer" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org"
rel="noreferrer noreferrer" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">libav-user-request@ffmpeg.org</a>
with subject "unsubscribe".<br>
</blockquote>
</div>
</div>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Libav-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a>
<a class="moz-txt-link-freetext" href="https://ffmpeg.org/mailman/listinfo/libav-user">https://ffmpeg.org/mailman/listinfo/libav-user</a>
To unsubscribe, visit link above, or email
<a class="moz-txt-link-abbreviated" href="mailto:libav-user-request@ffmpeg.org">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".
</pre>
</blockquote>
</body>
</html>