View Full Version : Converting 5.1 to stereo?
Katie Boundary
15th May 2020, 07:18
Do any avisynth filters convert 5.1-channel audio to stereo? The closest thing I can find is converttomono.
wonkey_monkey
15th May 2020, 07:52
http://avisynth.nl/index.php/GetChannel
https://forum.doom9.org/showthread.php?p=1735072#post1735072
Now everyone else remember not to reply because KB doesn't actually like getting the answers to their questions.
manolito
15th May 2020, 12:36
As long as I have not been officially declared Incompetent I can still decide for myself if I want to answer to a post or not... :devil:
There are several different methods for this downmix. You can downmix to "simple" stereo, you can convert to DolbyProLogic or to DolbyProLogicII. Then for all of the three methods you can include or ignore the LFE channel. The recommended method is to ignore LFE.
Here is an AVSI which contains the "official" functions by Tebasuna (THE expert on such things).
Downmix 6ch to stereo.avsi:
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)
}
Function Dmix6Dpl(clip a)
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3205, 0.2265)
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2265, 0.2265)
sr = MixAudio(bl, br, -0.2265, -0.2265)
blr = MergeChannels(sl, sr)
return MixAudio(lrc, blr, 1.0, 1.0)
}
Function Dmix6Dpl2(clip a)
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3254, 0.2301)
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2818, 0.1627)
sr = MixAudio(bl, br, -0.1627, -0.2818)
blr = MergeChannels(sl, sr)
return MixAudio(lrc, blr, 1.0, 1.0)
}
Function Dmix6StereoLfe(clip a)
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3)
lfe = GetChannel(a, 4)
lfc = MixAudio(fcc, lfe, 0.2071, 0.2071)
mix = MergeChannels(lfc, lfc)
lrc = MixAudio(flr, mix, 0.2929, 1.0)
blr = GetChannel(a, 5, 6)
return MixAudio(lrc, blr, 1.0, 0.2929)
}
Function Dmix6StereoLfe2(clip a)
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2929, 0.2071)
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.2071)
blr = GetChannel(a, 5, 6)
return MixAudio(lrc, blr, 1.0, 0.2929)
}
Function Dmix6DplLfe(clip a)
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2613, 0.1847)
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1847)
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.1847, 0.1847)
sr = MixAudio(bl, br, -0.1847, -0.1847)
blr = MergeChannels(sl, sr)
return MixAudio(lrc, blr, 1.0, 1.0)
}
Function Dmix6Dpl2Lfe(clip a)
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2646, 0.1870)
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1870)
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2291, 0.1323)
sr = MixAudio(bl, br, -0.1323, -0.2291)
blr = MergeChannels(sl, sr)
return MixAudio(lrc, blr, 1.0, 1.0)
}
Enjoy...
(Converting audio to Float first and normalizing after downmixing is optional)
//EDIT//
Here is a link to the complete downmix functions which contains all possible downmix methods:
https://files.videohelp.com/u/172211/A2D_Downmix.zip
amichaelt
15th May 2020, 15:53
Is there a reason you need to use Avisynth for this over just using eac3to? The latter just seems like a way easier tool for the job. *shrug*
Katie Boundary
15th May 2020, 19:25
Here is an AVSI which contains the "official" functions by Tebasuna (THE expert on such things).
Downmix 6ch to stereo.avsi:
-snip-
Enjoy...
Wow, that all seems suspiciously and needlessly complicated. However, thank you very much for pointing out the getchannel and mergechannel filters. After some experimentation, I've come up with the following bit of script:
W=wavsource("title_t00.track_4.1.wav")
l=GetChannel(w,1,3,5).converttomono()
r=Getchannel(w,2,3,6).converttomono()
a=mergechannels(l,r)
This gives a little bit more weight to the front center channel than is ideal, but I'm not really a sound person to begin with so I can live with that. Will it otherwise do what I want? Or have I misunderstood how the filters work?
Is there a reason you need to use Avisynth for this over just using eac3to? The latter just seems like a way easier tool for the job. *shrug*
I'd like to use the smallest possible number of tools and intermediary files that will still do what I want :)
EDIT: hold up. Is it legal to use the same argument multiple times in Getchhannel and/or mergechannel? Could I do "GetChannel(w,1,1,3,5,5).converttomono()" to create an audio channel that's 40% from the rear left, 40% from the front left, and 20% from the center?
manolito
15th May 2020, 20:00
The simplest Tebasuna script for your needs would be:
W=wavsource("title_t00.track_4.1.wav")
flr = GetChannel(W, 1, 2)
fcc = GetChannel(W, 3, 3)
lrc = MixAudio(flr, fcc, 0.3694, 0.2612)
blr = GetChannel(W, 5, 6)
a = MixAudio(lrc, blr, 1.0, 0.3694)
Give it a try and compare the result to your script.
Good luck...
Katie Boundary
16th May 2020, 00:39
This line:
fcc = GetChannel(W, 3, 3)
Is the one that answers my question: yes, the same argument can be used multiple times in Getchannel in order to give one audio channel more weight when using converttomono.
I'm not sure about the rhyme or reason behind the Tebasuna code. The weights look like the result of a cat stepping on a keyboard's number pad. Regardless, my tests with the script clip I posted earlier have proven more or less successful (TmpegEnc and Virtualdub recognize the result as a valid stereo input, no sounds are missing), so you did help :)
tebasuna51
16th May 2020, 00:43
Katie Boundary script:
l=GetChannel(w,1,3,5).converttomono()=0.33*FL + 0.33*FC + 0.33*SL
r=Getchannel(w,2,3,6).converttomono()=0.33*FR + 0.33*FC + 0.33*SR
yes the center channel is loud than canonical downmix:
l=0.369*FL + 0.261*FC + 0.369*SL
r=0.369*FR + 0.261*FC + 0.369*SR
BTW you can make any downmix at your taste, my prefered is reduce the surround channels increasing the Center, for instance:
l=0.369*FL + 0.369*FC + 0.262*SL
r=0.369*FR + 0.369*FC + 0.262*SR
After the downmix don't forget Normalize at your desired level, for instance:
Normalize(0.9)
tebasuna51
16th May 2020, 00:54
I'm not sure about the rhyme or reason behind the Tebasuna code.
The canonical downmix is:
FL' = FL + 0.707*FC + SL
FR' = FR + 0.707*FC + SR
The 0.707 (square root of 2) is because the acustic power is proportional to V^2 then adding only 0.707 to Front channels you obtain the same acustic power than the original FC channel.
But to avoid clip the mix must be normalized and the coeficients must be reduced to sum 1.0:
1/2.707 = 0.369
0.707/2.707= 0.261
The same than do Converttomono(), apply 0.333 coeficient to 3 channels.
Your script is ok, but don't forget Normalize(), the simple downmix most the times obtain low volume.
johnmeyer
16th May 2020, 01:32
Now everyone else remember not to reply because KB doesn't actually like getting the answers to their questions.
As long as I have not been officially declared Incompetent I can still decide for myself if I want to answer to a post or not... :devil:
Wow, that all seems suspiciously and needlessly complicated. <snip> [and then later ...]I'm not sure about the rhyme or reason behind the Tebasuna code [that manolito posted]. The weights look like the result of a cat stepping on a keyboard's number pad.From my neutral corner, I'd say that wonkey called it dead right, but maybe manolito enjoys the abuse.
I will also add that, from my engineering training and experience, it is quite clear that manolito's characterization of Tebasuna as the expert on such things is very well founded. His posts and the links to his past work show someone who knows exactly what he's talking about.
Katie Boundary
16th May 2020, 01:58
Katie Boundary script:
l=GetChannel(w,1,3,5).converttomono()=0.33*FL + 0.33*FC + 0.33*SL
r=Getchannel(w,2,3,6).converttomono()=0.33*FR + 0.33*FC + 0.33*SR
Actually it's now:
l=GetChannel(w,1,1,3,5,5).converttomono() = 40% FL, 20% FC, 40% SL
r=Getchannel(w,2,2,3,6,6).converttomono() = 40% FR, 20% FC, 40% SR
This yields a slightly quieted center channel and more pronounced stereo effects than your mathematically perfect approach taking exponential stuff into account, but I can live with that.
Normalization isn't critical, since most operating systems, most media players, AND my headphones all come with volume sliders :)
From my neutral corner, I'd say that wonkey called it dead right, but maybe manolito enjoys the abuse.
I wasn't abusing Manolito. I thanked him and acknowledged his help twice. There was even a smiley face. I have it on good authority that bitches love smiley faces.
manolito
16th May 2020, 12:24
I wasn't abusing Manolito.
Katie is absolutely right.
But thinking about it... So far I have never been abused by a female dinosaur. Maybe I would like it... :D
StainlessS
16th May 2020, 13:13
Did not the [bigger] female T-Rex often kill or maim a male suitor after mating [leastwise if you believe dino progs].
That the kind of abuse you are into Mani ?
[Katie takes no prisoners]
Groucho2004
16th May 2020, 13:36
Did not the [bigger] female T-Rex often kill or maim a male suitor after matingAfter mating, the female T-Rex used to gag the male, insert an oversized butt plug and spank him until he said the safe word.
So, just what Manolito likes. :D
kuchikirukia
20th May 2020, 02:22
Do any avisynth filters convert 5.1-channel audio to stereo? The closest thing I can find is converttomono.
Yes, every filter does it in fact. Just not to your standards. You should probably work on the correct way to do it.
Please do so elsewhere.
Katie Boundary
20th May 2020, 05:05
Yes, every filter does it in fact. Just not to your standards.
LOL. When it comes to audio, I don't HAVE standards. My hearing is shit.
StainlessS
20th May 2020, 11:09
I generally use this
Function FAVCStereo(clip Video, clip Audio) {
Dubbed = Video
Chan0 = (HasAudio(Audio)==False) ? AudioDub(Video, BlankClip(Video, audio_rate=48000, stereo=true)) : nop()
Dubbed = (HasAudio(Audio)==False) ? Chan0 : Dubbed
Audio = (HasAudio(Audio)==True) ? ConvertAudioToFloat(Audio) : Audio
Chan1 = (AudioChannels(Audio)==1) ? Audiodub(Video, GetChannel(Audio, 1, 1)) : nop()
Dubbed = (AudioChannels(Audio)==1) ? Chan1 : Dubbed
Chan2 = (AudioChannels(Audio)==2) ? Audiodub(Video, Audio) : nop()
Dubbed = (AudioChannels(Audio)==2) ? Chan2 : Dubbed
FrontLeft = (AudioChannels(Audio)==3) ? MixAudio(GetChannel(Audio, 1), GetChannel(Audio, 2), 0.5, 0.5) : nop()
FrontRight = (AudioChannels(Audio)==3) ? MixAudio(GetChannel(Audio, 3), GetChannel(Audio, 2), 0.5, 0.5) : nop()
Chan3 = (AudioChannels(Audio)==3) ? Audiodub(Video, MergeChannels(FrontLeft, FrontRight)) : nop()
Dubbed = (AudioChannels(Audio)==3) ? Chan3 : Dubbed
TotalLeft = (AudioChannels(Audio)==4) ? MixAudio(GetChannel(Audio, 1), GetChannel(Audio, 3), 0.5, 0.5) : nop()
TotalRight = (AudioChannels(Audio)==4) ? MixAudio(GetChannel(Audio, 2), GetChannel(Audio, 4), 0.5, 0.5) : nop()
Chan4 = (AudioChannels(Audio)==4) ? Audiodub(Video, MergeChannels(TotalLeft, TotalRight)) : nop()
Dubbed = (AudioChannels(Audio)==4) ? Chan4 : Dubbed
FrontLeft = (AudioChannels(Audio)==5) ? MixAudio(GetChannel(Audio, 1), GetChannel(Audio, 2), 0.3694, 0.2612) : nop()
FrontRight = (AudioChannels(Audio)==5) ? MixAudio(GetChannel(Audio, 3), GetChannel(Audio, 2), 0.3694, 0.2612) : nop()
TotalLeft = (AudioChannels(Audio)==5) ? MixAudio(FrontLeft, GetChannel(Audio, 4), 1, 0.3694) : nop()
TotalRight = (AudioChannels(Audio)==5) ? MixAudio(FrontRight, GetChannel(Audio, 5), 1, 0.3694) : nop()
Chan5 = (AudioChannels(Audio)==5) ? Audiodub(Video, MergeChannels(TotalLeft, TotalRight)) : nop()
Dubbed = (AudioChannels(Audio)==5) ? Chan5 : Dubbed
BackLeft = (AudioChannels(Audio)>=6) ? MixAudio(GetChannel(Audio, 4), GetChannel(Audio, 6), 0.2698, 0.2698) : nop()
BackRight = (AudioChannels(Audio)>=6) ? MixAudio(GetChannel(Audio, 5), GetChannel(Audio, 6), 0.2698, 0.2698) : nop()
FrontLeft = (AudioChannels(Audio)>=6) ? MixAudio(GetChannel(Audio, 1), GetChannel(Audio, 2), 0.2698, 0.1906) : nop()
FrontRight = (AudioChannels(Audio)>=6) ? MixAudio(GetChannel(Audio, 3), GetChannel(Audio, 2), 0.2698, 0.1906) : nop()
TotalLeft = (AudioChannels(Audio)>=6) ? MixAudio(FrontLeft, BackLeft, 1, 1) : nop()
TotalRight = (AudioChannels(Audio)>=6) ? MixAudio(FrontRight, BackRight, 1, 1) : nop()
Chan6 = (AudioChannels(Audio)>=6) ? Audiodub(Video, MergeChannels(TotalLeft, TotalRight)) : nop()
Dubbed = (AudioChannels(Audio)>=6) ? Chan6 : Dubbed
# Dubbed = (HasAudio(Audio)==True) ? Normalize(Dubbed) : Dubbed
# Dubbed = (HasAudio(Audio)==True) ? SSRC(Dubbed, 48000) : Dubbed
Dubbed = (HasAudio(Audio)==True) ? ConvertAudioTo16bit(Dubbed) : Dubbed
return(Dubbed)
}
Function FAVCStereoDSS(clip Video, clip Audio) {
Dubbed = Video
Chan0 = (HasAudio(Audio)==False) ? AudioDub(Video, BlankClip(Video, audio_rate=48000, stereo=true)) : nop()
Dubbed = (HasAudio(Audio)==False) ? Chan0 : Dubbed
Audio = (HasAudio(Audio)==True) ? ConvertAudioToFloat(Audio) : Audio
Chan1 = (AudioChannels(Audio)==1) ? Audiodub(Video, GetChannel(Audio, 1, 1)) : nop()
Dubbed = (AudioChannels(Audio)==1) ? Chan1 : Dubbed
Chan2 = (AudioChannels(Audio)==2) ? Audiodub(Video, Audio) : nop()
Dubbed = (AudioChannels(Audio)==2) ? Chan2 : Dubbed
FrontLeft = (AudioChannels(Audio)==3) ? MixAudio(GetChannel(Audio, 1), GetChannel(Audio, 3), 0.5, 0.5) : nop()
FrontRight = (AudioChannels(Audio)==3) ? MixAudio(GetChannel(Audio, 2), GetChannel(Audio, 3), 0.5, 0.5) : nop()
Chan3 = (AudioChannels(Audio)==3) ? Audiodub(Video, MergeChannels(FrontLeft, FrontRight)) : nop()
Dubbed = (AudioChannels(Audio)==3) ? Chan3 : Dubbed
TotalLeft = (AudioChannels(Audio)==4) ? MixAudio(GetChannel(Audio, 1), GetChannel(Audio, 3), 0.5, 0.5) : nop()
TotalRight = (AudioChannels(Audio)==4) ? MixAudio(GetChannel(Audio, 2), GetChannel(Audio, 4), 0.5, 0.5) : nop()
Chan4 = (AudioChannels(Audio)==4) ? Audiodub(Video, MergeChannels(TotalLeft, TotalRight)) : nop()
Dubbed = (AudioChannels(Audio)==4) ? Chan4 : Dubbed
FrontLeft = (AudioChannels(Audio)==5) ? MixAudio(GetChannel(Audio, 1), GetChannel(Audio, 3), 0.3694, 0.2612) : nop()
FrontRight = (AudioChannels(Audio)==5) ? MixAudio(GetChannel(Audio, 2), GetChannel(Audio, 3), 0.3694, 0.2612) : nop()
TotalLeft = (AudioChannels(Audio)==5) ? MixAudio(FrontLeft, GetChannel(Audio, 4), 1, 0.3694) : nop()
TotalRight = (AudioChannels(Audio)==5) ? MixAudio(FrontRight, GetChannel(Audio, 5), 1, 0.3694) : nop()
Chan5 = (AudioChannels(Audio)==5) ? Audiodub(Video, MergeChannels(TotalLeft, TotalRight)) : nop()
Dubbed = (AudioChannels(Audio)==5) ? Chan5 : Dubbed
BackLeft = (AudioChannels(Audio)>=6) ? MixAudio(GetChannel(Audio, 5), GetChannel(Audio, 4), 0.2698, 0.2698) : nop()
BackRight = (AudioChannels(Audio)>=6) ? MixAudio(GetChannel(Audio, 6), GetChannel(Audio, 4), 0.2698, 0.2698) : nop()
FrontLeft = (AudioChannels(Audio)>=6) ? MixAudio(GetChannel(Audio, 1), GetChannel(Audio, 3), 0.2698, 0.1906) : nop()
FrontRight = (AudioChannels(Audio)>=6) ? MixAudio(GetChannel(Audio, 2), GetChannel(Audio, 3), 0.2698, 0.1906) : nop()
TotalLeft = (AudioChannels(Audio)>=6) ? MixAudio(FrontLeft, BackLeft, 1, 1) : nop()
TotalRight = (AudioChannels(Audio)>=6) ? MixAudio(FrontRight, BackRight, 1, 1) : nop()
Chan6 = (AudioChannels(Audio)>=6) ? Audiodub(Video, MergeChannels(TotalLeft, TotalRight)) : nop()
Dubbed = (AudioChannels(Audio)>=6) ? Chan6 : Dubbed
# Dubbed = (HasAudio(Audio)==True) ? Normalize(Dubbed) : Dubbed
# Dubbed = (HasAudio(Audio)==True) ? SSRC(Dubbed, 48000) : Dubbed
Dubbed = (HasAudio(Audio)==True) ? ConvertAudioTo16bit(Dubbed) : Dubbed
return(Dubbed)
}
From this post:- https://forum.doom9.org/showthread.php?p=878303#post878303
The poster did some kind of app, of which this was a part, maybe search out his other posts, maybe was updated.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.