<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">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">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer noreferrer noreferrer" target="_blank">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">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div></div></div>