5.1 / Multichannel Audio does not downmix/convert right

Archive of historical bug reports.
Please use the GitHub link above to report issues.
Forum rules
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.

*******************************
Post Reply
DReffects
Posts: 4
Joined: Sat Dec 26, 2009 4:15 am

5.1 / Multichannel Audio does not downmix/convert right

Post by DReffects »

Hey Guys!

well, i've been waiting for a tool like this for ages. the only thing that got me worried is, that the downmix of ac3 / multichannel-audio does not seem to work properly.

It becomes stereo alright, but the playback is WAYYYY to slow. Its like a khz conversion gone wrong (when you simply set another khz rate and the audiofile becomes much slower instead of actually converting the audio)

If tried with all settings from automatic over stereo to mono - always the same result. I've used Apple Quicktime Trailers as input.

Code: Select all

[05:12:39] 2 job(s) to process
[05:12:39] starting job
[05:12:39] job configuration:
[05:12:39]  * source
[05:12:39]    + terminatorsalvation-tlr3_h1080p.mov
[05:12:39]    + title 1, chapter(s) 1 to 1
[05:12:39]    + container: mov,mp4,m4a,3gp,3g2,mj2
[05:12:39]    + data rate: 11142 kbps
[05:12:39]  * destination
[05:12:39]    + test1080p1000kbit.mp4
[05:12:39]    + container: MPEG-4 (.mp4 and .m4v)
[05:12:39]  * video track
[05:12:39]    + decoder: h264
[05:12:39]    + frame rate: same as source (around 23.976 fps)
[05:12:39]    + strict anamorphic
[05:12:39]      + modulus: 0
[05:12:39]      + storage dimensions: 1920 * 800 -> 1920 * 800, crop 0/0/0/0
[05:12:39]      + pixel aspect ratio: 1 / 1
[05:12:39]      + display dimensions: 1920 * 800
[05:12:39]    + filters
[05:12:39]      + Detelecine (pullup) (default settings)
[05:12:39]      + Decomb (default settings)
[05:12:39]    + encoder: x264
[05:12:39]      + options: b-adapt=2:rc-lookahead=50:ref=6:direct=auto:b-pyramid=1:subq=9:me=tesa:merange=32
[05:12:39]      + bitrate: 800 kbps, pass: 1
[05:12:39]  * audio track 0
[05:12:39]    + decoder: English (AAC) (track 1, id 1)
[05:12:39]    + mixdown: Stereo
[05:12:39]    + encoder: faac
[05:12:39]      + bitrate: 128 kbps, samplerate: 44100 Hz
libdvdnav: Using dvdnav version 4.1.3
libdvdread: Using libdvdcss version 1.2.10 for DVD access
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[05:12:39] dvd: not a dvd - trying as a stream/file instead
[05:12:39] yadif thread started for segment 0
[05:12:39] yadif thread started for segment 1
[05:12:39] decomb thread started for segment 0
[05:12:39] decomb thread started for segment 1
[05:12:39] encx264: keyint-min: 24, keyint-max: 240
[05:12:39] encx264: encoding with stored aspect 1/1
x264 [warning]: b-pyramid + mb-tree is not supported
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[05:12:39] reader: first SCR 0 id 1 DTS 0
x264 [info]: profile High, level 5.0
[05:12:39] sync: expecting 3601 video frames
Encoding: task 1 of 2, 19.74 % (2.12 fps, avg 1.89 fps, ETA 00h25m27s))
Can anyone confirm this? :)

Thanks!
Daniel

PS: hi^^
User avatar
JohnAStebbins
HandBrake Team
Posts: 5585
Joined: Sat Feb 09, 2008 7:21 pm

Re: 5.1 / Multichannel Audio does not downmix/convert right

Post by JohnAStebbins »

the downmix of ac3 / multichannel-audio does not seem to work properly
Your source is not ac3. it's aac. Since you didn't post a complete log I can't confirm this, but it is probably multi-channel aac. Handbrake has a known problem with multi-channel aac.
DReffects
Posts: 4
Joined: Sat Dec 26, 2009 4:15 am

Re: 5.1 / Multichannel Audio does not downmix/convert right

Post by DReffects »

JohnAStebbins wrote:Your source is not ac3. it's aac. Since you didn't post a complete log I can't confirm this, but it is probably multi-channel aac. Handbrake has a known problem with multi-channel aac.
Ah sorry, my fault. I sort of use 'ac3' as a term for 'all things multichannel' ;)

The Source is in fact AAC 5.1. If you're intrested: I have a nifty patch for the resample.c file from libavcodec for ffmpeg that can handle all 5.1 downmixing to stereo
User avatar
Rodeo
HandBrake Team
Posts: 12746
Joined: Tue Mar 03, 2009 8:55 pm

Re: 5.1 / Multichannel Audio does not downmix/convert right

Post by Rodeo »

DReffects wrote:If you're intrested: I have a nifty patch for the resample.c file from libavcodec for ffmpeg that can handle all 5.1 downmixing to stereo
We've discussed this on IRC and we'd like to give your patch a try. Could you pastebin it somewhere?
DReffects
Posts: 4
Joined: Sat Dec 26, 2009 4:15 am

Re: 5.1 / Multichannel Audio does not downmix/convert right

Post by DReffects »

here you go. works for all ffmpeg versions. though with some versions center, front right and front left channels are switched. found this ages ago somewhere and modified it a little bit.

Code: Select all

Index: libavcodec/resample.c
===================================================================
--- libavcodec/resample.c	(revision 11509)
+++ libavcodec/resample.c	(working copy)
@@ -37,6 +37,17 @@
     int input_channels, output_channels, filter_channels;
 };
 
+/*
+*/
+static short clip_short(int v) {
+    if (v < -32768)
+        v = -32768;
+    else if (v > 32767)
+        v = 32767;
+    return (short) v;
+}
+
+
 /* n1: number of samples */
 static void stereo_to_mono(short *output, short *input, int n1)
 {
@@ -88,14 +99,43 @@
     }
 }
 
-/* XXX: should use more abstract 'N' channels system */
-static void stereo_split(short *output1, short *output2, short *input, int n)
-{
+/* XXX: make this better.  channels will always be >= 2.
+ - Left = front_left + rear_gain * rear_left + center_gain * center
+ - Right = front_right + rear_gain * rear_right + center_gain * center
+ where rear_gain is usually around 0.5-1.0 and center_gain is almost always 0.7 (-3 dB) if I recall correctly.  */
+static void multi_to_stereo_split(short *output1, short *output2, short *input, int n, int channels) {
     int i;
+    short l,r;
 
     for(i=0;i<n;i++) {
-        *output1++ = *input++;
-        *output2++ = *input++;
+        if (channels == 2) {
+            /* simple stereo to stereo. Input is: l, r */
+            l = input[0];
+            r = input[1];
+        } else if (channels == 6) {
+            /* 5.1 to stereo. l, c, r, ls, rs, sw */
+            int fl,fr,c,rl,rr,lfe;
+            fl = input[0];
+            c = input[2];
+            fr = input[1];
+            rl = input[3];
+            rr = input[4];
+            lfe = input[5];
+
+            l = clip_short(fl + (0.5 * rl) + (0.7 * c));
+            r = clip_short(fr + (0.5 * rr) + (0.7 * c));
+        } else {
+            /* channels must be 3-5, or >= 7. l, c, r, ? */
+            l = input[0];
+            r = input[2];
+        }
+
+        /* output l & r. */
+        *output1++ = l;
+        *output2++ = r;
+
+        /* increment input. */
+        input += channels;
     }
 }
 
@@ -131,9 +171,9 @@
 {
     ReSampleContext *s;
 
-    if ( input_channels > 2)
+	 if ((input_channels > 2) && (input_channels != 6))
       {
-        av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than 2 unsupported.\n");
+		av_log(NULL, AV_LOG_ERROR, "Resampling with input channels other than 1,2, or 6 is unsupported.\n");
         return NULL;
       }
 
@@ -205,7 +245,7 @@
     } else if (s->output_channels >= 2) {
         buftmp3[0] = bufout[0];
         buftmp3[1] = bufout[1];
-        stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);
+        multi_to_stereo_split(buftmp2[0], buftmp2[1], input, nb_samples, s->input_channels);
     } else {
         buftmp3[0] = output;
         memcpy(buftmp2[0], input, nb_samples*sizeof(short));
mac_man_ad
Regular User
Posts: 75
Joined: Wed Aug 22, 2007 5:21 am

Re: 5.1 / Multichannel Audio does not downmix/convert right

Post by mac_man_ad »

DReffects,
What happens to the subwoofer channel with this patch? Seems to me to be ignored, and surely losing this sound information can't be proper behavior.
tlindgren
Bright Spark User
Posts: 245
Joined: Sun May 03, 2009 2:14 pm

Re: 5.1 / Multichannel Audio does not downmix/convert right

Post by tlindgren »

mac_man_ad wrote:DReffects,
What happens to the subwoofer channel with this patch? Seems to me to be ignored, and surely losing this sound information can't be proper behavior.
Postings on the Doom9 say that Dolby specifically says the LFE (.1) channel should usually be ignored during downmixing to Dolby ProLogic II, with quotes from official Dolby documentation.

The exception is if "unless it contains unique information that is not repeated in any of the five main channels", it's not a problem when it's done by the person doing the original 5.1 mix though but it sure messes things up for everyone else :!:

Anyway, most downmixes seems to drop the LFE channel so I think we can conclude that most 5.1 tracks do have bass on at least one of the other channels as recommended (center channel?). It may make sense to offer two different Prologic II downmixes but that complicates things quite a bit.

http://forum.doom9.org/showthread.php?t=133884
User avatar
Rodeo
HandBrake Team
Posts: 12746
Joined: Tue Mar 03, 2009 8:55 pm

Re: 5.1 / Multichannel Audio does not downmix/convert right

Post by Rodeo »

FWIW, this is fixed as of http://trac.handbrake.fr/changeset/3182
Post Reply