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 26th October 2018, 00:48   #1  |  Link
Exxess
Registered User
 
Join Date: Feb 2018
Posts: 1
Downmixing 5.1 to 2.0 - FFmpeg vs VLC

Hi,

I'm writing here to get some opinions on how you feel about the differences FFmpeg and VLC are handling surround to stereo downmixing.

If you don't know of the problem, here it is (I assume you have stereo speakers, and I hope I'm not the only person seeing/hearing this): Open any surround sound AC-3 file in VLC. Let FFmpeg downmix the same file to stereo and open it up in another VLC instance. Skip to a file position with dialogues and at first let the original file play for some seconds, then the one converted by FFmpeg. The latter one should be more quiet (at least it is for me).

Now let's have a look at the basics. I think the "most official" way to downmix is given in the AC-3 standard specification. It more or less says (page 95): Mix the center channel to both front channels with -3dB and mix the rear channels to the according front channel, again with -3dB. After that, coefficients are applied to re-normalize the mix.

With the basics clear, FFmpeg does exactly that. I looked it up in the sources (you will need ac3.h, ac3_parser.c and ac3dec.c in the libavcodec directory). The results sound the same if you use
Code:
-ac 2
or
-af "pan=stereo|FL < 1.0*FL + 0.707*FC + 0.707*BL|FR < 1.0*FR + 0.707*FC + 0.707*BR"
When you have a look at the VLC source code (modules/audio_filter/channel_mixer/simple.c), it just does the mixing part, but it seems that it doesn't re-normalize afterwards (or I overlooked the code for that).

My opinion when comparing these two outputs is that the downmix VLC does is more clearly understandable than the one FFmpeg does. Do you get my point? What's your opinion?

Last edited by Exxess; 26th October 2018 at 00:48. Reason: typo
Exxess is offline   Reply With Quote
Old 26th October 2018, 02:50   #2  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,883
I see...
Yes, they might be different, but I never trusted VLC anyway.
In this specific case, it seems that VLC has effects and other sounds slightly higher than it should be compared to the speech.
FFmpeg should also be able to apply a down mix using better and more known matrices like the Dolby Pro Logic II that would make the resulting stereo stream sound way better than the VLC down mix.
Unless you are particularly interested in using VLC for whatever reason, I suggest you to install the k-lite codec pack along with MPC-HC.
The pack will install the LAV Filters that you'll be using to handle audio and video.
MPC-HC is very detailed with different renders and different options.
As to the LAV Filters, you'll be able to set your preferred down mix method and the way audio is handled.
Another good player that does a down mix on the fly with many tweakable options is Potplayer, which uses the OpenCodecs instead.

I personally use these two on Windows and MPV on Linux.

Cheers.

P.s if you are asking why they implemented it that way on VLC instead, I don't know, but if you are willing to, you may commit a change to the source to add a better down mix.

Last edited by FranceBB; 26th October 2018 at 02:53.
FranceBB is offline   Reply With Quote
Old 26th October 2018, 05:25   #3  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Quote:
Originally Posted by Exxess View Post
When you have a look at the VLC source code (modules/audio_filter/channel_mixer/simple.c), it just does the mixing part, but it seems that it doesn't re-normalize afterwards (or I overlooked the code for that).
If you want to normalize the result after downmixing is something a user should decide for herself. This is how you do 6ch -> stereo downmix in AviSynth (no final normalizing):

Quote:
Function Dmix6Stereo(clip a)
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3694, 0.2612)
blr = GetChannel(a, 5, 6)
return MixAudio(lrc, blr, 1.0, 0.3694)
}

By FranceBB:
Quote:
FFmpeg should also be able to apply a down mix using better and more known matrices like the Dolby Pro Logic II that would make the resulting stereo stream sound way better than the VLC down mix.
I dispute this statement. Using the Dolby Pro Logic or Dolby Pro Logic II matrix for downmixing can make the resulting stereo audio sound better on a multichannel home theater setup (by giving the "pseudo" 6-ch generating DSP some phase information), but it does not improve the downmix result if you listen to it on a classic stereo speaker setup. Since I do not intend to invest in a home theater setup I always downmix multichannel sources in "simple stereo" mode which IMO sounds better when you listen to it with only 2 speakers.


Cheers
manolito

Last edited by manolito; 26th October 2018 at 05:28.
manolito is offline   Reply With Quote
Old 26th October 2018, 11:19   #4  |  Link
nevcairiel
Registered Developer
 
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,344
I agree with manolito, those Dolby Pro Logic downmixes are not designed for the best experience listening on Stereo speakers or headphones, they are designed to be able to recover some surround effects from a stereo signal with a Dolb Pro Logic decoder at the other end.
__________________
LAV Filters - open source ffmpeg based media splitter and decoders
nevcairiel is offline   Reply With Quote
Old 26th October 2018, 12:37   #5  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
- There are two way to normalize peaks, and it is needed to avoid clip audio:

1) Make two passes, like AviSynth can do. Like Manolito script and a Normalize() after.
In first pass we know the big peak obtained and in second pass attenuate or gain until the big value without clip (1.0 or any other value requested <1.0).
Without two passes we can do the best normalization, then VLC or ffmpeg can't do this mode and need use the second method.

2) Use normalized coeficients to guarantee than never go over 1.0.
For instance the ffmpeg downmix:

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

(WARNING: surround channels must be SL,SR, not BL,BR)
can produce peak values until 2.414 than are cliped to 1.0 making distortion. The normalized version of this mix is:

-af "pan=stereo|FL = 0.414*FL + 0.293*FC + 0.293*SL|FR = 0.414*FR + 0.293*FC + 0.293*SR"

When use '<' instead '=' ffmpeg change the coeficients to normalized version.

Also there are many ways to define the coeficients and the contribution to the final mix.
In a AC3 5.1 stream there are header fields like:

cmixlev: Center Mix Level, 2 Bits, values: 0.707 (–3.0 dB), 0.595 (–4.5 dB), 0.500 (–6.0 dB)
surmixlev: Surround Mix Level, 2 Bits, values: 0.707 (–3 dB), 0.500 (–6 dB), 0

than a compliant decoder must obey in order to obtain the downmix.
Of course a ffmpeg -af "pan=stereo..." override these values.
There are also dpl and dpl II downmix, for instance:

-af "pan=stereo|FL = 0.3254*FL + 0.2301*FC + 0.2818*SL + 0.1627*BR|FR = 0.3254*FR + 0.2301*FC - 0.1627*BL - 0.2818*SR"

That mix is only recommended to be used by AV with dplII decoder, to be played like stereo is worse than simple stereo (the coeficient of FC is worse).
Also, if want include LFE (not recommended by Dolby) the FC normalized coeficient must be worse.

But using normalized coeficients we can obtain less volume, maybe VLC don't use normalized coeficients with risk of clip.
I'm not sure but in VLC -> Preferences -> Audio -> Normalize volume to -> 2.0 (by default)
Maybe if you put here 1.0 the behaviour is the same than with ffmpeg.
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 29th October 2018, 00:18   #6  |  Link
Richard1485
Guest
 
Posts: n/a
Quote:
Originally Posted by manolito View Post
Since I do not intend to invest in a home theater setup I always downmix multichannel sources in "simple stereo" mode which IMO sounds better when you listen to it with only 2 speakers.
Yes, I strongly with this. It's what I do too. And it can be done on the fly with AC3Filter.
  Reply With Quote
Old 30th October 2018, 18:51   #7  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,988
It's worth noting that the Dolby formats have support for embedding preferred downmix methodologies as metadata. I don't think it's commonly used in practice, but just a note
Blue_MiSfit is offline   Reply With Quote
Reply

Tags
downmix, stereo

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 19:35.


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