[Libav-user] Once again about seeking in video file

adev dev androiddevmar11 at gmail.com
Fri Nov 28 22:25:04 CET 2014


I saw many threads about seeking in video files with FFMPEG. But still it
is not clear for me how to seek to specific location (in milliseconds) with
good accuracy. I know that to seek in video file it is needed to seek than
decode frames and check where we are, than seek again decode frames etc.
till we reach the exact moment we need. The best result with seeking I have
using this code:

AVRational timeBase = video_stream->time_base;

int64_t seek_pos = (int64_t)(((float)tsms)/1000 * (float)AV_TIME_BASE);

int64_t seek_target = av_rescale_q(seek_pos, AV_TIME_BASE_Q, timeBase);

av_seek_frame(format_context, video_stream_id, seek_target,
AVFMT_SEEK_TO_PTS);

But still in some videos and some places in this videos seeking is not
working perfectly. The question is if seeking to AVFMT_SEEK_TO_PTS makes
this complex algorithm of seeking in video file to have hight accuracy?
Maybe there is better implementation of seeking which considers all video
formats?

For example seeking is not working with MPEG-4 Visual file. I am using
FFMPEG 2.1. Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20141128/28dfa8d5/attachment.html>


More information about the Libav-user mailing list