View Full Version : Audio downmix via AviSynth
sundance
18th January 2008, 13:09
I have a media file with a 5.1 audio track. I'd like to convert that (along with the video) to a stereo track. Now I found that in the AviSynth wiki:
# Converts avi with "uncompressed 5.1 wav" audio to a stereo signal:
video = AviSource("c:\divx_wav.avi")
audio = WavSource(c:\divx_wav.avi)
stereo = GetChannel(audio, 1, 2)
return AudioDub(video, stereo)
If I understand that snippet correct, it extracts the left and right channels and produces a stereo track. But what if you'd like the center channel being taken into account, like:
new left = 5.1_left + 0.5 * 5.1_center
new right = 5.1_right + 0.5 * 5.1_center
Could this be done with an AviSynth script?
tebasuna51
18th January 2008, 18:11
new left = 5.1_left + 0.5 * 5.1_center
new right = 5.1_right + 0.5 * 5.1_center
Could this be done with an AviSynth script?
- To obtain same audio power you need coeficients like sqr(2)/2:
L' = L + 0.707*C
R' = R + 0.707*C
- To avoid clips (cut peaks) the coefficients must sum 1 (normalized)
L' = 0.5858*L + 0.4142*C
R' = 0.5858*R + 0.4142*C
Can be implemented with AviSynth with:
flr = GetChannel(audio, 1, 2)
fcc = GetChannel(audio, 3, 3)
new_audio = MixAudio(flr, fcc, 0.5858, 0.4142)
A more sophisticated function to obtain a downmix Dolby ProLogic II compatible can be:
function Dmix5Dpl2(clip a) # 5 Channels L,R,C,SL,SR -> dpl II
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3254, 0.2301)
bl = GetChannel(a, 4)
br = GetChannel(a, 5)
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)
}
The normalized coefficients avoid the clips but can decrease the volume, then is recommended use also Normalize() after the downmix:
new_audio = Dmix5Dpl2(audio).Normalize()
sundance
18th January 2008, 19:55
tebasuna51,
thanks a lot for this valuable "input"; I'll try to make it work...
Just to make sure I understood the algorithm:
flr = GetChannel(audio, 1, 2) ; results in a stereo stream with front left&right
fcc = GetChannel(audio, 3, 3) ; results in a 2-channel-stream, both with center
new_audio = MixAudio(flr, fcc, 0.5858, 0.4142)
After MixAudio(), the result has the desired mix with the appropriate coeffs applied. Correct?
tebasuna51
19th January 2008, 04:08
After MixAudio(), the result has the desired mix with the appropriate coeffs applied. Correct?
Yes, is a correct mix with only front channels.
vlada
5th February 2009, 19:05
Hi,
I have a simple question. How would a script to downmix 5.1 to stereo (DPL II) look like? Or should I ignore the subwoofer track? I think I shouldn't.
kemuri-_9
5th February 2009, 20:31
I have a simple question. How would a script to downmix 5.1 to stereo (DPL II) look like? Or should I ignore the subwoofer track? I think I shouldn't.
sample code of how to do downmixing is on the avisynth wiki:
http://avisynth.org/mediawiki/GetChannel
http://avisynth.org/mediawiki/MergeChannels
tebasuna51
6th February 2009, 00:55
Hi,
I have a simple question. How would a script to downmix 5.1 to stereo (DPL II) look like? Or should I ignore the subwoofer track? I think I shouldn't.
In this post (http://forum.doom9.org/showthread.php?p=1243880#post1243880) there are many options to downmix.
Dolby recommend don't use LFE (don't mistake LFE channel with the subwoofer) in DPL mix.
vlada
6th February 2009, 11:48
tebasuna51> Thanks a lot for your scripts. Could you please explain me in a little more detail the confusion between LFE and subwoofer? I thought that if you have a 5.1 speaker setup, then your subwoofer speaker receives the LFE track. Isn't this true?
I did a frequency analysis of center channel and LFE. The center channel has no lowpass filter applied, the LFE has a 8 kHZ highpass filter applied. I thought it would be lower.
So anyway I think I can drop the LFE channel, right?
tebasuna51
7th February 2009, 01:27
All audio equipment have a 'Bass management':
- Low quality equipment send all low frequencies (from all channels not only LFE) to subwoofer because is cheaper have only one amplifier and speaker with low frequencies support.
- High quality equipment permit select if the low frequencies are redirected to subwoofer or to front channels (also the LFE channel).
About using LFE in downmix:
From 214_Mixing with Dolby Pro Logic II Technology.pdf :
"There are other concerns when adding an LFE signal to the mix. If the LFE is simply redistributed within the other channels of the mix, they will usually be subject to some low-frequency bandpass filtering. This filtering causes phase shifts of the LFE signal. When they are acoustically added within a room, these phase shifts are fairly subtle and often go unnoticed. However, when they are electronically added together with the five main channels in the encoder, they may produce less than desirable results at certain frequencies. For this reason, it is recommended that the LFE signal not be used in a Dolby Pro Logic II downmix unless it contains unique information that is not repeated in any of the five main channels."
... it is recommended that the LFE signal not be used in a Dolby Pro Logic II downmix unless it contains unique information that is not repeated in any of the five main channels."
I have noticed, that MeGui automatically filters out the LFE content, when you downmix from discrete 5.1, to 2.0 Dolby Prologic II. So it seems, that it is programmed to follow the suggestion quoted by tebasuna51 above. Otherwise MeGUI makes great PL II downmixes, with clear and distinct channel separation.
Have done some preliminary experiments to circumvent this, with an avisynth script, which distributes LFE into FL and FR, feeding 5.0 into MeGui's PL II input. I get some unwanted noise from the rear channels, but not that bad.
newFL = MixAudio(FL, LFE, x.xx, y.yy)
newFR = MixAudio(FR, LFE, x.xx, y.yy)
Has anyone an idea to what would be proper levels for x.xx and y.yy if the target is to distribute LFE across FL and FR ??
tebasuna51
25th July 2009, 16:20
I have noticed, that MeGui automatically filters out the LFE content, when you downmix from discrete 5.1, to 2.0 Dolby Prologic II. So it seems, that it is programmed to follow the suggestion quoted by tebasuna51 above.
...
Has anyone an idea to what would be proper levels for x.xx and y.yy if the target is to distribute LFE across FL and FR ??
The audio management in MeGUI is similar to BeHappy.
In BeHappy you have the option to include LFE.
If you see some posts before, there are a link with many downmix options:
http://forum.doom9.org/showthread.php?p=1243880#post1243880
b66pak
25th July 2009, 19:16
@tebasuna51
i try to encode a stereo .wav (obtained by downmixing a 5.1 dts signal with DPL2 avisynth function) to .ac3 using aften so it will be recognized by my receiver as DPL2 but the receiver said stereo only!
could you suggest a command line for aften?
_
tebasuna51
26th July 2009, 00:12
could you suggest a command line for aften?
From aften -longhelp
[-dsur #] Dolby Surround mode
When operating in the two channel mode, this code
indicates whether or not the program has been encoded in
Dolby Surround. This information is not used by the
AC-3 decoder, but may be used by other portions of the
audio reproduction equipment.
0 = not indicated (default)
1 = not Dolby surround encoded
2 = Dolby surround encoded
Then the command line must be (default bitrate for 2.0 is 192 Kb/s):
Aften -dsur 2 downmixed.wav dpl_flaged.ac3
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.