[MPlayer-dev-eng] [patch] matroska demuxer reports incorrect AC-3 bitrate

Matthias Hopf mat at mshopf.de
Fri May 4 16:59:17 CEST 2007


Hi Trent,

On Apr 24, 07 17:38:45 -0700, Trent Piepho wrote:
> When a Matroska file contains an AC-3 stream, the mkv demuxer fills in the
> audio stream header structure field ->wh->nAvgBytesPerSec with a constant
> value of 16000.  Of course this is wrong unless the AC-3 stream happens to
> be 128 kbit/sec.

AC3 streams are inherently of variable bitrate, so I don't think a fixed
value will ever work right.

> This messes up mencoder when using -oac copy.  Mencoder always thinks ac3
> in mkv is 128 kbits and outputs the audio at this rate, then tries to sync
> the video to match.
> 
> This patch fixes the problem by stopping the mkv demuxer from creating a
> wave extension field for the audio stream header for AC-3 streams, since
> the mkv demuxer has nothing correct to put in this field.  mencoder will
> get the correct ac3 bit rate the same way it does for other demuxers, which
> also don't create wave extension fields for ac3 streams.

I can confirm, that this improves the situation with ac3 stream
significantly! The PTS look steady now, but there's still the issue that
there's a constant A/V offset throughout the whole encoding, which
varies from file to file (I got -150 to +200ms offset, determined by
watching the resulting encoding, especially scenes with pistol shots).

Situation with DTS is worse, I get stuttering audio (approx. one click
per second), and one frame per approx. 1-2 seconds of video is skipped.

I have yet to find a short enough sample that clearly exhibits these
issues. I'll post when I find one.

Until the source of this issue is found it might be a good idea to
include this patch, as it *significantly* improves the situation.

> ===================================================================
> --- libmpdemux/demux_mkv.c      (revision 23107)
> +++ libmpdemux/demux_mkv.c      (working copy)
> @@ -2098,8 +2098,8 @@
>    else if ((track->a_formattag == 0x2000) || /* AC3 */
>             (track->a_formattag == 0x2001)) /* DTS */
>      {
> -      sh_a->wf->nAvgBytesPerSec = 16000;
> -      sh_a->wf->nBlockAlign = 1536;
> +      free(sh_a->wf);
> +      sh_a->wf = NULL;
>      }
>    else if (track->a_formattag == 0x0001)  /* PCM || PCM_BE */
>      {


Thanks

Matthias

-- 
Matthias Hopf <mhopf at suse.de>      __        __   __
Maxfeldstr. 5 / 90409 Nuernberg   (_   | |  (_   |__          mat at mshopf.de
Phone +49-911-74053-715           __)  |_|  __)  |__  R & D   www.mshopf.de



More information about the MPlayer-dev-eng mailing list