[Libav-user] Seek backward

Gabriele Greco gabriele.greco at wyscout.com
Fri Dec 23 17:29:13 EET 2016


I'm trying to find a consistent way to seek backward with an
avcodec/avformat based player, supporting different codec and containers.

What I do at the moment is:

av_seek_frame(ictx, video_track, dest_pts, 0);
avcodec_flush_buffers(vctx);
avcodec_flush_buffers(actx);

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:

performing seek to 2046 (51149999) actual pts:51200000
got frame pts:51200000

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.

There is some advanced method (also with some encoding overhead) to perform
this being almost sure to go to the desired position?

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...

-- 
*Bye, *
*Gabry*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20161223/f312f6f3/attachment.html>


More information about the Libav-user mailing list