PR #23192 opened by Rodeo URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23192 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23192.patch
Parsers and encoders (e.g. AC3, AAC, ALAC) indicate/propagate the bitstream's channel configuration using "standard" layouts in AV_CHANNEL_ORDER_NATIVE but the encoded bitstream's channels are not actually in that order. Don't write a channel layout bitmap or description using a conflicting channel order, as some software will incorrectly override the bitstream-provided information using the chan atom's data instead (e.g. afinfo/afplay for AAC in MOV) Fixes part of #23138 >From 13ffa496b3f2d278a44a2458eda65d8534cfd202 Mon Sep 17 00:00:00 2001 From: Tim Walker <[email protected]> Date: Thu, 21 May 2026 17:44:31 +0200 Subject: [PATCH] avformat/movenc: don't write a 'chan' atom with an incorrect channel bitmap or description. --- libavformat/mov_chan.c | 23 ++++++++++++++++++----- libavformat/movenc.c | 5 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 67b22b048d..a11172ef2e 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -493,11 +493,24 @@ int ff_mov_get_channel_layout_tag(const AVCodecParameters *par, /* if no tag was found, use channel bitmap or description as a backup if possible */ if (tag == 0) { uint32_t *channel_desc; - if (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && - par->ch_layout.u.mask < 0x40000) { - *layout = MOV_CH_LAYOUT_USE_BITMAP; - *bitmap = (uint32_t)par->ch_layout.u.mask; - return 0; + + if (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) { + /* Parsers and encoders (e.g. AC3, AAC, ALAC) indicate/propagate the bitstream's + * channel configuration using "standard" layouts in AV_CHANNEL_ORDER_NATIVE but + * the encoded bitstream's channels are not actually in that order. Don't return + * a channel layout bitmap or description using a conflicting channel order, as + * some software will incorrectly override the bitstream-provided information + * using the chan atom's data instead (e.g. afinfo/afplay for AAC in MOV) */ + if (!layouts || layouts != mov_ch_layouts_wav) { + *layout = MOV_CH_LAYOUT_UNKNOWN; + return 0; + } + + if (par->ch_layout.u.mask < 0x40000) { + *layout = MOV_CH_LAYOUT_USE_BITMAP; + *bitmap = (uint32_t)par->ch_layout.u.mask; + return 0; + } } else if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) return AVERROR(ENOSYS); diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 10ea818dd3..df9988df76 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1017,6 +1017,11 @@ static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra return ret; } + /* no predefined tag found + ch_layout in AV_CHANNEL_ORDER_NATIVE + * but bitstream channels not actually in native order */ + if (layout_tag == MOV_CH_LAYOUT_UNKNOWN) + return 0; + if (layout_tag == MOV_CH_LAYOUT_MONO && track->mono_as_fc > 0) { av_assert0(!channel_desc); channel_desc = av_malloc(sizeof(*channel_desc)); -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
