In Horace's case the problem was re-mapping the channels when they didn't need remapping.
If this helps at all, as an experiment I created 3 wave files. The first Front left/right, the second Centre and LFE, and the third, Surround left/right. I muxed them as an MKA in that order and then used this command line to output an MKA containing a single 5.1ch PCM audio stream with the channels in the correct order.
ffmpeg -i 3.mka -filter_complex amerge=inputs=3 -c:a pcm_s16le output.mka
I'll go on the record as still not agreeing with that one.
For playback of multi-channel files, it might help to use a player that visually shows what's happening in each channel (given you're listening in stereo as I am). If you're using Windows, ffdshow displays the individual channel volumes in it's volume filter, or foobar2000's output meter adapts according to the number of channels being decoded and their layout. It can help to at least see where stuff is when it's not where it's supposed to be.
![]()
+ Reply to Thread
Results 31 to 45 of 45
-
Last edited by hello_hello; 10th May 2016 at 21:15.
-
Helpful post.
I have an MKV file with AC3-5.1 audio (layout: Channel layout: L R C LFE Ls Rs). When I run it through an AviSynth script, ffmpeg recognizes it as 5.1(side), but the layout in the outputted MP4 (encoder AAC) file is "Channel layout: L R C Cb Lb Rb".
Is this 100% correct?
I think if ffmpeg recognized the audio as 5.1(side), it should be "Ls Rs." The LFE channel is also labeled Cb, not LFE.Last edited by rgr; 2nd Sep 2025 at 03:43.
-
Different codecs use different channel orders for encoding, but they're decoded and remapped to the wave file channel order. MediaInfo displays the encoded channel order these days, rather than the decoded channel order.
L R C LFE Ls Rs
is the correct encoding order for 5.1ch AC3, where "s" is "surround".
C L R Ls Rs LFE
is the correct encoding order for 5.1ch AAC, where once again "s" is "surround" unless there's a PCE (program configuration element) specifying the channels. The AAC spec says encoding should start with the front centre channel, if it exists, encode the stereo channels in pairs from front to back and end with the back centre channel, if there is one. LFE is a "special" type of channel, encoded individually.
For 5.1ch AAC, ffmpeg uses PCE's to encode it as 5.1ch (side) by default (according to the ffmpeg log file), but from what I've been able to tell it doesn't follow the AAC spec for the encoded channel order, and as a result MediaInfo seems to be interpreting it as L R C Cb Lb Rb. Despite that, foobar2000 decodes it correctly as FL FR, C, LFE, BL BR (in wave file channel order).
When you add -channel_layout "5.1" to the command line, ffmpeg doesn't use PCE's to specify the channel layout, but it seems to be encoded in the correct order according to the AAC spec, so it's always decoded correctly.
There's an old thread on the topic here.
https://forum.videohelp.com/threads/401826-FFMPEG-changing-audio-channel-position#post2621729
Or try a google search using "L R C Cb Lb Rb".
Drilling down with MediaInfo's debug mode, this is what I'd expect to see (and do see when -channel_layout "5.1" is used).
It's also what you'd see when encoding 5.1ch audio with QAAC.
Code:000000B8 raw_data_block (923 bytes) 000000B8 SCE - single_channel_element (93 bytes) 000000B8 id_syn_ele: 0 (0x0) - (3 bits) - SCE - single_channel_element 000000B9 CPE - channel_pair_element (521 bytes) 00000115 id_syn_ele: 1 (0x1) - (3 bits) - CPE - channel_pair_element 000000B8 CPE - channel_pair_element (918 bytes) 000002C2 id_syn_ele: 1 (0x1) - (3 bits) - CPE - channel_pair_element 000000BE LFE - lfe_channel_element (915 bytes) 0000044E id_syn_ele: 3 (0x3) - (3 bits) - LFE - lfe_channel_element 000000B9 END - End (921 bytes) 00000451 id_syn_ele: 7 (0x7) - (3 bits) - END - End 00000452 byte_alignment: 0 (0x0) - (6 bits)
Code:000003CC raw_data_block (834 bytes) 000003CC CPE - channel_pair_element (261 bytes) 000003CC id_syn_ele: 1 (0x1) - (3 bits) - CPE - channel_pair_element 000003CF SCE - single_channel_element (556 bytes) 000004D1 id_syn_ele: 0 (0x0) - (3 bits) - SCE - single_channel_element 000003CC SCE - single_channel_element (562 bytes) 000005FB id_syn_ele: 0 (0x0) - (3 bits) - SCE - single_channel_element 000003CF CPE - channel_pair_element (830 bytes) 000005FE id_syn_ele: 1 (0x1) - (3 bits) - CPE - channel_pair_element 000003CC END - End (833 bytes) 0000070D id_syn_ele: 7 (0x7) - (3 bits) - END - End 0000070D byte_alignment: 0 (0x0) - (5 bits)
Last edited by hello_hello; 2nd Sep 2025 at 11:36.
Avisynth functions Resize8 Mod - Audio Speed/Meter/Wave - FixBlend.zip - Position.zip
Avisynth/VapourSynth functions CropResize - FrostyBorders - CPreview (Cropping Preview) -
This topic may have some more information:
https://forum.videohelp.com/threads/393684-Converting-to-AAC-5-1-7-1-with-ffmpeg-chang...channel-layout -
OK, after reading the manual, I see that the "C L R Ls Rs LFE" layout is correct for AAC5.1. However, in foobar I see that the channel order doesn't change -- LFE is still in 4th position instead of 6th. Doesn't ffmpeg do the channel swapping automatically? Do I have to change it manually?
-
foobar2000's output meter always displays the decoded audio in the wave file channel order, not necessarily the channel order the codec used to encode it.
[Attachment 88512 - Click to enlarge]
Try this (Surround = side. Rear surround = back).Avisynth functions Resize8 Mod - Audio Speed/Meter/Wave - FixBlend.zip - Position.zip
Avisynth/VapourSynth functions CropResize - FrostyBorders - CPreview (Cropping Preview) -
Yes, I figured it out. OK.
For 5.1ch AAC, ffmpeg uses PCE's to encode it as 5.1ch (side) by default (according to the ffmpeg log file), but from what I've been able to tell it doesn't follow the AAC spec for the encoded channel order, and as a result MediaInfo seems to be interpreting it as L R C Cb Lb Rb. Despite that, foobar2000 decodes it correctly as FL FR, C, LFE, BL BR (in wave file channel order).
When you add -channel_layout "5.1" to the command line, ffmpeg doesn't use PCE's to specify the channel layout, but it seems to be encoded in the correct order according to the AAC spec, so it's always decoded correctly.Last edited by rgr; 3rd Sep 2025 at 04:46.
-
a) encoded mp4 without -channel-layout
MediaInfo: L R C Cb Lb Rb
Foobar: FL FR FC LFE BL BR (matches what I see on the oscilloscope -- center 3rd from the top, LFE 4th from the top)
b) encoded mp4 WITH -channel-layout "5.1"
MediaInfo: C L R Ls Rs LFE (looks perfect for AAC 5.1)
Foobar: still FL FR FC LFE BL BR (matches what I see on the oscilloscope)
c) encoded mp4 WITH -channel-layout "5.1(side)"
MediaInfo: L R C Cb Lb Rb
Foobar: still FL FR FC LFE BL BR (matches what I see on the oscilloscope)
So Foobar will always show the channel order on the oscillator according to WAV? So if I always have the same order, does this mean that regardless of whether I use -channel_layout "5.1" / "5.1(side)" or not, the encoding is correct?
-channel_layout "5.1" seems to be the best option, as MediaInfo shows the correct order for AAC5.1. However, the source MKV is "5.1(side)". -
I've added a ticket to the ffmpeg bug tracker regarding this issue, It's here.
https://trac.ffmpeg.org/ticket/7384#comment:14 -
I'm only guessing about ffmpeg 5.1ch (side) not using the standard AAC channel order for encoding, based on what I see using MediaInfo in debug mode, but yes it does seem to change the encoding order. It uses PCEs to specify the channel layout though, so it should still be decoded correctly.
Because there's no such thing as "surround" channels in the wave file channel layout, I think originally the back channels were used as surround when they're decoded, as "back" comes directly after LFE in the wave file channel order. That was before 7.1ch was a thing though. It added the extra surround channels to the rear, so for consistency it's becoming standard practice to decode the 5.1ch surround channels as "side". According to the "Use legacy 5.1ch layout" option in LAV filters, "back" as surround for 5.1ch is the legacy format.
Having said that though, QAAC expects the input surround channels to be the back channels by default. https://github.com/nu774/qaac/wiki/Multichannel--handling
Why, when 5.1ch AAC is encoded as "side" by ffmpeg, it's decoded as "back" by foobar2000, I do not know, but as foobar2000 uses ffmpeg to decode, it probably means ffmpeg decodes it that way. And I assume unless the 5.1ch AAC has a PCE to specify the side channels as surround, its up to the decoder to decide how those surround channels should be decoded, in respect to whether they're decoded as back or side channels.
As a quick experiment I encoded a 5.1ch AC3 file, which fb2k decodes as side, as a wave file and the wave file used the side channels for surround. When I re-encoded the wave file as AAC with QAAC, the surround channels become "back". When I encoded it as flac with flac.exe it was encoded using the side channels, but when I encoded it as flac with ffmpeg (using fb2k) the flac file was decoded with the back channels as surround.
I'm not sure why there's an inconsistency but I don't think it matters. Lossy encoders will accept either the side or back channels as surround when encoding 5.1ch, so it probably doesn't matter much which way those surround channels are decoded.Last edited by hello_hello; 3rd Sep 2025 at 13:13.
Avisynth functions Resize8 Mod - Audio Speed/Meter/Wave - FixBlend.zip - Position.zip
Avisynth/VapourSynth functions CropResize - FrostyBorders - CPreview (Cropping Preview) -
@ hello_hello
I do not have foobar2000's output meter.
At least I do not have anything like the picture you posted.
My version is not too old but not the latest version. -
The screenshot above is actually taken from the top of the Matrix Mixer DSP window, simply to show the wave file channel order.
It's been abandoned by the author and it's not listed on the fb2k website for some reason, but for 32 bit fb2k it still works fine. It's handy if you want to downmix or remap channels or adjust channel volumes etc.
https://www.softpedia.com/get/Multimedia/Audio/Audio-Plugins/foo-dsp-mm.shtml
[Attachment 88545 - Click to enlarge]
It was the Peak Meter UI element that I posted a screenshot of much earlier in this thread. You can add it as an element to the GUI in layout editing mode. I've added it twice. A small version under one tab, and a larger version under another for when I want to view the channel layout. Alternatively you can enable it separately via the "View/Visualisations/Peak Meter" menu. You can also right click on it somewhere to run it in full screen mode.
[Attachment 88544 - Click to enlarge]Avisynth functions Resize8 Mod - Audio Speed/Meter/Wave - FixBlend.zip - Position.zip
Avisynth/VapourSynth functions CropResize - FrostyBorders - CPreview (Cropping Preview) -
I just realised MediaInfo's debug mode displays both the encoded channel order, and the channels to which it thinks (I assume) the audio should be decoded.
Code:Channel(s) : 6 Channel(s) : 6 channels Channel positions : Front: L C R, Side: L R, LFE Channel positions : 3/2/0.1 Channel layout : C L R Ls Rs LFE
Code:Channel(s) : 6 Channel(s) : 6 channels Channel positions : Front: L C R, Side: C, Back: L R Channel positions : 3/1/2 Channel layout : L R C Cb Lb Rb
Avisynth functions Resize8 Mod - Audio Speed/Meter/Wave - FixBlend.zip - Position.zip
Avisynth/VapourSynth functions CropResize - FrostyBorders - CPreview (Cropping Preview) -
@ hello_hello,
Is there an easy way to enable Matrix Mixer in foobar2000 ?
Like adding it to the View/DSP list.
The only way I found was to go to File/Preferences/Playback/DSP Manager then double click on Matrix Mixer in the Active DSP's window.
Similar Threads
-
FFMpeg and channel layout
By alexander121 in forum AudioReplies: 4Last Post: 22nd Mar 2015, 02:27 -
converting 6 channel audio to 2 channel & putting 2 streams in a container
By qorda in forum AudioReplies: 3Last Post: 14th Jan 2014, 02:43 -
ffmpeg, audio filtering how to set the layout ?
By Selur in forum AudioReplies: 0Last Post: 11th Dec 2013, 08:57 -
Layout of mediainfo
By pooksahib in forum Newbie / General discussionsReplies: 4Last Post: 27th Feb 2012, 09:30 -
ffmpeg error when encoding 6 channel aac
By BrianAtVH in forum AudioReplies: 5Last Post: 14th Feb 2012, 14:52