[Libav-user] What's the ultimate correct way of seeking

Info || Non-Lethal Applications info at non-lethal-applications.com
Thu Oct 30 22:38:12 CET 2014

Hey there,

got another question regarding seeking in QuickTime and MXF containers.
For my own video player, I need frame-accurate access to all video frames in the file stream.

So far I’m using this code:

int64_t seekPos = ((theFrameIndex/self.frameRate) * 1000000);
av_seek_frame(self.formatContext, -1, seekPos, AVSEEK_FLAG_BACKWARD);

It works pretty well for all intra-frame only codecs I’ve tried so far.
However, when using inter frame codecs like H.264, it doesn’t work properly.

Whenever I’m one frame after a keyframe and want to move backwards by one frame, 
seeking using the above code does not yield the previous I-frame but rather the next keyframe.

I could solve the issue by simply modifying the seek position to be one frame earlier than the actual desired frame index.

int64_t oneFrame = (1.0/self.frameRate) * 1000000;
seekPos -= oneFrame;

However, with some MXF files this also didn’t help.

Thus, I’d like to ask what the correct way of seeking really is at the time being.
I’m assuming that I’m not the only one that wants to seek to defined frame indices.

I read in the source files that there’s a new seeking API  (avformat_seek_file).
Are there any information as to when this will be available and if this addresses the issue (in case it’s not just my problem)?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20141030/0ab043ba/attachment.html>

More information about the Libav-user mailing list