View Full Version : What formula does FFmpeg use when converting 5.1 AC3 to stereo wav?
orion44
13th June 2020, 14:11
When converting 5.1 AC3 to stereo WAV:
ffmpeg -i AC3_51.ac3 -ac 2 Stereo.wav
what is the exact formula that '-ac 2' option uses in the background?
tebasuna51
13th June 2020, 21:26
FL' = FL + 0.7xFC + 0.7xSL
FR' = FR + 0.7xFC + 0.7xSR
orion44
13th June 2020, 22:20
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:
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
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)
tebasuna51
14th June 2020, 11:04
From ffmpeg docs (https://ffmpeg.org/ffmpeg-filters.html#toc-pan-1):
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).
orion44
14th June 2020, 14:38
Do popular software players, like PotPlayer and KMPlayer, use the same downmix as the "-ac 2" option when decoding 5.1 AC3 to stereo?
tebasuna51
15th June 2020, 01:30
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:
orion44
15th November 2021, 03:02
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?
tebasuna51
15th November 2021, 14:26
...
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.
orion44
15th November 2021, 23:15
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?
tebasuna51
16th November 2021, 11:10
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.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.