Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 Doom9's Forum What formula does FFmpeg use when converting 5.1 AC3 to stereo wav?
 Register FAQ Calendar Search Today's Posts Mark Forums Read

 13th June 2020, 14:11 #1  |  Link orion44 None     Join Date: Jul 2007 Location: The Background Posts: 265 What formula does FFmpeg use when converting 5.1 AC3 to stereo wav? When converting 5.1 AC3 to stereo WAV: Code: `ffmpeg -i AC3_51.ac3 -ac 2 Stereo.wav` what is the exact formula that '-ac 2' option uses in the background?
 13th June 2020, 21:26 #2  |  Link tebasuna51 Moderator     Join Date: Feb 2005 Location: Spain Posts: 6,435 FL' = FL + 0.7xFC + 0.7xSL FR' = FR + 0.7xFC + 0.7xSR __________________ BeHappy, AviSynth audio transcoder.
13th June 2020, 22:20   #3  |  Link
orion44
None

Join Date: Jul 2007
Location: The Background
Posts: 265
Quote:
 Originally Posted by tebasuna51 FL' = FL + 0.7xFC + 0.7xSL FR' = FR + 0.7xFC + 0.7xSR
Thanks.

I'm trying to exactly replicate the "-ac 2" option with pan filter command. I've found the following via google search:

Code:
`ffmpeg -i AC3_51.ac3 -af "pan=stereo|FL < 1.0*FL + 0.707*FC + 0.707*BL|FR < 1.0*FR + 0.707*FC + 0.707*BR" Stereo.wav`
Code:
`ffmpeg -i AC3_51.ac3 -af "pan=stereo|FL = 1.0*FL + 0.707*FC + 0.707*BL|FR = 1.0*FR + 0.707*FC + 0.707*BR" Stereo.wav`
Do any of the above two lines replicate exactly the "-ac 2" option?

Which of the two lines is the correct one? (note the "<" and "=" difference)

14th June 2020, 11:04   #4  |  Link
tebasuna51
Moderator

Join Date: Feb 2005
Location: Spain
Posts: 6,435
From ffmpeg docs:

Quote:
 If the ‘=’ in a channel specification is replaced by ‘<’, then the gains for that specification will be renormalized so that the total is 1, thus avoiding clipping noise.
The -ac 2 is equivalent to:
-af "pan=stereo|FL = 1.0*FL + 0.707*FC + 0.707*SL|FR = 1.0*FR + 0.707*FC + 0.707*SR"

FL' = FL + 0.7xFC + 0.7xSL
FR' = FR + 0.7xFC + 0.7xSR

The < option:
-af "pan=stereo|FL < 1.0*FL + 0.707*FC + 0.707*SL|FR < 1.0*FR + 0.707*FC + 0.707*SR"

Is equivalent to:
FL' = 0.414xFL + 0.293xFC + 0.293xSL
FR' = 0.414xFR + 0.293xFC + 0.293xSR

This avoid clipping noise(sum of coeficients = 1) but you can finish with low volume.

Note the SL,SR channels instead BL,BR in your samples. By default the surround channels are SL,SR (Side not Back, default longtime ago).

The canonical downmix is:

FL' = FL + 0.7xFC + SL
FR' = FR + 0.7xFC + SR

the ffmpeg default downmix lose surround volume
Normalized (sum of coeficients = 1):

FL' = 0.37xFL + 0.26xFC + 0.37xSL
FR' = 0.37xFR + 0.26xFC + 0.37xSR

To do a correct normalization, with the max volume without clip, you need do 2 pass (like AviSynth do).
__________________
BeHappy, AviSynth audio transcoder.

 14th June 2020, 14:38 #5  |  Link orion44 None     Join Date: Jul 2007 Location: The Background Posts: 265 Do popular software players, like PotPlayer and KMPlayer, use the same downmix as the "-ac 2" option when decoding 5.1 AC3 to stereo?
 15th June 2020, 01:30 #6  |  Link tebasuna51 Moderator     Join Date: Feb 2005 Location: Spain Posts: 6,435 You can configure the dowmix like you want. I have attached a 7.1 system but if you have a 2.0 you can mix, in mpc-hc: Attached Images   __________________ BeHappy, AviSynth audio transcoder.
15th November 2021, 03:02   #7  |  Link
orion44
None

Join Date: Jul 2007
Location: The Background
Posts: 265
Quote:
 Originally Posted by tebasuna51 FL' = FL + 0.7xFC + 0.7xSL FR' = FR + 0.7xFC + 0.7xSR
When downmixing 5.1 AC3 audio to stereo WAV, is the following allowed according to the Dolby downmix parameters:

1. Attenuate FL, FR, FC, SL, SR by 6 dB?
2. Attenuate FL, FR, FC by 6 dB, and attenuate SL, SR by 9 dB?

Is any of the above in accordance with Dolby standards?

15th November 2021, 14:26   #8  |  Link
tebasuna51
Moderator

Join Date: Feb 2005
Location: Spain
Posts: 6,435
Quote:
 Originally Posted by orion44 ... Is any of the above in accordance with Dolby standards?
Nope. The allowed values are included in BSI metadata and can be:

Center Mix Level: 0.707 (–3.0 dB), or 0.595 (–4.5 dB) or 0.500 (–6.0 dB)
Surround Mix Level: 0.707 (–3 dB) or 0.500 (–6 dB)

Front Levels can't be attenuated unless you do a Normalize over all channels.
Then Front levels must be always from 3 to 6 dB over the Center and Surround levels.
__________________
BeHappy, AviSynth audio transcoder.

15th November 2021, 23:15   #9  |  Link
orion44
None

Join Date: Jul 2007
Location: The Background
Posts: 265
Quote:
 Originally Posted by tebasuna51 Nope. The allowed values are included in BSI metadata and can be: Center Mix Level: 0.707 (–3.0 dB), or 0.595 (–4.5 dB) or 0.500 (–6.0 dB) Surround Mix Level: 0.707 (–3 dB) or 0.500 (–6 dB) Front Levels can't be attenuated unless you do a Normalize over all channels. Then Front levels must be always from 3 to 6 dB over the Center and Surround levels.
Are the Center and Surround channels allowed to have differing values, or do they have to be attenuated by the same value?

For example, the Center: -3 dB or -4.5 dB, but the Surround channels: -6 dB?

16th November 2021, 11:10   #10  |  Link
tebasuna51
Moderator

Join Date: Feb 2005
Location: Spain
Posts: 6,435
Quote:
 Originally Posted by orion44 Are the Center and Surround channels allowed to have differing values, or do they have to be attenuated by the same value? For example, the Center: -3 dB or -4.5 dB, but the Surround channels: -6 dB?
Can be different and my recommendation is Center: -3 dB, Surround channels: -6 and after Normalize to a permanent downmix 2.0.

But, of course, is a user selection and can vary with the movie.
__________________
BeHappy, AviSynth audio transcoder.