Potential Bug - "Dolby Pro Logic ii" audio filter swaps the rear channels

Started by jmitz5, March 12, 2022, 04:19:43 PM

Previous topic - Next topic

jmitz5

I have tried multiple Mac versions and the latest Windows version of Avidemux, it looks like all of them have the same problem: When converting 5.1 audio to 2 channel DPLii, the rear left and rear right channels are swapped. This is plainly apparent by importing the resulting audio into a program like Audacity. I have tested this problem with a few 5.1 audio test files (which I know to be correct), and all of them are louder in Lt when the right rear channel is supposed to be playing, and louder in Rt when the left rear channel is supposed to be playing. This means that they will be flipped when decoded.

Is this a bug, or am I doing something wrong? Is there a way to remap audio channels in Avidemux before applying filters so I can counteract this?

eumagga0x2a

I never used any 2-channel downmixing option other than stereo, so while I can confirm that the rear right channel from a 5.1 audio track is more audible in the first stereo channel (i.e. left) and the rear left in the second one, I don't know precisely what to expect. What is the point of using this downmixing option? Do you target some equipment with a Dolby Pro Logic decoder to re-create some surround experience?

jmitz5

Yes, Dolby Pro Logic is a system that encodes directional information into a stereo audio signal, mixing each channel into the stereo output with a different phase and relative volume. The relative phase and volume of the sounds in the final stereo mixdown (Lt and Rt) are what determine which speaker the sounds get directed to on playback. The system isn't as precise as discrete surround sound, but it's good for decreasing the file size of surround sound audio, and for getting surround sound support in places that only officially support stereo (like Youtube).

The correct relative gain values are shown in this wikipedia listing:
https://en.wikipedia.org/wiki/Matrix_decoder#Dolby_Pro_Logic_II_matrix_(5:2:5)
You can see that the rear right channel is supposed to be louder in Rt and the rear left channel is supposed to be louder in Lt.

I was actually really happy to discover the DPLii downmix option in Avidemux, because it is a lot more faithful than similar options I have seen in other programs like Handbrake and Subler (since it treats the channels symmetrically and preserves the LFE channel). But this channel swap bug is really annoying.

Can this bug be fixed? Or if it can't be fixed, is there at least a way to remap the channels without re-encoding, so I can "pre-swap" the rear channels before using the DPLii downmix option? I have tested pre-swapping in audacity and it seems like it works just fine, but it is really inconvenient. I should probably specify that I mainly use Mac.

eumagga0x2a

Quote from: jmitz5 on March 14, 2022, 04:57:06 AMThe correct relative gain values are shown in this wikipedia listing:
https://en.wikipedia.org/wiki/Matrix_decoder#Dolby_Pro_Logic_II_matrix_(5:2:5)
You can see that the rear right channel is supposed to be louder in Rt and the rear left channel is supposed to be louder in Lt.

The matrix in Avidemux seems to be more or less correct, but phase shift results in perceived loudness of rear left and right channels being swapped. I don't know what a DPL2 decoder expects, so I just confirm the behaviour. It is also massively different from the behaviour of aresample filter in ffmpeg, which keeps left and right channels of all sorts completely separated.

Quote from: jmitz5 on March 14, 2022, 04:57:06 AMCan this bug be fixed?

Sure, but probably not by me.

Quote from: jmitz5 on March 14, 2022, 04:57:06 AMis there at least a way to remap the channels without re-encoding, so I can "pre-swap" the rear channels before using the DPLii downmix option?

No, this is not possible in Avidemux and it presumably would not make the output stream a valid input for a DPL2 decoder.

szlldm

Quick ffmpeg test with
-af "aresample=matrix_encoding=dplii"results no perceived rear channel swap.

eumagga0x2a

szlldm has modified / fixed Dolby downsampling modes so that the result matches the channel location expected by human ear. Please try a future nightly build.