PR #23318 opened by Rodeo URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23318 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23318.patch
Move writing of the CHAN chunk to after the COMM chunk due to channel count only being available from the latter. Other tools (e.g. afconvert) already write COMM before CHAN (see AIFF-tags-COMM-CHAN-FLLR-SSND.aif). ff_mov_read_chan (used by aiffdec) needs the channel count to validate the number of channel descriptions and will error out if channel descriptions are found but the channel count is zero (which it is before the COMM chunk has been parsed). aiffenc does not write CHAN chunks with channel descriptions but if it were to do so, then without this change, aiffdec would then be unable to successfully parse the CHAN. Changes fate-id3v2-utf16-bom >From 564b56ccd075377be12da0ca25e6b27e36de11a4 Mon Sep 17 00:00:00 2001 From: Tim Walker <[email protected]> Date: Wed, 3 Jun 2026 01:39:29 +0200 Subject: [PATCH] avformat/aiffenc: write CHAN chunk after COMM COMM is where the channel count is indicated Channel count can be useful when parsing the CHAN chunk --- libavformat/aiffenc.c | 14 ++++++++------ tests/ref/fate/id3v2-utf16-bom | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index 2cd1119409..db65c09f11 100644 --- a/libavformat/aiffenc.c +++ b/libavformat/aiffenc.c @@ -147,12 +147,6 @@ static int aiff_write_header(AVFormatContext *s) avio_wb32(pb, 0xA2805140); } - if (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && par->ch_layout.nb_channels > 2) { - ffio_wfourcc(pb, "CHAN"); - avio_wb32(pb, 12); - ff_mov_write_chan(pb, par->ch_layout.u.mask); - } - put_meta(s, "title", MKBETAG('N', 'A', 'M', 'E')); put_meta(s, "author", MKBETAG('A', 'U', 'T', 'H')); put_meta(s, "copyright", MKBETAG('(', 'c', ')', ' ')); @@ -193,6 +187,14 @@ static int aiff_write_header(AVFormatContext *s) avio_write(pb, par->extradata, par->extradata_size); } + /* CHAN chunk; a decoder may use the channel count when parsing this chunk, + * so let's write it after the COMM chunk which indicates said channel count. */ + if (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && par->ch_layout.nb_channels > 2) { + ffio_wfourcc(pb, "CHAN"); + avio_wb32(pb, 12); + ff_mov_write_chan(pb, par->ch_layout.u.mask); + } + /* Sound data chunk */ ffio_wfourcc(pb, "SSND"); aiff->ssnd = avio_tell(pb); /* Sound chunk size */ diff --git a/tests/ref/fate/id3v2-utf16-bom b/tests/ref/fate/id3v2-utf16-bom index 99d1bd064d..99e54deef6 100644 --- a/tests/ref/fate/id3v2-utf16-bom +++ b/tests/ref/fate/id3v2-utf16-bom @@ -1,4 +1,4 @@ -9b8bfdf87a8d3d089819ef9f6f264ec4 *tests/data/fate/id3v2-utf16-bom.aiff +8e292c72670bc4b09b05b2eb11edfa70 *tests/data/fate/id3v2-utf16-bom.aiff 885482 tests/data/fate/id3v2-utf16-bom.aiff #tb 0: 1/90000 #media_type 0: video -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
