Skip to content

Loopback route: FLAC 7.1(wide) is served without a channel layout, so its front-of-centre pair plays as the side surrounds #1120

Open

Description

@yazcaleb

What happens

A FLAC track whose channel layout is FFmpeg's 7.1(wide) (FL FR FC LFE BL BR FLC FRC) plays on the loopback route with every sample intact, but the served fMP4 carries no channel layout. AVFoundation then falls back to the default 8-channel order and reads the front-of-centre pair as the side surrounds:

FFmpeg channel Source FLAC as AVFoundation reads it Served fMP4 as AVFoundation reads it
FL, FR, FC, LFE L, R, C, LFE L, R, C, LFE
BL, BR Rls, Rrs Rls, Rrs
FLC, FRC Lc, Rc Ls, Rs

So on a 7.1 system, the content mixed for the front-of-centre speakers plays from the side surrounds. The same happens when DTS-HD Master Audio in that layout goes through the FLAC bridge (audioBridgeMode: .lossless), so it isn't specific to stream copy. A standard 7.1 layout (with sides) and 5.1 come out correctly labelled, because the default order happens to match them.

afinfo on the served stream (init segment plus segments, concatenated) reports:

Data format:     8 ch,  48000 Hz, flac (0x00000003) from 24-bit source, 512 frames/packet
                no channel layout.

afinfo on the source FLAC reports Channel layout: 7.1 (L R C LFE Rls Rrs Lc Rc).

Steps

  1. Make a 7.1(wide) FLAC with a different tone on each channel, and mux it beside a short black picture:

    ffmpeg -f lavfi -i "aevalsrc=0.3*sin(2*PI*220*t)|0.3*sin(2*PI*330*t)|0.3*sin(2*PI*440*t)|0.3*sin(2*PI*55*t)|0.3*sin(2*PI*550*t)|0.3*sin(2*PI*660*t)|0.3*sin(2*PI*770*t)|0.3*sin(2*PI*880*t):c=7.1(wide):s=48000:d=5" -c:a flac -sample_fmt s32 wide.flac
    ffmpeg -f lavfi -i color=black:s=320x180:r=24 -i wide.flac -map 0:v -map 1:a -c:v libx264 -g 24 -pix_fmt yuv420p -c:a copy -shortest wide.mkv
    
  2. Serve it with HLSVideoEngine(url:dvModeAvailable: false, audioBridgeMode: .lossless) and start().

  3. Download the media playlist's EXT-X-MAP and every segment, concatenate them, and read the audio track's CMAudioFormatDescriptionGetChannelLayout (or run afinfo on the file).

Expected: the served layout names the front-of-centre pair, as the source does: L R C LFE Rls Rrs Lc Rc. A chnl box, or a dfLa-side layout AVFoundation reads, would do.
Served: no channel layout, read as L R C LFE Rls Rrs Ls Rs.

The samples themselves are bit-exact against FFmpeg's decode, channel for channel. Only the labels are wrong.

Where seen

AetherEngine 7.71.0 with the TrueHDObjectAudio and DTSXObjectAudio traits, macOS 26.7, Xcode 27.1. Found with FATE's dts/master_audio_7.1_24bit.dts (DTS-HD MA, 7.1(wide)): both its bridged FLAC and a FLAC re-encode of it played through stream copy show the table above. iOS and tvOS weren't checked, but the served init segment is the same.

Activity

  1. added
    area: audio
    bug
    on Nov 23, 2026
  2. superuser404notfound commented on Nov 23, 2026

    @superuser404notfound
    Owner

    Thanks for the clean repro, the tone-per-channel fixture made this quick to pin down.

    What I measured on macOS 27 with CMAudioFormatDescriptionGetChannelLayout: CoreMedia reads no channel layout from a FLAC sample entry at all. I tried a chnl box after dfLa, a QuickTime chan box, and a dfLa that carries a WAVEFORMATEXTENSIBLE_CHANNEL_MASK=0xff Vorbis comment. All three still read as L R C LFE Rls Rrs Ls Rs. Apple's own afconvert -f m4af -d flac drops the layout the same way (it even warns about it). So there is no FLAC-side box to fix. CoreMedia assumes the FLAC default per channel count, and anything else lands on the wrong speakers.

    The bridged DTS case had a second problem on top. The FLAC bridge opened its encoder in the default 7.1 layout, so swr folded FLC/FRC into the fronts before the labels even mattered.

    Fixed on main in d72b39b and dcbaa3b. A layout FLAC cannot label now goes out as 24-bit PCM (ipcm) in the source's own layout. movenc writes that as a chnl box, and CoreMedia does read that one.

    • A FLAC source in such a layout leaves stream copy in either bridge mode.
    • A bridged source (DTS-HD MA, PCM) gets PCM under .lossless. .surroundCompat keeps E-AC-3 5.1.
    • 5.1 with back surrounds, mono and stereo stay on FLAC.

    With your wide.mkv, the served init plus segment now reads L R C LFE Rls Rrs Lc Rc through AVFoundation, the same as the source FLAC. Issue1120FLACChannelLayoutTests pins the per-channel values and the AVFoundation read-back. The cost is bandwidth on the loopback, 9.2 Mbit/s for 48 kHz 7.1.

    It isn't released yet. I'll leave this open until you've had a chance to check it with the FATE DTS-HD MA file.

  3. superuser404notfound commented on Nov 24, 2026

    @superuser404notfound
    Owner

    Released in 7.74.0 (dcbaa3b).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: audiobug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions