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.

 

Go Back   Doom9's Forum > General > Audio encoding

Reply
 
Thread Tools Search this Thread Display Modes
Old 13th June 2020, 14:11   #1  |  Link
orion44
None
 
orion44's Avatar
 
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?
orion44 is offline   Reply With Quote
Old 13th June 2020, 21:26   #2  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
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.
tebasuna51 is offline   Reply With Quote
Old 13th June 2020, 22:20   #3  |  Link
orion44
None
 
orion44's Avatar
 
Join Date: Jul 2007
Location: The Background
Posts: 265
Quote:
Originally Posted by tebasuna51 View Post
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)
orion44 is offline   Reply With Quote
Old 15th November 2021, 03:02   #4  |  Link
orion44
None
 
orion44's Avatar
 
Join Date: Jul 2007
Location: The Background
Posts: 265
Quote:
Originally Posted by tebasuna51 View Post
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?
orion44 is offline   Reply With Quote
Old 15th November 2021, 14:26   #5  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,435
Quote:
Originally Posted by orion44 View Post
...
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.
tebasuna51 is offline   Reply With Quote
Old 15th November 2021, 23:15   #6  |  Link
orion44
None
 
orion44's Avatar
 
Join Date: Jul 2007
Location: The Background
Posts: 265
Quote:
Originally Posted by tebasuna51 View Post
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?
orion44 is offline   Reply With Quote
Old 16th November 2021, 11:10   #7  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,435
Quote:
Originally Posted by orion44 View Post
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.
tebasuna51 is offline   Reply With Quote
Old 14th June 2020, 11:04   #8  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
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.
tebasuna51 is offline   Reply With Quote
Old 14th June 2020, 14:38   #9  |  Link
orion44
None
 
orion44's Avatar
 
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?
orion44 is offline   Reply With Quote
Old 15th June 2020, 01:30   #10  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
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.
tebasuna51 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:07.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.