<div dir="ltr">I'm trying to find a consistent way to seek backward with an avcodec/avformat based player, supporting different codec and containers.<div><br></div><div>What I do at the moment is:</div><div><br></div><div>av_seek_frame(ictx, video_track, dest_pts, 0);</div><div>avcodec_flush_buffers(vctx);</div><div>avcodec_flush_buffers(actx);</div><div><br></div><div>And it works well if the dest_pts is "far" from the actual pts, but if I try to seek for instance 2 seconds before the actual position I often get as first frame the same pts of the actual position... here is a log fragment:</div><div><br></div><div><div>performing seek to 2046 (51149999) actual pts:51200000</div><div>got frame pts:51200000</div></div><div><div><br></div><div>I think the problem is related to the keyframe distribution in the stream, since it works ok with some files and does not with other, also with the same codec/container but probabily with different keyframe intervals.</div><div><br></div><div>There is some advanced method (also with some encoding overhead) to perform this being almost sure to go to the desired position?</div><div><br></div><div>The only thing I can think is to jump backward 30 seconds and then decode 28 seconds of audio/video without displaying it, so that I can stop to -2 secs, also if the frame is a B frame. This will fail anyway if the I frame distance is more than 30 secs... and it will be really heavy for the CPU with the 1080p streams I'm working usually with...</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div><div><b>Bye, </b></div></div><div><b>Gabry</b></div></div></div></div>
</div></div>