[Libav-user] What's the ultimate correct way of seeking
nfxjfg at googlemail.com
Thu Oct 30 23:11:16 CET 2014
On Thu, 30 Oct 2014 22:38:12 +0100
Info || Non-Lethal Applications <info at non-lethal-applications.com>
> [Libav-user] What's the ultimate correct way of seeking
None. libavformat can be pretty bad at seeking. Sometimes it simply
doesn't handle it correctly at all. You could probably improve it for
some formats by poking their implementations.
> 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.
No. libavformat will seek to keyframes only (if that concept even
applies; sometimes there's no such thing as "keyframes" in the stream).
Also, the framerate (depending on the source) can be wrong.
Generally, you have to seek by timestamps. If you set the
AVSEEK_FLAG_BACKWARD flag, and there's no keyframe with the requested
timestamp, it will seek to the first keyframe before that. Then you can
decode some frames until you reach the one with the target timestamp.
> 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.
Many file formats don't really have a proper concept of frame numbers.
> 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)?
This "new API" is completely worthless.
More information about the Libav-user