VideoHelp Forum




+ Reply to Thread
Page 2 of 2
FirstFirst 1 2
Results 31 to 45 of 45
  1. Originally Posted by overlookmotel View Post
    Horace did you ever get to the bottom of this? I'm having exactly the same problem, with a 5.1 MOV file created in FFMPEG playing back in VLC with the centre channel coming through the left speaker only. (this is with VLC downmixing the 5.1 to stereo - I only have 2 speakers).
    In Horace's case the problem was re-mapping the channels when they didn't need remapping.

    Originally Posted by overlookmotel View Post
    I've tried setting FFMPEG's output layout to 5.1 and 5.1(side) and it makes no difference. In VLC it plays back with the centre channel being played through left only.
    Here's my FFMPEG command:
    ffmpeg -i input.mov -filter_complex "[0:1]pan=FL|c0=c0[ch0];[0:1]pan=FR|c0=c1[ch1];[0:2]pan=FC|c0=c0[ch2];[0:2]pan=LFE|c0=c1[ch3];[0:3]pan=SL|c0=c0[ch4];[0:3]pan=SR|c0=c1[ch5];[ch0][ch1][ch2][ch3][ch4][ch5]amerge=inputs=6[aout]" -c:v copy -c:a pcm_s16le -map 0:0 -map [aout] output.mov
    # NB stream 0 is video, streams 1-3 the 3 x stereo audio streams
    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

    Click image for larger version

Name:	ffmpeg.gif
Views:	1210
Size:	18.8 KB
ID:	36970

    Originally Posted by overlookmotel View Post
    Cornucopia mentioned earlier in this thread that "MOV container (and by extension, MP4) has NAMED channels and so will tell you exactly how (in what order) those channels are listed, whether using industry convention order (SMPTE/AES/EBU) or not. Unless I'm mistaken, for those formats, the order does not matter, as they are retrieved by name, not number."
    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.

    Name:  foobar.gif
Views: 2204
Size:  5.7 KB
    Last edited by hello_hello; 10th May 2016 at 21:15.
    Quote Quote  
  2. Member
    Join Date
    Aug 2018
    Location
    Wrocław
    Search PM
    Originally Posted by hello_hello View Post
    ffmpeg decodes the following by mapping the surround channels to the back channels in wave file format. ie L, R, C, LFE, BL, BR
    AAC (M4A) - (FDKAAC, ffmpeg's AAC, NeroAAC, FhGAAC, QAAC)
    Apple Lossless (M4A)
    Opus
    Ogg
    WMA 9.2 (WMAEncode)
    WMA 10 (WMAEncode)
    ffmpeg decodes the following by mapping the surround channels to the side channels in wave file format ie L, R, C, LFE, SL, SR
    AC3
    DTS
    ffmpeg decodes the following by mapping the surround channels to the channels specified in the file (back or side)
    FLAC
    Wave
    Wavepack
    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.
    Quote Quote  
  3. Member
    Join Date
    Aug 2018
    Location
    Wrocław
    Search PM
    I added the following to the ffmpeg command line:

    -channel_layout "5.1"

    but instead of the expected "L R C LFE Ls Rs" I now have "C L R Ls Rs LFE". So it's worse than before. Do you have any advice?
    Quote Quote  
  4. 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)
    Without -channel_layout "5.1" in the command line:

    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)
    I don't know why ffmpeg seems to change the encoded channel order for 5.1ch (side), or why MediaInfo interprets it as L R C Cb Lb Rb. As I said, foobar2000 (and therefore ffmpeg) decodes it correctly.
    Last edited by hello_hello; 2nd Sep 2025 at 11:36.
    Quote Quote  
  5. Member
    Join Date
    Aug 2018
    Location
    Wrocław
    Search PM
    Originally Posted by rgr View Post
    I added the following to the ffmpeg command line:

    -channel_layout "5.1"

    but instead of the expected "L R C LFE Ls Rs" I now have "C L R Ls Rs LFE". So it's worse than before. Do you have any advice?
    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?
    Quote Quote  
  6. 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.

    Image
    [Attachment 88512 - Click to enlarge]


    Try this (Surround = side. Rear surround = back).
    Image Attached Files
    Quote Quote  
  7. Member
    Join Date
    Aug 2018
    Location
    Wrocław
    Search PM
    Originally Posted by hello_hello View Post
    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
    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).
    So by default it should be encoded correctly and played correctly? Only internally the order will be inconsistent with the recommendations?

    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.
    But in the foobar on the oscillator, I saw that the channel order hadn't changed. Center in 3rd position, LFE in 4th.
    Last edited by rgr; 3rd Sep 2025 at 04:46.
    Quote Quote  
  8. Member
    Join Date
    Aug 2018
    Location
    Wrocław
    Search PM
    Originally Posted by hello_hello View Post
    MediaInfo displays the encoded channel order these days, rather than the decoded channel order.
    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)".
    Quote Quote  
  9. Member
    Join Date
    Aug 2018
    Location
    Wrocław
    Search PM
    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 see the ticket is still open. But the comments were helpful -- channel_layout "5.1" is recommended.
    Quote Quote  
  10. 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.
    Quote Quote  
  11. Originally Posted by hello_hello View Post
    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.

    Image
    [Attachment 88512 - Click to enlarge]

    @ 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.
    Quote Quote  
  12. 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

    Image
    [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.

    Image
    [Attachment 88544 - Click to enlarge]
    Quote Quote  
  13. 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
    It still displays an odd layout for AAC 5.1ch (Side) encoded by ffmpeg though.

    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
    Quote Quote  
  14. @ 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.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!