[FFmpeg-devel] strange seek problem matroska and avcodec_flush_buffers

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Feb 19 11:29:11 CET 2012

On Sun, Feb 19, 2012 at 04:42:50AM -0500, Don Moir wrote:
> The strange thing is, if I don't call avcodec_flush_buffers, the damn thing works almost perfect for me. Very clean actually, no distortion but a little frame flicker.

That's probably just because the frames before and after are quite
If you really wanted to you probably could hack error concealment to
do something better than substituting a plain gray for missing
references (in this and probably many other cases, just a darker
gray seems like it would look nicer).

> I have to assume for now that SMPlayer is not calling avcodec_flush_buffers when seeking because it almost works. Just some distortion.

I'll come back to that, but that is essentially a conscious decision
on MPlayer's part.

> http://sms.pangolin.com/temp/bad_seek_matroska_strange.mkv  (2.5 mb)

Finally you _really_ found a file with intra refresh.
It has no intra frames but instead SEI NALs in which the
encoder promises that if you just decode 31 frames you'll
have a fine picture.
That of course means that you have to demux and decode 31
frames before getting any video.
So that means about one second of audio with no matching video.
Every player has trouble with that in a different way,
ffplay plays video very slowly, MPlayer displays the first frame
and then stops (IIRC this is on purpose so that people seeking
quickly through the file get "snapshots" shown as soon as possible),
I suspect some players will also just show black for about a second.
Now coming back to MPlayer just showing distortion:
I extremely hate when players rather show nothing than something
that might have minimal corruption.
Thus MPlayer instructs FFmpeg to _not_ discard any initial
non-keyframes (or in this case frames before the intra refresh
interval passed) by setting CODEC_FLAG2_SHOW_ALL.
You can change that however with -lavdopts wait_keyframe.

More information about the ffmpeg-devel mailing list