View Full Version : 6 channels to Stereo
doomleox999
3rd April 2018, 17:50
Hi everyone, first of all english is not my first language, sorry for any mistakes I make.
When I encode a 6ch audio to stereo with MeGUI I use this setting:
https://i.imgur.com/Weferft.jpg
The final result is not as loud as the original audio, now, if I extract the audio track from the file and encode it with ffmpeg (-i sixchannels.aac -ac 2 -ab 128k stereo.aac something like that) the result is amazing! It's almost indistinguible from the original.
I'm no expert, so I'm not sure if I'm right, but I feel that ffmpeg mixes the 6 channels and MeGUI only takes 2 out of the 6. Again, I'm not sure if that's right but that's the impression I get.
Am I right? Am I wrong? Is it possible to use ffmpeg WITH MeGUI (to save time) or tell MeGUI to "mix the 6 channels into stereo"?
Thanks in advance!
tebasuna51
3rd April 2018, 21:50
The final result is not as loud as the original audio
Of course with 2 speakers we can't obtain the same volume than with 6 speakers.
if I extract the audio track from the file and encode it with ffmpeg (-i sixchannels.aac -ac 2 -ab 128k stereo.aac something like that) the result is amazing! It's almost indistinguible from the original.
Then use ffmpeg instead MeGUI. No problem.
but I feel that ffmpeg mixes the 6 channels and MeGUI only takes 2 out of the 6. Again, I'm not sure if that's right but that's the impression I get.
Nope, MeGUI (AviSynth) mix the 6 channels an normalize to obtain the max volume without distort.
Is it possible to use ffmpeg WITH MeGUI (to save time)
To save time use ffmpeg out of MeGUI, you don't need AviSynth for your conversion.
hello_hello
4th April 2018, 04:00
If you check the log file you'll find the script MeGUI uses for downmixing the audio. It reduces the volume to prevent clipping when the channels are combined, followed by Normalize() to increase the peaks to maximum after downmixing (assuming the Normaize option is checked).
Maybe ffmpeg doesn't prevent clipping by default, and likewise when you playback 5.1ch audio being downmixed to stereo, the volume isn't being reduced to prevent clipping either, so they sound the same.
doomleox999
4th April 2018, 04:49
If you check the log file you'll find the script MeGUI uses for downmixing the audio.
---[Information] Audio
--[Information] [04/04/18 00:36:34] Trying to open the file with LWLibavAudioSource()
--[Information] [04/04/18 00:38:03] Successfully opened the file with LWLibavAudioSource()
-[NoImage] ClearAutoloadDirs()
-[NoImage] AddAutoloadDir("C:\Users\USER\MeGUI\tools\avs\plugins")
-[NoImage] LoadPlugin("C:\Users\USER\MeGUI\tools\lsmash\LSMASHSource.dll")
-[NoImage] LWLibavAudioSource("C:\Users\USER\Desktop\MeGUI Output\AUDIO.aac")
-[NoImage] # detected channels: 6
-[NoImage] # detected channel positions: 3/2/0.1
-[NoImage] LoadPlugin("C:\Users\USER\MeGUI\tools\avisynth_plugin\AudioLimiter.dll")
-[NoImage] c6_stereo(ConvertAudioToFloat(last))
-[NoImage] Normalize()
-[NoImage] return last
-[NoImage] # 5.1 Channels L,R,C,LFE,SL,SR -> stereo + LFE
-[NoImage] function c6_stereo(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] lf = GetChannel(a, 4)
-[NoImage] sl = GetChannel(a, 5)
-[NoImage] sr = GetChannel(a, 6)
-[NoImage] fl_sl = MixAudio(fl, sl, 0.2929, 0.2929)
-[NoImage] fr_sr = MixAudio(fr, sr, 0.2929, 0.2929)
-[NoImage] fc_lf = MixAudio(fc, lf, 0.2071, 0.2071)
-[NoImage] l = MixAudio(fl_sl, fc_lf, 1.0, 1.0)
-[NoImage] r = MixAudio(fr_sr, fc_lf, 1.0, 1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5 Channels L,R,C,SL,SR or L,R,LFE,SL,SR-> Stereo
-[NoImage] function c5_stereo(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] sl = GetChannel(a, 4)
-[NoImage] sr = GetChannel(a, 5)
-[NoImage] fl_sl = MixAudio(fl, sl, 0.3694, 0.3694)
-[NoImage] fr_sr = MixAudio(fr, sr, 0.3694, 0.3694)
-[NoImage] l = MixAudio(fl_sl, fc, 1.0, 0.2612)
-[NoImage] r = MixAudio(fr_sr, fc, 1.0, 0.2612)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5 Channels L,R,C,LFE,S -> Stereo
-[NoImage] function c52_stereo(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] lf = GetChannel(a, 4)
-[NoImage] bc = GetChannel(a, 5)
-[NoImage] fl_bc = MixAudio(fl, bc, 0.3205, 0.2265)
-[NoImage] fr_bc = MixAudio(fr, bc, 0.3205, 0.2265)
-[NoImage] fc_lf = MixAudio(fc, lf, 0.2265, 0.2265)
-[NoImage] l = MixAudio(fl_bc, fc_lf, 1.0, 1.0)
-[NoImage] r = MixAudio(fr_bc, fc_lf, 1.0, 1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 4 Channels Quadro L,R,SL,SR -> Stereo
-[NoImage] function c4_stereo(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] sl = GetChannel(a, 3)
-[NoImage] sr = GetChannel(a, 4)
-[NoImage] l = MixAudio(fl, sl, 0.5, 0.5)
-[NoImage] r = MixAudio(fr, sr, 0.5, 0.5)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 4 Channels L,R,C,LFE or L,R,S,LFE or L,R,C,S -> Stereo
-[NoImage] function c42_stereo(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] lf = GetChannel(a, 4)
-[NoImage] fc_lf = MixAudio(fc, lf, 0.2929, 0.2929)
-[NoImage] l = MixAudio(fl, fc_lf, 0.4142, 1.0)
-[NoImage] r = MixAudio(fr, fc_lf, 0.4142, 1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 3 Channels L,R,C or L,R,S or L,R,LFE -> Stereo
-[NoImage] function c3_stereo(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] l = MixAudio(fl, fc, 0.5858, 0.4142)
-[NoImage] r = MixAudio(fr, fc, 0.5858, 0.4142)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5.1 Channels L,R,C,LFE,SL,SR -> Dolby ProLogic
-[NoImage] function c6_dpl(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] sl = GetChannel(a, 5)
-[NoImage] sr = GetChannel(a, 6)
-[NoImage] bc = MixAudio(sl, sr, 0.2265, 0.2265)
-[NoImage] fl_fc = MixAudio(fl, fc, 0.3205, 0.2265)
-[NoImage] fr_fc = MixAudio(fr, fc, 0.3205, 0.2265)
-[NoImage] l = MixAudio(fl_fc, bc, 1.0, 1.0)
-[NoImage] r = MixAudio(fr_fc, bc, 1.0, -1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5 Channels L,R,C,SL,SR -> Dolby ProLogic
-[NoImage] function c5_dpl(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] sl = GetChannel(a, 4)
-[NoImage] sr = GetChannel(a, 5)
-[NoImage] bc = MixAudio(sl, sr, 0.2265, 0.2265)
-[NoImage] fl_fc = MixAudio(fl, fc, 0.3205, 0.2265)
-[NoImage] fr_fc = MixAudio(fr, fc, 0.3205, 0.2265)
-[NoImage] l = MixAudio(fl_fc, bc, 1.0, 1.0)
-[NoImage] r = MixAudio(fr_fc, bc, 1.0, -1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5 Channels L,R,LFE,SL,SR -> Dolby ProLogic
-[NoImage] function c52_dpl(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] sl = GetChannel(a, 4)
-[NoImage] sr = GetChannel(a, 5)
-[NoImage] bc = MixAudio(sl, sr, 0.2929, 0.2929)
-[NoImage] l = MixAudio(fl, bc, 0.4142, 1.0)
-[NoImage] r = MixAudio(fr, bc, 0.4142, -1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5 Channels L,R,C,LFE,S -> Dolby ProLogic
-[NoImage] function c53_dpl(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] bc = GetChannel(a, 5)
-[NoImage] fl_fc = MixAudio(fl, fc, 0.4142, 0.2929)
-[NoImage] fr_fc = MixAudio(fr, fc, 0.4142, 0.2929)
-[NoImage] l = MixAudio(fl_fc, bc, 1.0, 0.2929)
-[NoImage] r = MixAudio(fr_fc, bc, 1.0, -0.2929)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 4 Channels Quadro L,R,SL,SR -> Dolby ProLogic
-[NoImage] function c4_dpl(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] sl = GetChannel(a, 3)
-[NoImage] sr = GetChannel(a, 4)
-[NoImage] bc = MixAudio(sl, sr, 0.2929, 0.2929)
-[NoImage] l = MixAudio(fl, bc, 0.4142, 1.0)
-[NoImage] r = MixAudio(fr, bc, 0.4142, -1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 4 Channels L,R,LFE,S -> Dolby ProLogic
-[NoImage] function c42_dpl(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] bc = GetChannel(a, 4)
-[NoImage] l = MixAudio(fl, bc, 0.5858, 0.4142)
-[NoImage] r = MixAudio(fr, bc, 0.5858, -0.4142)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 4 Channels L,R,C,S -> Dolby ProLogic
-[NoImage] function c43_dpl(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] bc = GetChannel(a, 4)
-[NoImage] fl_fc = MixAudio(fl, fc, 0.4142, 0.2929)
-[NoImage] fr_fc = MixAudio(fr, fc, 0.4142, 0.2929)
-[NoImage] l = MixAudio(fl_fc, bc, 1.0, 0.2929)
-[NoImage] r = MixAudio(fr_fc, bc, 1.0, -0.2929)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 3 Channels L,R,S -> Dolby ProLogic
-[NoImage] function c3_dpl(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] bc = GetChannel(a, 3)
-[NoImage] l = MixAudio(fl, bc, 0.5858, 0.4142)
-[NoImage] r = MixAudio(fr, bc, 0.5858, -0.4142)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5.1 Channels L,R,C,LFE,SL,SR -> Dolby ProLogic II
-[NoImage] function c6_dpl2(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] sl = GetChannel(a, 5)
-[NoImage] sr = GetChannel(a, 6)
-[NoImage] ssl = MixAudio(sl, sr, 0.2818, 0.1627)
-[NoImage] ssr = MixAudio(sl, sr, -0.1627, -0.2818)
-[NoImage] fl_fc = MixAudio(fl, fc, 0.3254, 0.2301)
-[NoImage] fr_fc = MixAudio(fr, fc, 0.3254, 0.2301)
-[NoImage] l = MixAudio(fl_fc, ssl, 1.0, 1.0)
-[NoImage] r = MixAudio(fr_fc, ssr, 1.0, 1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5 Channels L,R,C,SL,SR -> Dolby ProLogic II
-[NoImage] function c5_dpl2(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] sl = GetChannel(a, 4)
-[NoImage] sr = GetChannel(a, 5)
-[NoImage] ssl = MixAudio(sl, sr, 0.2818, 0.1627)
-[NoImage] ssr = MixAudio(sl, sr, -0.1627, -0.2818)
-[NoImage] fl_fc = MixAudio(fl, fc, 0.3254, 0.2301)
-[NoImage] fr_fc = MixAudio(fr, fc, 0.3254, 0.2301)
-[NoImage] l = MixAudio(fl_fc, ssl, 1.0, 1.0)
-[NoImage] r = MixAudio(fr_fc, ssr, 1.0, 1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 5 Channels L,R,LFE,SL,SR -> Dolby ProLogic II
-[NoImage] function c52_dpl2(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] sl = GetChannel(a, 4)
-[NoImage] sr = GetChannel(a, 5)
-[NoImage] ssl = MixAudio(sl, sr, 0.3714, 0.2144)
-[NoImage] ssr = MixAudio(sl, sr, -0.2144, -0.3714)
-[NoImage] l = MixAudio(fl, ssl, 0.4142, 1.0)
-[NoImage] r = MixAudio(fr, ssr, 0.4142, 1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
-[NoImage] # 4 Channels Quadro L,R,SL,SR -> Dolby ProLogic II
-[NoImage] function c4_dpl2(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] sl = GetChannel(a, 3)
-[NoImage] sr = GetChannel(a, 4)
-[NoImage] ssl = MixAudio(sl, sr, 0.3714, 0.2144)
-[NoImage] ssr = MixAudio(sl, sr, -0.2144, -0.3714)
-[NoImage] l = MixAudio(fl, ssl, 0.4142, 1.0)
-[NoImage] r = MixAudio(fr, ssr, 0.4142, 1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
--[Information] [04/04/18 00:38:09] AviSynth script
--[Information] [04/04/18 00:38:09] Command line used: -ignorelength -br 128000 -if - -of "{0}"
--[Information] [04/04/18 00:38:09] AviSynth script environment opened
--[Information] [04/04/18 00:38:15] Script loaded
--[Information] [04/04/18 00:38:15] Output Decoder
---[Information] [04/04/18 00:38:15] Channels: 2
---[Information] [04/04/18 00:38:15] Bits per sample: 32
---[Information] [04/04/18 00:38:15] Sample rate: 48000
--[Information] [04/04/18 00:38:15] Job command line: C:\Users\USER\MeGUI\tools\eac3to\neroAacEnc.exe -ignorelength -br 128000 -if - -of "C:\Users\USER\Desktop\MeGUI Output\AUDIO.m4a"
--[Information] [04/04/18 00:38:16] Process started
--[Information] [04/04/18 00:38:16] Standard output stream
--[Information] [04/04/18 00:38:16] Standard error stream
So this is the log, do you see something weird?
Is it possible to copy a log of ffmpeg?
hello_hello
4th April 2018, 05:42
So this is the log, do you see something weird?
Nothing that I can see.
-[NoImage] # detected channels: 6
-[NoImage] # detected channel positions: 3/2/0.1
-[NoImage] LoadPlugin("C:\Users\USER\MeGUI\tools\avisynth_plugin\AudioLimiter.dll")
-[NoImage] c6_stereo(ConvertAudioToFloat(last))
-[NoImage] Normalize()
-[NoImage] return last
-[NoImage] # 5.1 Channels L,R,C,LFE,SL,SR -> stereo + LFE
-[NoImage] function c6_stereo(clip a)
-[NoImage] {
-[NoImage] fl = GetChannel(a, 1)
-[NoImage] fr = GetChannel(a, 2)
-[NoImage] fc = GetChannel(a, 3)
-[NoImage] lf = GetChannel(a, 4)
-[NoImage] sl = GetChannel(a, 5)
-[NoImage] sr = GetChannel(a, 6)
-[NoImage] fl_sl = MixAudio(fl, sl, 0.2929, 0.2929)
-[NoImage] fr_sr = MixAudio(fr, sr, 0.2929, 0.2929)
-[NoImage] fc_lf = MixAudio(fc, lf, 0.2071, 0.2071)
-[NoImage] l = MixAudio(fl_sl, fc_lf, 1.0, 1.0)
-[NoImage] r = MixAudio(fr_sr, fc_lf, 1.0, 1.0)
-[NoImage] return MergeChannels(l, r)
-[NoImage] }
The first quoted section shows MeGUI is downmixing with the c6_stereo() function, followed by Normalize(), and the second quoted section shows the c6_stereo() function, which seems normal.
0.2929 means the front left and surround left channels are being downmixed with a (roughly) 10.5dB volume reduction for each. The same applies to FR and SR.
0.2071 means the centre and LFE channels are being mixed together with a (roughly) 13.5dB reduction, then they're added to left and right. The upshot is, the centre and LFE channels have their volumes reduced by 3dB relative to the other channels, which is normal.
That's a fair volume reduction, but Normalize() will increase it again until the peaks are at maximum. Sometimes they're very close to maximum anyway (hence reducing the volume so much to prevent clipping when downmixing) and Normalize() will therefore not increase the volume much.
You could try importing the downmixed audio into Auidacity to see if it can be amplified without clipping, but you shouldn't be able to.
You can also try downmixing with one of the Pro Logic stereo options. They should sound the same as normal stereo but they don't include the LFE channel, which means the rest of the channels are mixed together at a slightly higher volume, and you might find the peaks are coming from a loud LFE channel, so Normalize() will have more effect without it. I never include the LFE channel when downmixing, but unfortunately there's no option to not include it when downmixing to normal stereo with MeGUI.
Is it possible to copy a log of ffmpeg?
Add -report to the beginning of the command line and ffmpeg should save a log file.
I think it's likely ffmpeg isn't reducing the volume to prevent possible clipping (or maybe it uses Pro Logic downmixing by default?) but I've never used it for downmixing so I don't know how much the log file will tell you about it.
tebasuna51
4th April 2018, 09:01
The ffmpeg log don't say the matrix used to downmix. In my test I found than use:
FL' = FL + 0.7*FC + 0.7*SL
FR' = FR + 0.7*FC + 0.7*SR
- A simple stereo downmix is used.
- The LFE is ignored (recommended).
- Don't prevent clip. Volume values until 2.4 can be obtained and all values over 1.0 are clipped.
The matrix used in MeGUI function c6_stereo is:
FL' = 0.2929*FL + 0.2071*FC + 0.2071*LFE + 0.2929*SL
FR' = 0.2929*FR + 0.2071*FC + 0.2071*LFE + 0.2929*SR
Is a matrix with normalized coeficients than can output a max volume value of 1.0 (without clip)
To avoid low volume values after mix is Normalized to obtain max volume without clip.
----------------------------------------------
You can use BeHappy to downmix with more options to prevent the know problem of low volume dialogs.
For instance simple Stereo without LFE:
FL' = 0.3694*FL + 0.2612*FC + 0.3694*SL
FR' = 0.3694*FR + 0.2612*FC + 0.3694*SR
Or 'Night Mode' forcing Center channel:
FL' = 0.1875*FL + 0.625*FC + 0.1875*SL
FR' = 0.1875*FR + 0.625*FC + 0.1875*SR
Or 'Simple (F+C)':
FL' = FL + 0.7071*FC
FR' = FR + 0.7071*FC
Even you can make your script with the desired mix.
mkver
4th April 2018, 18:11
With -loglevel debug or higher ffmpeg tells you the matrix used:
[Parsed_aresample_0 @ 0000000000191080] [SWR @ 00000000001a1000] Using fltp internally between filters
[Parsed_aresample_0 @ 0000000000191080] [SWR @ 00000000001a1000] Matrix coefficients:
[Parsed_aresample_0 @ 0000000000191080] [SWR @ 00000000001a1000] FL: FL:0.414214 FR:0.000000 FC:0.292893 LFE:0.000000 SL:0.292893 SR:0.000000
[Parsed_aresample_0 @ 0000000000191080] [SWR @ 00000000001a1000] FR: FL:0.000000 FR:0.414214 FC:0.292893 LFE:0.000000 SL:0.000000 SR:0.292893
[Parsed_aresample_0 @ 0000000000191080] ch:6 chl:5.1(side) fmt:fltp r:48000Hz -> ch:2 chl:stereo fmt:s16 r:48000Hz
tebasuna51
4th April 2018, 21:09
You are right, using -loglevel debug the matrix is showed, but the mine confirm my first post with clip problems:
[auto_resampler_0 @ 0000000000440a40] [SWR @ 0000000002b21140] Using fltp internally between filters
[auto_resampler_0 @ 0000000000440a40] [SWR @ 0000000002b21140] Matrix coefficients:
[auto_resampler_0 @ 0000000000440a40] [SWR @ 0000000002b21140] FL: FL:1.000000 FR:0.000000 FC:0.707107 LFE:0.000000 BL:0.707107 BR:0.000000
[auto_resampler_0 @ 0000000000440a40] [SWR @ 0000000002b21140] FR: FL:0.000000 FR:1.000000 FC:0.707107 LFE:0.000000 BL:0.000000 BR:0.707107
hello_hello
5th April 2018, 13:00
Is the difference in log files the difference between using -ac 2 and the audio resampler function (https://ffmpeg.org/ffmpeg-resampler.html), whatever the command line for using it might be? It appears the audio resampler has some sort of clipping prevention (rematrix_maxval) although by the description I assume it performs some sort of peak limiting rather than peak normalising.
mkver
5th April 2018, 13:20
1. If I use -ac2 the only difference I get is that it now reports "auto_resampler", not the explicitly called "Parsed_aresample":
[auto_resampler_0 @ 0000000000169a00] [SWR @ 0000000000169c40] Using fltp internally between filters
[auto_resampler_0 @ 0000000000169a00] [SWR @ 0000000000169c40] Matrix coefficients:
[auto_resampler_0 @ 0000000000169a00] [SWR @ 0000000000169c40] FL: FL:0.414214 FR:0.000000 FC:0.292893 LFE:0.000000 SL:0.292893 SR:0.000000
[auto_resampler_0 @ 0000000000169a00] [SWR @ 0000000000169c40] FR: FL:0.000000 FR:0.414214 FC:0.292893 LFE:0.000000 SL:0.000000 SR:0.292893
[auto_resampler_0 @ 0000000000169a00] ch:6 chl:5.1(side) fmt:fltp r:48000Hz -> ch:2 chl:stereo fmt:s16 r:48000Hz
2. I use an input file that ffmpeg detects as 5.1(side), whereas your file has back channels according to ffmpeg. I don't think that this is the reason behind the difference, but it should be noted. My ffmpeg has been built less than two weeks ago, when has yours?
3. My first test was with using aresample like this: -filter:a aresample=ocl=stereo
tebasuna51
5th April 2018, 15:49
EDIT: I used only the parameter -ac 2 to let ffmpeg select the default downmix...
We can also instruct ffmpeg with the desired downmix using a filter, for instance:
-af "pan=stereo|FL < FL + .7FC + .3BL + .3SL + 0.2LFE|FR < FR + .7FC + .3BR + .3SR + 0.2LFE"
But the problem is always the same, with normalized coeficients => low volume, with big coeficients => more volume but clip risk.
hello_hello
5th April 2018, 18:33
1. If I use -ac2 the only difference I get is that it now reports "auto_resampler", not the explicitly called "Parsed_aresample"
Could the type of audio being downmixed make a difference? What sort of audio were you using as the source?
AC3 has rules about how 5.1ch is supposed to be downmixed to stereo, and if ffmpeg is following those rules when decoding and downmixing, it'd probably apply a volume reduction. I think it's around 7.5dB over-all, which is roughly what it seems to be doing in your case.
I wonder if ffmpeg might downmix different sources differently? I might play around with it tomorrow if I get a chance. I've not downmixed with ffmpeg before.
mkver
5th April 2018, 18:59
My source was a 5.1 ac3 file (which ffmeg treats as 5.1(side) -- ac3 only has one 5.1 channel layout); I just decoded said file to a 5.1(side) wav file to get rid of any special information for downmixing. And if I downmix said wav file, I get exactly the same coefficients as before. If I decode the ac3 and resample to 5.1 (with back channels), the side channels are simply copied to the back channels (and the other channels stay the same). If I downmix said file to stereo, I get the same coefficients as in the 5.1(side) case (just with BL/BR instead of SL/SR). So I can only think of two more possibilities: tebasuna51 uses a different ffmpeg version or he uses a file with embedded downmix coefficients that are honored by ffmpeg.
doomleox999
5th April 2018, 22:58
Wow you guys know a lot about this, I can't understand everything you are talking about (specially "clipping") but I think that MeGUI DOES something different than ffmpeg and that's the reason why they deliver different results. What is not clear for me is if you can instruct MeGUI to (forgive my ignorance) downmix just like ffmpeg does, do I have to add some lines to the script?
tebasuna51
6th April 2018, 11:22
AC3 has rules about how 5.1ch is supposed to be downmixed to stereo, and if ffmpeg is following those rules when decoding and downmixing...
You are right, in the header of AC3 there are fields:
Center mix level
0 = -3.0 dB (default in Aften encode, recommended)
1 = -4.5 dB (default in ffmpeg encode)
2 = -6.0 dB
Surround mix level
0 = -3 dB (default in Aften encode)
1 = -6 dB (default in ffmpeg encode, recommended)
2 = 0
than can be used by ffmpeg, but the source of doomleox999 is a sixchannels.aac, and ADTS aac headers don't have that fields.
I used wav input files to let free ffmpeg downmix.
BTW the question is what downmix matrix use, we can force to ffmpeg use any custom matrix (-af "pan=stereo...") and we can use any downmix script with AviSynth.
When try to play with only 2 speakers we can't obtain the same volume than using 6 speakers, we need choice between less volume (normalized coeficients) or distort high volumes (signal clip).
What is clip? (short explain)
Audio samples can be stored in float formats without limits of volume.
But always must be converted to int samples (at least at end of digital-analog conversion).
And float values greater than 1.0 are truncated to 1.0 and asigned to max integer allowed.
Values greater than 1.0 are lossed, in a audio editor show like a clip (red values in image):
tebasuna51
6th April 2018, 12:15
...if you can instruct MeGUI to downmix just like ffmpeg does...?
Yes, but what ffmpeg do?
Y tried with a sixchannels.aac and now uses:
[auto_resampler_0 @ 0000000002bf5140] [SWR @ 0000000002bf5240] Matrix coefficients:
[auto_resampler_0 @ 0000000002bf5140] [SWR @ 0000000002bf5240] FL: FL:0.414214 FR:0.000000 FC:0.292893 LFE:0.000000 BL:0.292893 BR:0.000000
[auto_resampler_0 @ 0000000002bf5140] [SWR @ 0000000002bf5240] FR: FL:0.000000 FR:0.414214 FC:0.292893 LFE:0.000000 BL:0.000000 BR:0.292893
or:
FL' = 0.414214*FL + 0.292893*FC + 0.292893*SL
FR' = 0.414214*FR + 0.292893*FC + 0.292893*SR
Is a normalized mix without clip, the difference with MeGUI is don't use the LFE channel (like is recommended) but is not a big diference in volume:
Front coeficient 0.4 versus 0.3
Center coeficient 0.3 versus 0.2
And MeGUI do a last Normalize to obtain max volume without clip, ffmpeg don't normalize at end.
You can use the same mix and Normalize at end with this script:
ClearAutoloadDirs()
AddAutoloadDir("C:\Users\USER\MeGUI\tools\avs\plugins")
LoadPlugin("C:\Users\USER\MeGUI\tools\lsmash\LSMASHSource.dll")
a=LWLibavAudioSource("C:\Users\USER\Desktop\MeGUI Output\AUDIO.aac")
fl = GetChannel(a, 1)
fr = GetChannel(a, 2)
fc = GetChannel(a, 3)
# lf = GetChannel(a, 4)
sl = GetChannel(a, 5)
sr = GetChannel(a, 6)
fl_sl = MixAudio(fl, sl, 0.414214, 0.292893)
fr_sr = MixAudio(fr, sr, 0.414214, 0.292893)
l = MixAudio(fl_sl, fc, 1.0, 0.292893)
r = MixAudio(fr_sr, fc, 1.0, 0.292893)
MergeChannels(l, r)
Normalize()
return last
doomleox999
7th April 2018, 06:51
So I just load that script in "Audio Input" in MeGUI? Is that how it works?
By the way, I was testing 6ch to stereo again with ffmpeg and the same file and something new happened at the end of the encode. To be honest I'm not sure if it happened everytime before, I'm talking about those red lines at the bottom:
https://i.imgur.com/VXo9dzs.png
tebasuna51
7th April 2018, 08:31
So I just load that script in "Audio Input" in MeGUI? Is that how it works?
Yes, put the megui log to confirm.
By the way, I was testing 6ch to stereo again with ffmpeg and the same file and something new happened at the end of the encode. To be honest I'm not sure if it happened everytime before, I'm talking about those red lines at the bottom:
ffmpeg show that message when Noise scalefactors are greater than 30.
Maybe it is a encoder bug or a file corruption, it don't seems critical.
doomleox999
9th April 2018, 11:54
So the noise scalefactors thing from ffmpeg is not important? Even if they are red? (I sound childish haha but if the program use red I'd guess is for a reason)
I get the same result with the custom script, just to be sure, this is where I have to load it right?
https://i.imgur.com/1Ju0i6i.jpg
tebasuna51
9th April 2018, 16:02
So the noise scalefactors thing from ffmpeg is not important? Even if they are red?
I say not critical because is a problem in the source file than can't be corrected. If sound bad at some point we can do nothing, maybe find other source file.
There are other message (yelow) to suspect over the encoder than make this aac file.
I get the same result with the custom script, just to be sure, this is where I have to load it right?
Yes.
BTW the in the Config Encoder Settings you can't use a preset for multichannel if you downmix to stereo.
For a stereo with a bitrate near 128 Kb/s (absolutely not recomended for multichannel) you can use a VBR with Q = 0.4
Also if downmix and Normalize are already in the .avs don't repeat them, use some config like:
hello_hello
9th April 2018, 18:59
1. If I use -ac2 the only difference I get is that it now reports "auto_resampler", not the explicitly called "Parsed_aresample"
I finally got a chance to have a play, and it appears ffmpeg uses different downmix coefficients according to the input bitdepth. I guess if it's decoding, it'd depend how it's decoding the audio. I only tested with a piped input courtesy of foobar2000 and the following command line.
-report -loglevel debug -i - -ignore_length true -ac 2 -c:a libmp3lame -q:a 2 -id3v2_version 3 %d
The same source file (5.1ch AC3) was used each time, but for each I changed the maximum bitdepth in the fb2k encoder configuration.
32 bit float:
Stream mapping:
Stream #0:0 -> #0:0 (pcm_f32le (native) -> mp3 (libmp3lame))
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
detected 4 logical cores
[graph_0_in_0_0 @ 039abb40] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 039abb40] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 039abb40] Setting 'sample_fmt' to value 'flt'
[graph_0_in_0_0 @ 039abb40] Setting 'channel_layout' to value '0x3f'
[graph_0_in_0_0 @ 039abb40] tb:1/48000 samplefmt:flt samplerate:48000 chlayout:0x3f
[format_out_0_0 @ 039acc80] Setting 'sample_fmts' to value 's32p|fltp|s16p'
[format_out_0_0 @ 039acc80] Setting 'sample_rates' to value '44100|48000|32000|22050|24000|16000|11025|12000|8000'
[format_out_0_0 @ 039acc80] Setting 'channel_layouts' to value '0x3'
[format_out_0_0 @ 039acc80] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 0393c400] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 039ad680] picking fltp out of 3 ref:flt
[auto_resampler_0 @ 039ad680] [SWR @ 039adc80] Using fltp internally between filters
[auto_resampler_0 @ 039ad680] [SWR @ 039adc80] Matrix coefficients:
[auto_resampler_0 @ 039ad680] [SWR @ 039adc80] FL: FL:1.000000 FR:0.000000 FC:0.707107 LFE:0.000000 BL:0.707107 BR:0.000000
[auto_resampler_0 @ 039ad680] [SWR @ 039adc80] FR: FL:0.000000 FR:1.000000 FC:0.707107 LFE:0.000000 BL:0.000000 BR:0.707107
[auto_resampler_0 @ 039ad680] ch:6 chl:5.1 fmt:flt r:48000Hz -> ch:2 chl:stereo fmt:fltp r:48000Hz
Output #0, mp3, to 'test.mp3':
Metadata:
TSSE : Lavf58.9.100
Stream #0:0, 0, 1/48000: Audio: mp3 (libmp3lame), 48000 Hz, stereo, fltp, delay 1105
Metadata:
encoder : Lavc58.11.101 libmp3lame
24 bit integer:
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s24le (native) -> mp3 (libmp3lame))
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
detected 4 logical cores
[graph_0_in_0_0 @ 039abc80] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 039abc80] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 039abc80] Setting 'sample_fmt' to value 's32'
[graph_0_in_0_0 @ 039abc80] Setting 'channel_layout' to value '0x3f'
[graph_0_in_0_0 @ 039abc80] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x3f
[format_out_0_0 @ 039ace00] Setting 'sample_fmts' to value 's32p|fltp|s16p'
[format_out_0_0 @ 039ace00] Setting 'sample_rates' to value '44100|48000|32000|22050|24000|16000|11025|12000|8000'
[format_out_0_0 @ 039ace00] Setting 'channel_layouts' to value '0x3'
[format_out_0_0 @ 039ace00] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 0393a280] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 039ad3c0] picking s32p out of 3 ref:s32
[auto_resampler_0 @ 039ad3c0] [SWR @ 039addc0] Using fltp internally between filters
[auto_resampler_0 @ 039ad3c0] [SWR @ 039addc0] Matrix coefficients:
[auto_resampler_0 @ 039ad3c0] [SWR @ 039addc0] FL: FL:0.414214 FR:0.000000 FC:0.292893 LFE:0.000000 BL:0.292893 BR:0.000000
[auto_resampler_0 @ 039ad3c0] [SWR @ 039addc0] FR: FL:0.000000 FR:0.414214 FC:0.292893 LFE:0.000000 BL:0.000000 BR:0.292893
[auto_resampler_0 @ 039ad3c0] ch:6 chl:5.1 fmt:s32 r:48000Hz -> ch:2 chl:stereo fmt:s32p r:48000Hz
Output #0, mp3, to 'test.mp3':
Metadata:
TSSE : Lavf58.9.100
Stream #0:0, 0, 1/48000: Audio: mp3 (libmp3lame), 48000 Hz, stereo, s32p (24 bit), delay 1105
Metadata:
encoder : Lavc58.11.101 libmp3lame
16 bit integer:
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le (native) -> mp3 (libmp3lame))
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
detected 4 logical cores
[graph_0_in_0_0 @ 0397d840] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 0397d840] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 0397d840] Setting 'sample_fmt' to value 's16'
[graph_0_in_0_0 @ 0397d840] Setting 'channel_layout' to value '0x3f'
[graph_0_in_0_0 @ 0397d840] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x3f
[format_out_0_0 @ 03971d40] Setting 'sample_fmts' to value 's32p|fltp|s16p'
[format_out_0_0 @ 03971d40] Setting 'sample_rates' to value '44100|48000|32000|22050|24000|16000|11025|12000|8000'
[format_out_0_0 @ 03971d40] Setting 'channel_layouts' to value '0x3'
[format_out_0_0 @ 03971d40] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 039edc40] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 03971b00] picking s16p out of 3 ref:s16
[auto_resampler_0 @ 03971b00] [SWR @ 03a25080] Using s16p internally between filters
[auto_resampler_0 @ 03971b00] [SWR @ 03a25080] Matrix coefficients:
[auto_resampler_0 @ 03971b00] [SWR @ 03a25080] FL: FL:0.414214 FR:0.000000 FC:0.292893 LFE:0.000000 BL:0.292893 BR:0.000000
[auto_resampler_0 @ 03971b00] [SWR @ 03a25080] FR: FL:0.000000 FR:0.414214 FC:0.292893 LFE:0.000000 BL:0.000000 BR:0.292893
[auto_resampler_0 @ 03971b00] ch:6 chl:5.1 fmt:s16 r:48000Hz -> ch:2 chl:stereo fmt:s16p r:48000Hz
Output #0, mp3, to 'test.mp3':
Metadata:
TSSE : Lavf58.9.100
Stream #0:0, 0, 1/48000: Audio: mp3 (libmp3lame), 48000 Hz, stereo, s16p, delay 1105
Metadata:
encoder : Lavc58.11.101 libmp3lame
I dunno.... it seems kind of odd to me it's not consistent.
hello_hello
9th April 2018, 19:20
To make it even more interesting, ffmpeg changes downmix coefficients according to the output format.
-report -loglevel debug -i - -ignore_length true -ac 2 -c:a aac %d
32 bit float:
Stream mapping:
Stream #0:0 -> #0:0 (pcm_f32le (native) -> aac (native))
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
detected 4 logical cores
[graph_0_in_0_0 @ 039aad00] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 039aad00] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 039aad00] Setting 'sample_fmt' to value 'flt'
[graph_0_in_0_0 @ 039aad00] Setting 'channel_layout' to value '0x3f'
[graph_0_in_0_0 @ 039aad00] tb:1/48000 samplefmt:flt samplerate:48000 chlayout:0x3f
[format_out_0_0 @ 039abe80] Setting 'sample_fmts' to value 'fltp'
[format_out_0_0 @ 039abe80] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[format_out_0_0 @ 039abe80] Setting 'channel_layouts' to value '0x3'
[format_out_0_0 @ 039abe80] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 039aa180] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 039ac8c0] [SWR @ 039acf80] Using fltp internally between filters
[auto_resampler_0 @ 039ac8c0] [SWR @ 039acf80] Matrix coefficients:
[auto_resampler_0 @ 039ac8c0] [SWR @ 039acf80] FL: FL:1.000000 FR:0.000000 FC:0.707107 LFE:0.000000 BL:0.707107 BR:0.000000
[auto_resampler_0 @ 039ac8c0] [SWR @ 039acf80] FR: FL:0.000000 FR:1.000000 FC:0.707107 LFE:0.000000 BL:0.000000 BR:0.707107
[auto_resampler_0 @ 039ac8c0] ch:6 chl:5.1 fmt:flt r:48000Hz -> ch:2 chl:stereo fmt:fltp r:48000Hz
Output #0, ipod, to 'test.m4a':
Metadata:
encoder : Lavf58.9.100
Stream #0:0, 0, 1/48000: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, delay 1024, 128 kb/s
Metadata:
encoder : Lavc58.11.101 aac
24 bit integer:
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s24le (native) -> aac (native))
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
detected 4 logical cores
[graph_0_in_0_0 @ 039ab4c0] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 039ab4c0] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 039ab4c0] Setting 'sample_fmt' to value 's32'
[graph_0_in_0_0 @ 039ab4c0] Setting 'channel_layout' to value '0x3f'
[graph_0_in_0_0 @ 039ab4c0] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x3f
[format_out_0_0 @ 039ac100] Setting 'sample_fmts' to value 'fltp'
[format_out_0_0 @ 039ac100] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[format_out_0_0 @ 039ac100] Setting 'channel_layouts' to value '0x3'
[format_out_0_0 @ 039ac100] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 039aa980] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 039ad080] [SWR @ 039ad740] Using fltp internally between filters
[auto_resampler_0 @ 039ad080] [SWR @ 039ad740] Matrix coefficients:
[auto_resampler_0 @ 039ad080] [SWR @ 039ad740] FL: FL:1.000000 FR:0.000000 FC:0.707107 LFE:0.000000 BL:0.707107 BR:0.000000
[auto_resampler_0 @ 039ad080] [SWR @ 039ad740] FR: FL:0.000000 FR:1.000000 FC:0.707107 LFE:0.000000 BL:0.000000 BR:0.707107
[auto_resampler_0 @ 039ad080] ch:6 chl:5.1 fmt:s32 r:48000Hz -> ch:2 chl:stereo fmt:fltp r:48000Hz
Output #0, ipod, to 'test.m4a':
Metadata:
encoder : Lavf58.9.100
Stream #0:0, 0, 1/48000: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp (24 bit), delay 1024, 128 kb/s
Metadata:
encoder : Lavc58.11.101 aac
16 bit integer:
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le (native) -> aac (native))
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
detected 4 logical cores
[graph_0_in_0_0 @ 0399e880] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 0399e880] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 0399e880] Setting 'sample_fmt' to value 's16'
[graph_0_in_0_0 @ 0399e880] Setting 'channel_layout' to value '0x3f'
[graph_0_in_0_0 @ 0399e880] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x3f
[format_out_0_0 @ 03af3a80] Setting 'sample_fmts' to value 'fltp'
[format_out_0_0 @ 03af3a80] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[format_out_0_0 @ 03af3a80] Setting 'channel_layouts' to value '0x3'
[format_out_0_0 @ 03af3a80] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 03920f80] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 03985580] [SWR @ 03a4f240] Using fltp internally between filters
[auto_resampler_0 @ 03985580] [SWR @ 03a4f240] Matrix coefficients:
[auto_resampler_0 @ 03985580] [SWR @ 03a4f240] FL: FL:1.000000 FR:0.000000 FC:0.707107 LFE:0.000000 BL:0.707107 BR:0.000000
[auto_resampler_0 @ 03985580] [SWR @ 03a4f240] FR: FL:0.000000 FR:1.000000 FC:0.707107 LFE:0.000000 BL:0.000000 BR:0.707107
[auto_resampler_0 @ 03985580] ch:6 chl:5.1 fmt:s16 r:48000Hz -> ch:2 chl:stereo fmt:fltp r:48000Hz
Output #0, ipod, to 'test.m4a':
Metadata:
encoder : Lavf58.9.100
Stream #0:0, 0, 1/48000: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, delay 1024, 128 kb/s
Metadata:
encoder : Lavc58.11.101 aac
doomleox999
13th April 2018, 03:53
Sadly, I'm still getting the same result. I checked the ffmpeg report and this is how it mixes (you know what I mean) the channels:
[auto_resampler_0 @ 000002e30d6f3d80] [SWR @ 000002e30d6f3e80] FL: FL:1.000000 FR:0.000000 FC:0.707107 LFE:0.000000 BL:0.707107 BR:0.000000
[auto_resampler_0 @ 000002e30d6f3d80] [SWR @ 000002e30d6f3e80] FR: FL:0.000000 FR:1.000000 FC:0.707107 LFE:0.000000 BL:0.000000 BR:0.707107
Is it possible to write a script so MeGUI can do the same?
What about this "Extra" tab? Can you add something here to make MeGUI use other matrix when downmixing the channels?
https://i.imgur.com/SFazWgf.jpg
tebasuna51
13th April 2018, 09:19
Is it possible to write a script so MeGUI can do the same?
Of course replace the part of my script:
fl_sl = MixAudio(fl, sl, 0.414214, 0.292893)
fr_sr = MixAudio(fr, sr, 0.414214, 0.292893)
l = MixAudio(fl_sl, fc, 1.0, 0.292893)
r = MixAudio(fr_sr, fc, 1.0, 0.292893)
MergeChannels(l, r)
Normalize()
with:
fl_sl = MixAudio(fl, sl, 1.0, 0.707107)
fr_sr = MixAudio(fr, sr, 1.0, 0.707107)
l = MixAudio(fl_sl, fc, 1.0, 0.707107)
r = MixAudio(fr_sr, fc, 1.0, 0.707107)
MergeChannels(l, r)
Don't use Normalize() because you can obtain the same than before.
Now you can have clips in all volume values between 1.0 and 2.4
Like my image in https://forum.doom9.org/showthread.php?p=1838646#post1838646
What about this "Extra" tab? Can you add something here to make MeGUI use other matrix when downmixing the channels?
Nope, the Custom Command Line is for add parameters to NeroAacEnc.
Nothing usefull can be added here.
doomleox999
19th April 2018, 08:41
I still don't get the same result I get when encoding with ffmpeg (2ch sounds the same as original 6ch) so maybe I should give you more info about this whole situation.
The original file is a mkv with video, audio and some subtitles. This is what MediaInfo says about the audio:
Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : HE-AAC / LC
Format settings : Explicit
Codec ID : A_AAC-2
Duration : 1 h 26 min
Bit rate : 141 kb/s
Channel(s) : 6 channels
Channel positions : Front: L C R, Side: L R, LFE
Sampling rate : 48.0 kHz / 24.0 kHz
Frame rate : 23.438 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 87.6 MiB (7%)
Is it OK to encode the mkv directly to aac or m4a or is better to extract the audio and encode that file? Because something weird happens when I extract the audio. If I open it, MPC-HC tells me its lenght is 1 h 22 min but Windows Explorer says 3 h 46 min.
I use this script:
AddAutoloadDir("C:\Users\LTX\BACKUP\MeGUI\tools\avs\plugins")
LoadPlugin("C:\Users\LTX\BACKUP\MeGUI\tools\lsmash\LSMASHSource.dll")
a=LWLibavAudioSource("C:\Users\LTX\Desktop\EOE_6CH.mkv")
fl = GetChannel(a, 1)
fr = GetChannel(a, 2)
fc = GetChannel(a, 3)
# lf = GetChannel(a, 4)
sl = GetChannel(a, 5)
sr = GetChannel(a, 6)
fl_sl = MixAudio(fl, sl, 1.0, 0.707107)
fr_sr = MixAudio(fr, sr, 1.0, 0.707107)
l = MixAudio(fl_sl, fc, 1.0, 0.707107)
r = MixAudio(fr_sr, fc, 1.0, 0.707107)
MergeChannels(l, r)
But when I check the MeGUI log I think the program is ignoring the script, maybe because of the options I choose:
https://i.imgur.com/a4L5591.jpg
And those are the options I want. Another weird thing is that MeGUI takes like 50 min to encode the audio, while ffmpeg is super fast and gives me a better result.
mkver
19th April 2018, 09:24
I somehow forgot about this thread, but now that I see hello_hellos results I see a system behind it: If ffmpeg downmixes to 32b float, it uses the one set of coefficients, if it downmixes to pcm it uses the other set of coefficients. The most direct way to test this is by not using the aac or libmp3lame encoders, but -c:a pcm_s16le, pcm_s24le, pcm_f32le. And if one does it, the results confirm the preceding statement. The aac encoder probably accepts float input only (or prefers it) so that the auto_resampler resamples everything to float, whereas libmp3lame seems to accept everything so that downmixing in this case only changes the number of channels, not the sample format.
But does anybody have a definitive answer why ffmpeg uses different coefficients for float and non-float? In both cases the ratios coincide: 1/0.707107 and 0.414214/0.292893 are both very good approximations for 2^(0.5) which is probably the value that they are supposed to be. Probably it is because one doesn't need to care about clipping that much if one uses float output.
tebasuna51
19th April 2018, 10:39
I still don't get the same result I get when encoding with ffmpeg (2ch sounds the same as original 6ch)
I can't understand how 2 ch sound the same as 6 ch.
2 speakers can supply the same volume than 6 speakers?
Do you listen the 6 ch in a 6 speakers system?
Is it OK to encode the mkv directly to aac or m4a or is better to extract the audio and encode that file?
It is the same, some soft (eac3to, ffmpeg) can do the 4 task (extract, decode, downmix and recode) in 1 job.
Because something weird happens when I extract the audio. If I open it, MPC-HC tells me its lenght is 1 h 22 min but Windows Explorer says 3 h 46 min.
If you want know exactly the info about a AAC audio you need extract the aac and use a soft than read the full file like LeeAudBi (https://www.sendspace.com/filegroup/TRjdKOmbRCIBaFxtyU6Jkw), you can't trust in MPC-HC, Windows Explorer or MediaInfo.
But when I check the MeGUI log I think the program is ignoring the script, maybe because of the options I choose:
Another weird thing is that MeGUI takes like 50 min to encode the audio,
It is not normal, please supply the MeGUI log.
But does anybody have a definitive answer why ffmpeg uses different coefficients for float and non-float?
Good question, but we can force the coefficients using the filter -af "pan=stereo..."
Then you can select the coefficients with ffmpeg and with AviSinth, and obtain the same.
Probably it is because one doesn't need to care about clipping that much if one uses float output.
But at some point in the chain of conversion between digital to analog audio all values over 1.0 are clipped.
You need Normalize or accept distort audio, maybe only a few points and you don't care in this sample, but we can't expect that always.
doomleox999
20th April 2018, 04:57
I can't understand how 2 ch sound the same as 6 ch.
2 speakers can supply the same volume than 6 speakers?
Do you listen the 6 ch in a 6 speakers system?
I use headphones. The best way to explain the difference I hear would be sending you samples from the original 6ch, the MeGUI 2ch encode, and the ffmpeg 2ch encode, because my vocabulary regarding audio is limited, I can't explain myself well (even in my first language haha) but I'm not sure if that's allowed.
This is the MeGUI log using the script from my previous reply:
(I had to edit it so I could post it, I removed every "[NoImage]")
[Information] Log
-[Information] Versions
--[Information] MeGUI: 2828 x86
--[Information] Update Check: stable update server
--[Information] System Information
---[Information] Operating System: Windows 10 (CORE_SINGLELANGUAGE) 1709 x64 (10.0.16299.309)
---[Information] .NET Framework: 4.0 (4.0.0.0)
---[Information] .NET Framework: 4.7 (4.7.02556)
---[Information] DPI: 100% (96/96)
---[Information] Monitor 1
----[Information] Resolution: 1366x768
----[Information] Primary Screen: True
--[Information] Component Information
---[Information] Haali Media Splitter: not installed
---[Information] Haali DSS2: not installed
---[Information] ICSharpCode.SharpZipLib: 0.85.5.452 (07-08-2008)
---[Information] MediaInfo: 17.12.0.0 (21-12-2017)
---[Information] SevenZipSharp: 0.64.3890.29348 (02-01-2011)
---[Information] 7z: 9.20 (18-11-2010)
--[Information] AviSynth Information
---[Information] AviSynth Wrapper
----[Information] Version: 1.0.2721.0
----[Information] Date: 29-04-2017
----[Information] Interface: 3
---[Information] AviSynth
----[Information] not installed
---[Information] AviSynth portable
----[Information] File Version: 0.1
----[Information] Date: 27-12-2017
----[Information] Name: AviSynth+ 0.1 (r2580, MT, i386)
----[Information] Version: AviSynth+ 0.1 (r2580, MT, i386)
----[Information] AviSynth+: true
----[Information] MT: true
----[Information] Status: active
-[Information] Update detection
--[Information] [19/04/18 22:42:19] Connected to server: http://megui.org/auto/stable/
--[Information] [19/04/18 22:42:19] No package requires an update
-[Information] Log for job1 (audio, EOE_6CH.avs -> EOE_6CH.m4a)
--[Information] [19/04/18 22:59:33] Started handling job
--[Information] [19/04/18 22:59:33] Preprocessing
--[Information] [19/04/18 22:59:34] MediaInfo
---[Information] [19/04/18 22:59:34] File: C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH.avs
---[Information] AVS input file detected. Getting media information from AviSynth.
---[Information] General
----[Information] Format: AVS
----[Information] FormatString: AviSynth Script
----[Information] FileSize: 536
----[Information] PlayTime: 01:26:49.1310000
---[Information] Audio
----[Information] ID: 0
----[Information] StreamOrder:
----[Information] Format: AVS
----[Information] FormatProfile:
----[Information] FormatSettingsSBR:
----[Information] FormatSettingsPS:
----[Information] Muxing Mode:
----[Information] SamplingRate: 48000
----[Information] SamplingRateString: 48000
----[Information] Channels: 2
----[Information] ChannelsString: 2 channels
----[Information] ChannelPositionsString2:
----[Information] BitRateMode: CBR
----[Information] Delay: 0
----[Information] Title:
----[Information] Language:
----[Information] LanguageString:
----[Information] Default:
----[Information] DefaultString:
----[Information] Forced:
----[Information] ForcedString:
----[Information] [19/04/18 22:59:43] The language information is not available for this track. The default MeGUI language has been selected.
--[Information] [19/04/18 22:59:50] Ignoring downmix as there is only 2 channel(s)
--[Information] [19/04/18 22:59:50] AviSynth script
--- ClearAutoloadDirs()
--- AddAutoloadDir("C:\Users\LTX\BACKUP\MeGUI\tools\avs\plugins")
--- Import("C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH.avs")
--- # detected channels: 2
--- # detected channel positions:
--- Normalize()
--- return last
--- # 5.1 Channels L,R,C,LFE,SL,SR -> stereo + LFE
--- function c6_stereo(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- lf = GetChannel(a, 4)
--- sl = GetChannel(a, 5)
--- sr = GetChannel(a, 6)
--- fl_sl = MixAudio(fl, sl, 0.2929, 0.2929)
--- fr_sr = MixAudio(fr, sr, 0.2929, 0.2929)
--- fc_lf = MixAudio(fc, lf, 0.2071, 0.2071)
--- l = MixAudio(fl_sl, fc_lf, 1.0, 1.0)
--- r = MixAudio(fr_sr, fc_lf, 1.0, 1.0)
--- return MergeChannels(l, r)
--- }
--- # 5 Channels L,R,C,SL,SR or L,R,LFE,SL,SR-> Stereo
--- function c5_stereo(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- sl = GetChannel(a, 4)
--- sr = GetChannel(a, 5)
--- fl_sl = MixAudio(fl, sl, 0.3694, 0.3694)
--- fr_sr = MixAudio(fr, sr, 0.3694, 0.3694)
--- l = MixAudio(fl_sl, fc, 1.0, 0.2612)
--- r = MixAudio(fr_sr, fc, 1.0, 0.2612)
--- return MergeChannels(l, r)
--- }
--- # 5 Channels L,R,C,LFE,S -> Stereo
--- function c52_stereo(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- lf = GetChannel(a, 4)
--- bc = GetChannel(a, 5)
--- fl_bc = MixAudio(fl, bc, 0.3205, 0.2265)
--- fr_bc = MixAudio(fr, bc, 0.3205, 0.2265)
--- fc_lf = MixAudio(fc, lf, 0.2265, 0.2265)
--- l = MixAudio(fl_bc, fc_lf, 1.0, 1.0)
--- r = MixAudio(fr_bc, fc_lf, 1.0, 1.0)
--- return MergeChannels(l, r)
--- }
--- # 4 Channels Quadro L,R,SL,SR -> Stereo
--- function c4_stereo(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- sl = GetChannel(a, 3)
--- sr = GetChannel(a, 4)
--- l = MixAudio(fl, sl, 0.5, 0.5)
--- r = MixAudio(fr, sr, 0.5, 0.5)
--- return MergeChannels(l, r)
--- }
--- # 4 Channels L,R,C,LFE or L,R,S,LFE or L,R,C,S -> Stereo
--- function c42_stereo(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- lf = GetChannel(a, 4)
--- fc_lf = MixAudio(fc, lf, 0.2929, 0.2929)
--- l = MixAudio(fl, fc_lf, 0.4142, 1.0)
--- r = MixAudio(fr, fc_lf, 0.4142, 1.0)
--- return MergeChannels(l, r)
--- }
--- # 3 Channels L,R,C or L,R,S or L,R,LFE -> Stereo
--- function c3_stereo(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- l = MixAudio(fl, fc, 0.5858, 0.4142)
--- r = MixAudio(fr, fc, 0.5858, 0.4142)
--- return MergeChannels(l, r)
--- }
--- # 5.1 Channels L,R,C,LFE,SL,SR -> Dolby ProLogic
--- function c6_dpl(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- sl = GetChannel(a, 5)
--- sr = GetChannel(a, 6)
--- bc = MixAudio(sl, sr, 0.2265, 0.2265)
--- fl_fc = MixAudio(fl, fc, 0.3205, 0.2265)
--- fr_fc = MixAudio(fr, fc, 0.3205, 0.2265)
--- l = MixAudio(fl_fc, bc, 1.0, 1.0)
--- r = MixAudio(fr_fc, bc, 1.0, -1.0)
--- return MergeChannels(l, r)
--- }
--- # 5 Channels L,R,C,SL,SR -> Dolby ProLogic
--- function c5_dpl(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- sl = GetChannel(a, 4)
--- sr = GetChannel(a, 5)
--- bc = MixAudio(sl, sr, 0.2265, 0.2265)
--- fl_fc = MixAudio(fl, fc, 0.3205, 0.2265)
--- fr_fc = MixAudio(fr, fc, 0.3205, 0.2265)
--- l = MixAudio(fl_fc, bc, 1.0, 1.0)
--- r = MixAudio(fr_fc, bc, 1.0, -1.0)
--- return MergeChannels(l, r)
--- }
--- # 5 Channels L,R,LFE,SL,SR -> Dolby ProLogic
--- function c52_dpl(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- sl = GetChannel(a, 4)
--- sr = GetChannel(a, 5)
--- bc = MixAudio(sl, sr, 0.2929, 0.2929)
--- l = MixAudio(fl, bc, 0.4142, 1.0)
--- r = MixAudio(fr, bc, 0.4142, -1.0)
--- return MergeChannels(l, r)
--- }
--- # 5 Channels L,R,C,LFE,S -> Dolby ProLogic
--- function c53_dpl(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- bc = GetChannel(a, 5)
--- fl_fc = MixAudio(fl, fc, 0.4142, 0.2929)
--- fr_fc = MixAudio(fr, fc, 0.4142, 0.2929)
--- l = MixAudio(fl_fc, bc, 1.0, 0.2929)
--- r = MixAudio(fr_fc, bc, 1.0, -0.2929)
--- return MergeChannels(l, r)
--- }
--- # 4 Channels Quadro L,R,SL,SR -> Dolby ProLogic
--- function c4_dpl(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- sl = GetChannel(a, 3)
--- sr = GetChannel(a, 4)
--- bc = MixAudio(sl, sr, 0.2929, 0.2929)
--- l = MixAudio(fl, bc, 0.4142, 1.0)
--- r = MixAudio(fr, bc, 0.4142, -1.0)
--- return MergeChannels(l, r)
--- }
--- # 4 Channels L,R,LFE,S -> Dolby ProLogic
--- function c42_dpl(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- bc = GetChannel(a, 4)
--- l = MixAudio(fl, bc, 0.5858, 0.4142)
--- r = MixAudio(fr, bc, 0.5858, -0.4142)
--- return MergeChannels(l, r)
--- }
--- # 4 Channels L,R,C,S -> Dolby ProLogic
--- function c43_dpl(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- bc = GetChannel(a, 4)
--- fl_fc = MixAudio(fl, fc, 0.4142, 0.2929)
--- fr_fc = MixAudio(fr, fc, 0.4142, 0.2929)
--- l = MixAudio(fl_fc, bc, 1.0, 0.2929)
--- r = MixAudio(fr_fc, bc, 1.0, -0.2929)
--- return MergeChannels(l, r)
--- }
--- # 3 Channels L,R,S -> Dolby ProLogic
--- function c3_dpl(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- bc = GetChannel(a, 3)
--- l = MixAudio(fl, bc, 0.5858, 0.4142)
--- r = MixAudio(fr, bc, 0.5858, -0.4142)
--- return MergeChannels(l, r)
--- }
--- # 5.1 Channels L,R,C,LFE,SL,SR -> Dolby ProLogic II
--- function c6_dpl2(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- sl = GetChannel(a, 5)
--- sr = GetChannel(a, 6)
--- ssl = MixAudio(sl, sr, 0.2818, 0.1627)
--- ssr = MixAudio(sl, sr, -0.1627, -0.2818)
--- fl_fc = MixAudio(fl, fc, 0.3254, 0.2301)
--- fr_fc = MixAudio(fr, fc, 0.3254, 0.2301)
--- l = MixAudio(fl_fc, ssl, 1.0, 1.0)
--- r = MixAudio(fr_fc, ssr, 1.0, 1.0)
--- return MergeChannels(l, r)
--- }
--- # 5 Channels L,R,C,SL,SR -> Dolby ProLogic II
--- function c5_dpl2(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- fc = GetChannel(a, 3)
--- sl = GetChannel(a, 4)
--- sr = GetChannel(a, 5)
--- ssl = MixAudio(sl, sr, 0.2818, 0.1627)
--- ssr = MixAudio(sl, sr, -0.1627, -0.2818)
--- fl_fc = MixAudio(fl, fc, 0.3254, 0.2301)
--- fr_fc = MixAudio(fr, fc, 0.3254, 0.2301)
--- l = MixAudio(fl_fc, ssl, 1.0, 1.0)
--- r = MixAudio(fr_fc, ssr, 1.0, 1.0)
--- return MergeChannels(l, r)
--- }
--- # 5 Channels L,R,LFE,SL,SR -> Dolby ProLogic II
--- function c52_dpl2(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- sl = GetChannel(a, 4)
--- sr = GetChannel(a, 5)
--- ssl = MixAudio(sl, sr, 0.3714, 0.2144)
--- ssr = MixAudio(sl, sr, -0.2144, -0.3714)
--- l = MixAudio(fl, ssl, 0.4142, 1.0)
--- r = MixAudio(fr, ssr, 0.4142, 1.0)
--- return MergeChannels(l, r)
--- }
--- # 4 Channels Quadro L,R,SL,SR -> Dolby ProLogic II
--- function c4_dpl2(clip a)
--- {
--- fl = GetChannel(a, 1)
--- fr = GetChannel(a, 2)
--- sl = GetChannel(a, 3)
--- sr = GetChannel(a, 4)
--- ssl = MixAudio(sl, sr, 0.3714, 0.2144)
--- ssr = MixAudio(sl, sr, -0.2144, -0.3714)
--- l = MixAudio(fl, ssl, 0.4142, 1.0)
--- r = MixAudio(fr, ssr, 0.4142, 1.0)
--- return MergeChannels(l, r)
--- }
--[Information] [19/04/18 22:59:50] Command line used: -ignorelength -br 128000 -if - -of "{0}"
--[Information] [19/04/18 22:59:50] AviSynth script environment opened
--[Information] [19/04/18 22:59:56] Script loaded
--[Information] [19/04/18 22:59:56] Output Decoder
---[Information] [19/04/18 22:59:56] Channels: 2
---[Information] [19/04/18 22:59:56] Bits per sample: 32
---[Information] [19/04/18 22:59:56] Sample rate: 48000
--[Information] [19/04/18 22:59:56] Job command line: C:\Users\LTX\BACKUP\MeGUI\tools\eac3to\neroAacEnc.exe -ignorelength -br 128000 -if - -of "C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH.m4a"
--[Information] [19/04/18 22:59:58] Process started
--[Information] [19/04/18 22:59:58] Standard output stream
--[Information] [19/04/18 22:59:58] Standard error stream
---[Information] [19/04/18 23:09:30] *************************************************************
---[Information] [19/04/18 23:09:30] * *
---[Information] [19/04/18 23:09:30] * Nero AAC Encoder *
---[Information] [19/04/18 23:09:30] * Copyright 2009 Nero AG *
---[Information] [19/04/18 23:09:30] * All Rights Reserved Worldwide *
---[Information] [19/04/18 23:09:30] * *
---[Information] [19/04/18 23:09:30] * Package build date: Feb 18 2010 *
---[Information] [19/04/18 23:09:30] * Package version: 1.5.4.0 *
---[Information] [19/04/18 23:09:30] * *
---[Information] [19/04/18 23:09:30] * See -help for a complete list of available parameters. *
---[Information] [19/04/18 23:09:30] * *
---[Information] [19/04/18 23:09:30] *************************************************************
--[Information] [19/04/18 23:47:51] MediaInfo
---[Information] [19/04/18 23:47:51] File: C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH.m4a
---[Information] General
----[Information] Format: MPEG-4
----[Information] FormatString: MPEG-4
----[Information] FileSize: 84327816
----[Information] PlayTime: 01:26:49.195
---[Information] Audio
----[Information] ID: 1
----[Information] StreamOrder: 0
----[Information] Format: AAC
----[Information] FormatProfile: LC
----[Information] FormatSettingsSBR: No (Explicit)
----[Information] FormatSettingsPS:
----[Information] Muxing Mode:
----[Information] SamplingRate: 48000
----[Information] SamplingRateString: 48.0 kHz
----[Information] Channels: 2
----[Information] ChannelsString: 2 channels
----[Information] ChannelPositionsString2: 2/0/0
----[Information] BitRateMode: VBR
----[Information] Delay:
----[Information] Title:
----[Information] Language:
----[Information] LanguageString:
----[Information] Default:
----[Information] DefaultString:
----[Information] Forced:
----[Information] ForcedString:
----[Information] [19/04/18 23:47:51] The language information is not available for this track. The default MeGUI language has been selected.
--[Information] [19/04/18 23:47:51] Postprocessing
---[Information] [19/04/18 23:47:51] Deleting intermediate files
--[Information] [19/04/18 23:47:51] Job completed
Ignoring downmix as there is only 2 channel(s)
What? Why? It has 6 channels for sure!
tebasuna51
20th April 2018, 13:17
I use headphones.
In any point of your audio chain there are a downmix to send audio to your headphones with only 2 speakers.
You are comparing a downmix method with other, not the original and the downmixed.
The best way to explain the difference I hear would be sending you samples from the original 6ch, ... but I'm not sure if that's allowed.
You can cut a sample and upload in http://www.sendspace.com for instance.
This is the MeGUI log using the script from my previous reply:
-- Ignoring downmix as there is only 2 channel(s)
...
Import("C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH.avs")
# detected channels: 2
Normalize()
return last
...
What? Why? It has 6 channels for sure!
The original have 6 channels but now the input is EOE_6CH.avs
And inside EOE_6CH.avs there are already the desired downmix to 2.0, and also a Normalize(), duplicated now.
See my image in https://forum.doom9.org/showthread.php?p=1839018#post1839018
When the input is a .avs with the desired downmix you can select:
Keep Original channels
and if the Normalize() is included in the .avs, uncheck the Normalize peaks or you waste time with 2 Normalize() functions.
doomleox999
22nd April 2018, 01:20
So, I used this script:
ClearAutoloadDirs()
AddAutoloadDir("C:\Users\LTX\BACKUP\MeGUI\tools\avs\plugins")
LoadPlugin("C:\Users\LTX\BACKUP\MeGUI\tools\lsmash\LSMASHSource.dll")
a=LWLibavAudioSource("C:\Users\LTX\Desktop\EOE_6CH.mkv")
fl = GetChannel(a, 1)
fr = GetChannel(a, 2)
fc = GetChannel(a, 3)
# lf = GetChannel(a, 4)
sl = GetChannel(a, 5)
sr = GetChannel(a, 6)
fl_sl = MixAudio(fl, sl, 1.0, 0.707107)
fr_sr = MixAudio(fr, sr, 1.0, 0.707107)
l = MixAudio(fl_sl, fc, 1.0, 0.707107)
r = MixAudio(fr_sr, fc, 1.0, 0.707107)
MergeChannels(l, r)
Normalize()
return last
With this audio configuration:
https://i.imgur.com/gZZ8zCg.jpg
And I'm still getting the same result. Here's the log:
[Information] Log
-[Information] Versions
--[Information] MeGUI: 2828 x86
--[Information] Update Check: stable update server
--[Information] System Information
---[Information] Operating System: Windows 10 (CORE_SINGLELANGUAGE) 1709 x64 (10.0.16299.309)
---[Information] .NET Framework: 4.0 (4.0.0.0)
---[Information] .NET Framework: 4.7 (4.7.02556)
---[Information] DPI: 100% (96/96)
---[Information] Monitor 1
----[Information] Resolution: 1366x768
----[Information] Primary Screen: True
--[Information] Component Information
---[Information] Haali Media Splitter: not installed
---[Information] Haali DSS2: not installed
---[Information] ICSharpCode.SharpZipLib: 0.85.5.452 (07-08-2008)
---[Information] MediaInfo: 17.12.0.0 (21-12-2017)
---[Information] SevenZipSharp: 0.64.3890.29348 (02-01-2011)
---[Information] 7z: 9.20 (18-11-2010)
--[Information] AviSynth Information
---[Information] AviSynth Wrapper
----[Information] Version: 1.0.2721.0
----[Information] Date: 29-04-2017
----[Information] Interface: 3
---[Information] AviSynth
----[Information] not installed
---[Information] AviSynth portable
----[Information] File Version: 0.1
----[Information] Date: 27-12-2017
----[Information] Name: AviSynth+ 0.1 (r2580, MT, i386)
----[Information] Version: AviSynth+ 0.1 (r2580, MT, i386)
----[Information] AviSynth+: true
----[Information] MT: true
----[Information] Status: active
-[Information] Update detection
--[Information] [21/04/18 06:51:22] Using cached update config and server: http://megui.org/auto/stable/
--[Information] [21/04/18 06:51:22] No package requires an update
-[Information] Log for job1 (audio, EOE_6CH.avs -> EOE_6CH_custom_script.m4a)
--[Information] [21/04/18 06:55:22] Started handling job
--[Information] [21/04/18 06:55:22] Preprocessing
--[Information] [21/04/18 06:55:23] MediaInfo
---[Information] [21/04/18 06:55:23] File: C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH.avs
---[Information] AVS input file detected. Getting media information from AviSynth.
---[Information] General
----[Information] Format: AVS
----[Information] FormatString: AviSynth Script
----[Information] FileSize: 585
----[Information] PlayTime: 01:26:49.1310000
---[Information] Audio
----[Information] ID: 0
----[Information] StreamOrder:
----[Information] Format: AVS
----[Information] FormatProfile:
----[Information] FormatSettingsSBR:
----[Information] FormatSettingsPS:
----[Information] Muxing Mode:
----[Information] SamplingRate: 48000
----[Information] SamplingRateString: 48000
----[Information] Channels: 2
----[Information] ChannelsString: 2 channels
----[Information] ChannelPositionsString2:
----[Information] BitRateMode: CBR
----[Information] Delay: 0
----[Information] Title:
----[Information] Language:
----[Information] LanguageString:
----[Information] Default:
----[Information] DefaultString:
----[Information] Forced:
----[Information] ForcedString:
----[Information] [21/04/18 06:55:31] The language information is not available for this track. The default MeGUI language has been selected.
--[Information] [21/04/18 06:55:40] AviSynth script
---[NoImage] ClearAutoloadDirs()
---[NoImage] AddAutoloadDir("C:\Users\LTX\BACKUP\MeGUI\tools\avs\plugins")
---[NoImage] Import("C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH.avs")
---[NoImage] # detected channels: 2
---[NoImage] # detected channel positions:
---[NoImage] return last
--[Information] [21/04/18 06:55:40] Command line used: -ignorelength -q 0.4 -if - -of "{0}"
--[Information] [21/04/18 06:55:40] AviSynth script environment opened
--[Information] [21/04/18 06:55:47] Script loaded
--[Information] [21/04/18 06:55:47] Output Decoder
---[Information] [21/04/18 06:55:47] Channels: 2
---[Information] [21/04/18 06:55:47] Bits per sample: 32
---[Information] [21/04/18 06:55:47] Sample rate: 48000
--[Information] [21/04/18 06:55:47] Job command line: C:\Users\LTX\BACKUP\MeGUI\tools\eac3to\neroAacEnc.exe -ignorelength -q 0.4 -if - -of "C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH_custom_script.m4a"
--[Information] [21/04/18 06:55:49] Process started
--[Information] [21/04/18 06:55:49] Standard output stream
--[Information] [21/04/18 06:55:49] Standard error stream
---[Information] [21/04/18 07:12:27] *************************************************************
---[Information] [21/04/18 07:12:27] * *
---[Information] [21/04/18 07:12:27] * Nero AAC Encoder *
---[Information] [21/04/18 07:12:27] * Copyright 2009 Nero AG *
---[Information] [21/04/18 07:12:27] * All Rights Reserved Worldwide *
---[Information] [21/04/18 07:12:27] * *
---[Information] [21/04/18 07:12:27] * Package build date: Feb 18 2010 *
---[Information] [21/04/18 07:12:27] * Package version: 1.5.4.0 *
---[Information] [21/04/18 07:12:27] * *
---[Information] [21/04/18 07:12:27] * See -help for a complete list of available parameters. *
---[Information] [21/04/18 07:12:27] * *
---[Information] [21/04/18 07:12:27] *************************************************************
--[Information] [21/04/18 08:02:15] MediaInfo
---[Information] [21/04/18 08:02:15] File: C:\Users\LTX\Desktop\MeGUI Output\EOE_6CH_custom_script.m4a
---[Information] General
----[Information] Format: MPEG-4
----[Information] FormatString: MPEG-4
----[Information] FileSize: 74149830
----[Information] PlayTime: 01:26:49.195
---[Information] Audio
----[Information] ID: 1
----[Information] StreamOrder: 0
----[Information] Format: AAC
----[Information] FormatProfile: LC
----[Information] FormatSettingsSBR: No (Explicit)
----[Information] FormatSettingsPS:
----[Information] Muxing Mode:
----[Information] SamplingRate: 48000
----[Information] SamplingRateString: 48.0 kHz
----[Information] Channels: 2
----[Information] ChannelsString: 2 channels
----[Information] ChannelPositionsString2: 2/0/0
----[Information] BitRateMode: VBR
----[Information] Delay:
----[Information] Title:
----[Information] Language:
----[Information] LanguageString:
----[Information] Default:
----[Information] DefaultString:
----[Information] Forced:
----[Information] ForcedString:
----[Information] [21/04/18 08:02:17] The language information is not available for this track. The default MeGUI language has been selected.
--[Information] [21/04/18 08:02:17] Postprocessing
---[Information] [21/04/18 08:02:17] Deleting intermediate files
--[Information] [21/04/18 08:02:17] Job completed
BTW, these are the first 15 seconds of the file. The samples are from the original mkv file, the ffmpeg encode and the MeGUI encode.
6 CH ORIGINAL MKV.aac (https://www.sendspace.com/file/ucii96)
2 CH FFMPEG.aac (https://www.sendspace.com/file/wq45cq)
2 CH MEGUI.aac (https://www.sendspace.com/file/5a1qul)
I hope this is enough for you to note the difference between the 2 encodes, if it's not, let me know and I'll upload more.
tebasuna51
22nd April 2018, 12:58
The audio volume is proportional to RMS value of audio signals, your 6 CH original sample:
6 CH ORIGINAL MKV.aac
---------------------
RMS power ch0: 3.56% (-28.98 dB)
RMS power ch1: 2.27% (-32.87 dB)
RMS power ch2: 1.80% (-34.91 dB)
RMS power ch3: 3.15% (-30.04 dB)
RMS power ch4: 2.44% (-32.26 dB)
RMS power ch5: 2.43% (-32.28 dB)
------
15.65
And the recodec ones:
2 CH FFMPEG.aac 2 CH MEGUI.aac
------------------- -------------------
RMS power L: 4.45% (-27.03 dB) 3.19% (-29.91 dB)
RMS power R: 3.58% (-28.92 dB) 2.53% (-31.92 dB)
----- -----
8.03 5.72
Min value L: -40.22% (-7.91 dB) -28.36% (-10.95 dB)
Min value R: -26.14% (-11.65 dB) -18.59% (-14.61 dB)
Max value L: 39.02% (-8.17 dB) 27.20% (-11.31 dB)
Max value R: 25.67% (-11.81 dB) 16.95% (-15.42 dB)
The volume of ffmpeg sample is half of original, and the megui sample is the third part of original (like can be expected with 2 speakers instead 6).
But recoding your sample with the same methods than you, instead the original, and cut the first 15 sec.:
ffmpeg_stereo.aac Megui_stereo.m4a
------------------- -------------------
RMS power L: 4.45% (-27.03 dB) 11.11% (-19.09 dB)
RMS power R: 3.58% (-28.93 dB) 8.82% (-21.10 dB)
----- ------
8.03 19.93
Min value L: -28.36% (-10.95 dB) -100.00% (0.00 dB)
Min value R: -18.59% (-14.61 dB) -66.13% (-3.59 dB)
Max value L: 27.20% (-11.31 dB) 97.13% (-0.25 dB)
Max value R: 16.95% (-15.42 dB) 61.68% (-4.20 dB)
The ffmpeg sample have identical volume than before, but the megui-avisynth have bigger volume than original.
The difference is related to Normalize().
Now Normalize amplify the volume to reach the max volume without distort:
Min value L: -28.36% (-10.95 dB) -100.00% (0.00 dB)
But normalizing the full stream reach the max volume at a point not included in the sample and, in the sample, the máx volume value is:
Min value L: -40.22% (-7.91 dB) -28.36% (-10.95 dB)
That means than the ffmpeg downmix have parts with samples clipped.
If you want the same result don't Normalize().
doomleox999
23rd April 2018, 16:03
I didn't normalize and the result is the same. BTW, I noticed in the last log that MeGUI doesn't mention anything about the matrix thing, so maybe it didn't work.
I'm talking about this part in the custom script:
fl_sl = MixAudio(fl, sl, 1.0, 0.707107)
fr_sr = MixAudio(fr, sr, 1.0, 0.707107)
l = MixAudio(fl_sl, fc, 1.0, 0.707107)
r = MixAudio(fr_sr, fc, 1.0, 0.707107)
tebasuna51
23rd April 2018, 20:44
I didn't normalize and the result is the same.
Is not possible, without the Normalize() we must obtain similar values than ffmpeg:
2 CH FFMPEG.aac 2 CH MEGUI_Not-Nor.
------------------- -------------------
RMS power L: 4.45% (-27.03 dB) 4.45% (-27.04 dB)
RMS power R: 3.58% (-28.92 dB) 3.53% (-29.05 dB)
----- -----
8.03 7.98
Min value L: -40.22% (-7.91 dB) -40.70% (-7.81 dB)
Min value R: -26.14% (-11.65 dB) -27.07% (-11.35 dB)
Max value L: 39.02% (-8.17 dB) 38.43% (-8.31 dB)
Max value R: 25.67% (-11.81 dB) 23.76% (-12.48 dB)
BTW, I noticed in the last log that MeGUI doesn't mention anything about the matrix thing, so maybe it didn't work.
Is not showed in the log because MeGUI don't add the downmix, is included in the Import().
If you obtain only two channels the downmix work.
doomleox999
24th April 2018, 19:40
These are the scripts I used and 15 seconds samples of both results:
ClearAutoloadDirs()
AddAutoloadDir("C:\Users\LTX\BACKUP\MeGUI\tools\avs\plugins")
LoadPlugin("C:\Users\LTX\BACKUP\MeGUI\tools\lsmash\LSMASHSource.dll")
a=LWLibavAudioSource("C:\Users\LTX\Desktop\EOE_6CH.mkv")
fl = GetChannel(a, 1)
fr = GetChannel(a, 2)
fc = GetChannel(a, 3)
# lf = GetChannel(a, 4)
sl = GetChannel(a, 5)
sr = GetChannel(a, 6)
fl_sl = MixAudio(fl, sl, 1.0, 0.707107)
fr_sr = MixAudio(fr, sr, 1.0, 0.707107)
l = MixAudio(fl_sl, fc, 1.0, 0.707107)
r = MixAudio(fr_sr, fc, 1.0, 0.707107)
MergeChannels(l, r)
Normalize()
return last
EOE_6CH.aac (https://www.sendspace.com/file/4rocp1)
ClearAutoloadDirs()
AddAutoloadDir("C:\Users\LTX\BACKUP\MeGUI\tools\avs\plugins")
LoadPlugin("C:\Users\LTX\BACKUP\MeGUI\tools\lsmash\LSMASHSource.dll")
a=LWLibavAudioSource("C:\Users\LTX\Desktop\EOE_6CH.mkv")
fl = GetChannel(a, 1)
fr = GetChannel(a, 2)
fc = GetChannel(a, 3)
# lf = GetChannel(a, 4)
sl = GetChannel(a, 5)
sr = GetChannel(a, 6)
fl_sl = MixAudio(fl, sl, 1.0, 0.707107)
fr_sr = MixAudio(fr, sr, 1.0, 0.707107)
l = MixAudio(fl_sl, fc, 1.0, 0.707107)
r = MixAudio(fr_sr, fc, 1.0, 0.707107)
MergeChannels(l, r)
return last
EOE_6CH - NO NORM.aac (https://www.sendspace.com/file/6pvaxl)
tebasuna51
24th April 2018, 21:26
a=LWLibavAudioSource("C:\Users\LTX\Desktop\EOE_6CH.mkv")
You need use:
a=LWLibavAudioSource("6 CH ORIGINAL MKV.aac")
not the full stream and after cut, in order to see the effect of Normalize()
doomleox999
25th April 2018, 03:21
I used the original mkv file, not the 15 seconds sample. You told me that using the mkv or an aac (extracted audio) is the same.
tebasuna51
25th April 2018, 09:18
I used the original mkv file, not the 15 seconds sample. You told me that using the mkv or an aac (extracted audio) is the same.
Yes, but is not the same use the full aac or mkv than use only the first 15 seconds.
Normalize() amplify the source until reach a max value, in the first 15 seconds (100% in my Megui_stereo.m4a), using the full stream the 100% is in another point out of first 15 sec. and can't be amplified more.
hello_hello
30th April 2018, 18:22
I somehow forgot about this thread, but now that I see hello_hellos results I see a system behind it: If ffmpeg downmixes to 32b float, it uses the one set of coefficients, if it downmixes to pcm it uses the other set of coefficients. The most direct way to test this is by not using the aac or libmp3lame encoders, but -c:a pcm_s16le, pcm_s24le, pcm_f32le. And if one does it, the results confirm the preceding statement. The aac encoder probably accepts float input only (or prefers it) so that the auto_resampler resamples everything to float, whereas libmp3lame seems to accept everything so that downmixing in this case only changes the number of channels, not the sample format.
But does anybody have a definitive answer why ffmpeg uses different coefficients for float and non-float? In both cases the ratios coincide: 1/0.707107 and 0.414214/0.292893 are both very good approximations for 2^(0.5) which is probably the value that they are supposed to be. Probably it is because one doesn't need to care about clipping that much if one uses float output.
Personally, I think the way ffmpeg changes the coefficients is somewhat strange. I don't think it's unreasonable to expect the same command line would always produce the same result (aside from the output format).
The coefficients might relate to the ability of the output format/codec to encode peaks above 0dB. I can't speak for ffmpeg's AAC encoder, but QAAC doesn't clip peaks when the input is float. I vaguely remember someone in another forum testing it and QAAC coped with peaks well over 0dB.
I'm not sure about the LAME encoder. The stand-alone version accepts 32 bit float but downsamples to 24 bit integer before encoding, so peaks greater than 0dB would be clipped.
ffmeg's built-in LAME encoder seems to accept 32 bit float though. I've compared it to the standalone LAME, and ffmpeg's LAME encodes peaks above 0dB, at least according to a true peak scan of the encoded audio. Whether those peaks are encoded accurately.... that might be a different story.
hello_hello
30th April 2018, 19:05
doomleox999,
as an alternative you could try downmixing and encoding with foobar2000. I use it for 99.9% of my audio encoding. You can add DSPs to both the playback and conversion chains and conversion configurations can be saved as presets. There's plugins for decoding audio it can't decode "out of the box" (DTS and AC3 are the main examples) and there's even a plugin for decoding Avisynth scripts.
Not that I downmix much these days, but if I downmix and encode a bunch of related files (episodes of a TV show etc) I usually downmix with the matrix mixer DSP (http://skipyrich.com/w/index.php/Foobar2000:Matrix_Mixer) while reducing the over-all volume by 6dB. It's not quite enough to guarantee there won't be clipping, but it's enough most of the time, and that way the relative volumes of each track doesn't change. Once it's encoded, I run a ReplayGain scan on the encoded audio to check the peak levels (I encode with either QAAC or ffmpeg's MP3 encoder so the peaks aren't clipped before encoding). If a track or two has peaks above 0dB I'd probably re-encode them with a limiter DSP in the conversion chain. On the rare occasion there's lots of tracks with peaks above 0dB, I'd decrease the volume of each output file by an appropriate amount (so the relative volumes remain the same). Foobar2000 can losslessly adjust the volume of MP3 and AAC audio in an MP4 or MKV container, or alternatively you could reduce the downmix volume and re-encode them all a second time, which isn't as bad as it sounds as you can encode multiple files simultaneously.
Fb2k comes with it's own downmix DSP but it's not configurable and it doesn't reduce the volume to prevent clipping.
There's a screenshot of the matrix mixer DSP below. The coefficients are specified as a percentage, as they are when downmixing with Avisynth or ffmpeg. This is my standard 5.1ch to stereo downmix preset with an overall 6dB volume reduction. Both the back and side channels need to be included for 5.1ch, as the surround channels can be in either the back or side.
https://s7.postimg.cc/4azs5mn7v/fb2k_mm.gif
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.