PR #26261 opened by Baptiste Coudurier (bcoudurier)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26261
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26261.patch

Stacked on https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26024; only the last two 
commits are new.

- Stream copy now writes the .mp3 sample entry, as HLS already does.
- The MPD declares `mp3` instead of `mp4a.40.34`, which means object type 34. 
HLS keeps `mp4a.40.34`, Apple's string for MP3.

🤖 Generated with [Claude Code](https://claude.com/claude-code)



From 68f532c5254fd03fdd955be541aa14107958a333 Mon Sep 17 00:00:00 2001
From: Baptiste Coudurier <[email protected]>
Date: Sat, 14 Nov 2026 21:11:51 -0800
Subject: [PATCH 1/4] avformat/isom: demux MPEG-4 Audio Layer-1/2 object types
 as mp1/mp2

Their access units are plain frames (ISO/IEC 14496-3 9.4.1), unlike Layer-3.
Also fix the comment of the MP2 0x69 objectTypeIndication.

Signed-off-by: Baptiste Coudurier <[email protected]>
---
 libavformat/isom.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 09be63aa193..8319a49ebf9 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -28,6 +28,7 @@
 #include "libavcodec/mpeg4audio.h"
 #include "libavcodec/mpegaudiodata.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/mem.h"
 
 /* http://www.mp4ra.org */
 /* ordered by muxing preference */
@@ -49,7 +50,7 @@ const AVCodecTag ff_mp4_obj_type[] = {
     { AV_CODEC_ID_AAC         , 0x67 }, /* MPEG-2 AAC Low */
     { AV_CODEC_ID_AAC         , 0x68 }, /* MPEG-2 AAC SSR */
     { AV_CODEC_ID_MP3         , 0x69 }, /* 13818-3 */
-    { AV_CODEC_ID_MP2         , 0x69 }, /* 11172-3 */
+    { AV_CODEC_ID_MP2         , 0x69 }, /* 13818-3 */
     { AV_CODEC_ID_MPEG1VIDEO  , 0x6A }, /* 11172-2 */
     { AV_CODEC_ID_MP3         , 0x6B }, /* 11172-3 */
     { AV_CODEC_ID_MJPEG       , 0x6C }, /* 10918-1 */
@@ -322,9 +323,9 @@ void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
 
 static const AVCodecTag mp4_audio_types[] = {
     { AV_CODEC_ID_MP3ON4, AOT_PS   }, /* old mp3on4 draft */
-    { AV_CODEC_ID_MP3ON4, AOT_L1   }, /* layer 1 */
-    { AV_CODEC_ID_MP3ON4, AOT_L2   }, /* layer 2 */
-    { AV_CODEC_ID_MP3ON4, AOT_L3   }, /* layer 3 */
+    { AV_CODEC_ID_MP1,    AOT_L1   }, /* layer 1, one frame per AU */
+    { AV_CODEC_ID_MP2,    AOT_L2   }, /* layer 2, one frame per AU */
+    { AV_CODEC_ID_MP3ON4, AOT_L3   }, /* layer 3, mp3_channel_elements */
     { AV_CODEC_ID_MP4ALS, AOT_ALS  }, /* MPEG-4 ALS */
     { AV_CODEC_ID_NONE,   AOT_NULL },
 };
@@ -393,6 +394,13 @@ int ff_mp4_read_dec_config_descr(void *logctx, AVStream 
*st, AVIOContext *pb)
             if (!(st->codecpar->codec_id = ff_codec_get_id(mp4_audio_types,
                                                         cfg.object_type)))
                 st->codecpar->codec_id = AV_CODEC_ID_AAC;
+            /* Layer 1/2 access units are plain frames, the AudioSpecificConfig
+             * is not their extradata. */
+            if (st->codecpar->codec_id == AV_CODEC_ID_MP1 ||
+                st->codecpar->codec_id == AV_CODEC_ID_MP2) {
+                av_freep(&st->codecpar->extradata);
+                st->codecpar->extradata_size = 0;
+            }
         }
     }
     return 0;
-- 
2.54.1


From 168258fb1984823e693c8f6968cf1f7ad3f08764 Mon Sep 17 00:00:00 2001
From: Baptiste Coudurier <[email protected]>
Date: Sat, 14 Nov 2026 21:11:52 -0800
Subject: [PATCH 2/4] avformat/movenc: write MP2 and MP3 in mp4 so Apple
 players decode them

MP2 uses MPEG-4 Audio object type 33 with a generated AudioSpecificConfig, MP3 
a .mp3 sample entry.

Signed-off-by: Baptiste Coudurier <[email protected]>
---
 libavformat/Makefile                  |  3 +-
 libavformat/movenc.c                  | 60 +++++++++++++++++++++------
 tests/fate/dashenc.mak                |  4 +-
 tests/fate/mov.mak                    |  9 ++++
 tests/ref/fate/dash-big-init          |  2 +-
 tests/ref/fate/dash-seek-zero         |  2 +-
 tests/ref/fate/generic-tags-remux-mov |  4 +-
 tests/ref/fate/hls-fmp4-big-init      |  2 +-
 tests/ref/fate/mov-mp4-mp2-aot33      | 23 ++++++++++
 tests/ref/fate/mov-mp4-mp3-remux      | 33 +++++++++++++++
 10 files changed, 122 insertions(+), 20 deletions(-)
 create mode 100644 tests/ref/fate/mov-mp4-mp2-aot33
 create mode 100644 tests/ref/fate/mov-mp4-mp3-remux

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 30e3b334411..892bb102b61 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -759,7 +759,8 @@ SHLIBOBJS-$(CONFIG_MATROSKA_DEMUXER)     += 
mpeg4audio_sample_rates.o \
                                             opus_frame_duration_tab.o
 SHLIBOBJS-$(CONFIG_MATROSKA_MUXER)       += opus_frame_duration_tab.o
 SHLIBOBJS-$(CONFIG_MOV_DEMUXER)          += ac3_channel_layout_tab.o
-SHLIBOBJS-$(CONFIG_MOV_MUXER)            += mpegaudiotabs.o
+SHLIBOBJS-$(CONFIG_MOV_MUXER)            += mpeg4audio_sample_rates.o \
+                                            mpegaudiotabs.o
 SHLIBOBJS-$(CONFIG_MP3_MUXER)            += mpegaudiotabs.o
 SHLIBOBJS-$(CONFIG_MXF_MUXER)            += golomb_tab.o \
                                             rangecoder_dec.o
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index e51fd53458b..167fbd1748b 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -43,6 +43,7 @@
 #include "libavcodec/ac3_parser_internal.h"
 #include "libavcodec/dnxhddata.h"
 #include "libavcodec/flac.h"
+#include "libavcodec/mpeg4audio.h"
 #include "libavcodec/mpegaudiodata.h"
 #include "libavcodec/get_bits.h"
 
@@ -810,14 +811,46 @@ static int esds_has_decoder_specific_info(enum AVCodecID 
codec_id)
     }
 }
 
+/* AudioSpecificConfig for Layer-2, ISO/IEC 14496-3 subpart 9 */
+static int mp2_audio_specific_config(uint8_t *buf, int size, MOVTrack *track)
+{
+    const AVCodecParameters *par = track->par;
+    int channels = par->ch_layout.nb_channels;
+    PutBitContext pbc;
+    int sfi;
+
+    for (sfi = 0; sfi < 13; sfi++)
+        if (ff_mpeg4audio_sample_rates[sfi] == par->sample_rate)
+            break;
+
+    init_put_bits(&pbc, buf, size);
+    put_bits(&pbc, 5, AOT_ESCAPE);
+    put_bits(&pbc, 6, AOT_L2 - 32);
+    put_bits(&pbc, 4, sfi < 13 ? sfi : 15);
+    if (sfi == 13)
+        put_bits(&pbc, 24, par->sample_rate);
+    put_bits(&pbc, 4, channels <= 2 ? channels : 0);
+    put_bits(&pbc, 1, 0); // MPEG_1_2_SpecificConfig.extension
+    flush_put_bits(&pbc);
+    return put_bytes_output(&pbc);
+}
+
 static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic
 {
     struct mpeg4_bit_rate_values bit_rates = calculate_mpeg4_bit_rates(track);
     int64_t pos = avio_tell(pb);
-    int write_dsi = track->extradata_size[track->last_stsd_index] &&
-                    esds_has_decoder_specific_info(track->par->codec_id);
-    int decoder_specific_info_len = write_dsi ?
-                                    5 + 
track->extradata_size[track->last_stsd_index] : 0;
+    const uint8_t *dsi = track->extradata[track->last_stsd_index];
+    int dsi_size = track->extradata_size[track->last_stsd_index];
+    uint8_t asc[6];
+    int decoder_specific_info_len;
+
+    if (track->par->codec_id == AV_CODEC_ID_MP2) {
+        dsi      = asc;
+        dsi_size = mp2_audio_specific_config(asc, sizeof(asc), track);
+    } else if (!esds_has_decoder_specific_info(track->par->codec_id)) {
+        dsi_size = 0;
+    }
+    decoder_specific_info_len = dsi_size ? 5 + dsi_size : 0;
 
     avio_wb32(pb, 0); // size
     ffio_wfourcc(pb, "esds");
@@ -832,9 +865,10 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack 
*track) // Basic
     put_descr(pb, 0x04, 13 + decoder_specific_info_len);
 
     // Object type indication
-    if ((track->par->codec_id == AV_CODEC_ID_MP2 ||
-         track->par->codec_id == AV_CODEC_ID_MP3) &&
-        track->par->sample_rate > 24000)
+    if (track->par->codec_id == AV_CODEC_ID_MP2)
+        avio_w8(pb, 0x40); // 14496-3, Layer-2 is signalled in the DSI
+    else if (track->par->codec_id == AV_CODEC_ID_MP3 &&
+             track->par->sample_rate > 24000)
         avio_w8(pb, 0x6B); // 11172-3
     else
         avio_w8(pb, ff_codec_get_tag(ff_mp4_obj_type, track->par->codec_id));
@@ -852,11 +886,10 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack 
*track) // Basic
     avio_wb32(pb, bit_rates.max_bit_rate); // maxbitrate
     avio_wb32(pb, bit_rates.avg_bit_rate);
 
-    if (write_dsi) {
+    if (dsi_size) {
         // DecoderSpecific info descriptor
-        put_descr(pb, 0x05, track->extradata_size[track->last_stsd_index]);
-        avio_write(pb, track->extradata[track->last_stsd_index],
-                   track->extradata_size[track->last_stsd_index]);
+        put_descr(pb, 0x05, dsi_size);
+        avio_write(pb, dsi, dsi_size);
     }
 
     // SL descriptor
@@ -1617,7 +1650,9 @@ static int mov_write_audio_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContex
         if (ret < 0)
             return ret;
         ret = mov_write_pcmc_tag(s, pb, track);
-    } else if (track->extradata_size[track->last_stsd_index] > 0)
+    } else if (track->extradata_size[track->last_stsd_index] > 0 &&
+               track->par->codec_id != AV_CODEC_ID_MP2 &&
+               track->par->codec_id != AV_CODEC_ID_MP3)
         ret = mov_write_glbl_tag(pb, track);
 
     if (ret < 0)
@@ -9625,6 +9660,7 @@ static const AVCodecTag codec_mp4_tags[] = {
     { AV_CODEC_ID_APPLE_APAC,      MKTAG('a', 'p', 'a', 'c') },
     { AV_CODEC_ID_ALAC,            MKTAG('a', 'l', 'a', 'c') },
     { AV_CODEC_ID_MP4ALS,          MKTAG('m', 'p', '4', 'a') },
+    { AV_CODEC_ID_MP3,             MKTAG('.', 'm', 'p', '3') },
     { AV_CODEC_ID_MP3,             MKTAG('m', 'p', '4', 'a') },
     { AV_CODEC_ID_MP2,             MKTAG('m', 'p', '4', 'a') },
     { AV_CODEC_ID_AC3,             MKTAG('a', 'c', '-', '3') },
diff --git a/tests/fate/dashenc.mak b/tests/fate/dashenc.mak
index 0f1cca3341c..a359dfdfd1f 100644
--- a/tests/fate/dashenc.mak
+++ b/tests/fate/dashenc.mak
@@ -38,7 +38,7 @@ tests/data/dash_big_init.mpd: ffmpeg$(PROGSSUF)$(EXESUF) | 
tests/data
        '<SegmentURL media="dash_big_init_0.m4s"/><SegmentURL 
media="dash_big_init_1.m4s"/>' \
        '</SegmentList></Representation></AdaptationSet></Period></MPD>' > $@
 
-FATE_DASHENC_LAVFI-$(call ALLYES, AEVALSRC_FILTER ASPLIT_FILTER 
ARESAMPLE_FILTER MP2FIXED_ENCODER HLS_MUXER MP4_MUXER DASH_DEMUXER MOV_DEMUXER 
MP3_DECODER FILE_PROTOCOL FRAMECRC_MUXER PIPE_PROTOCOL) += fate-dash-big-init
+FATE_DASHENC_LAVFI-$(call ALLYES, AEVALSRC_FILTER ASPLIT_FILTER 
ARESAMPLE_FILTER MP2FIXED_ENCODER HLS_MUXER MP4_MUXER DASH_DEMUXER MOV_DEMUXER 
MP2_DECODER FILE_PROTOCOL FRAMECRC_MUXER PIPE_PROTOCOL) += fate-dash-big-init
 fate-dash-big-init: tests/data/dash_big_init.mpd
 fate-dash-big-init: CLEANFILES = tests/data/dash_big_init.mpd 
tests/data/dash_big_init.m3u8 tests/data/dash_big_init.mp4 
tests/data/dash_big_init_*.m4s
 fate-dash-big-init: CMD = framecrc -i 
$(TARGET_PATH)/tests/data/dash_big_init.mpd -map 0:a:99 -c copy
@@ -50,7 +50,7 @@ tests/data/dash_seek.mpd: ffmpeg$(PROGSSUF)$(EXESUF) | 
tests/data
        -c:a mp2fixed -b:a 8k -bitexact -f dash -seg_duration 1 \
        -init_seg_name dash_seek_init.mp4 -media_seg_name 
'dash_seek_$$Number$$.m4s' $(TARGET_PATH)/$@
 
-FATE_DASHENC_LAVFI-$(call ALLYES, SINE_FILTER ARESAMPLE_FILTER LAVFI_INDEV 
PCM_S16LE_DECODER MP2FIXED_ENCODER DASH_MUXER MP4_MUXER DASH_DEMUXER 
MOV_DEMUXER MP3_DECODER FILE_PROTOCOL FRAMECRC_MUXER PIPE_PROTOCOL) += 
fate-dash-seek-zero fate-dash-seek-reference
+FATE_DASHENC_LAVFI-$(call ALLYES, SINE_FILTER ARESAMPLE_FILTER LAVFI_INDEV 
PCM_S16LE_DECODER MP2FIXED_ENCODER DASH_MUXER MP4_MUXER DASH_DEMUXER 
MOV_DEMUXER MP2_DECODER FILE_PROTOCOL FRAMECRC_MUXER PIPE_PROTOCOL) += 
fate-dash-seek-zero fate-dash-seek-reference
 fate-dash-seek-zero fate-dash-seek-reference: tests/data/dash_seek.mpd
 fate-dash-seek-zero: CMD = framecrc -ss 0 -i 
$(TARGET_PATH)/tests/data/dash_seek.mpd -c copy
 fate-dash-seek-reference: CMD = framecrc -i 
$(TARGET_PATH)/tests/data/dash_seek.mpd -c copy
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index b62aca69885..c693d68f81c 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -435,6 +435,15 @@ fate-mov-dfpwm-last-packet: CMD = transcode lavfi 
"sine=r=48000,atrim=end_sample
 fate-mov-vfr: CMP = oneline
 fate-mov-vfr: REF = 1558b4a9398d8635783c93f84eb5a60d
 
+# MP2 is written as MPEG-4 Audio object type 33 (ISO/IEC 14496-3 subpart 9)
+# and has to demux back as mp2, without the AudioSpecificConfig as extradata.
+FATE_MOV_FFMPEG_FFPROBE-$(call TRANSCODE, MP2, MP4 MOV, LAVFI_INDEV 
SINE_FILTER ATRIM_FILTER ARESAMPLE_FILTER PCM_S16LE_DECODER) += 
fate-mov-mp4-mp2-aot33
+fate-mov-mp4-mp2-aot33: CMD = transcode lavfi 
"sine=r=44100,atrim=end_sample=11520" mp4 "-auto_conversion_filters -c:a mp2" 
"-c copy" "-show_entries 
stream=codec_name,codec_tag_string,sample_rate,channels,extradata_size"
+
+# MP3 is written with a .mp3 sample entry and no esds.
+FATE_MOV_FFMPEG_FFPROBE_SAMPLES-$(call REMUX, MP4 MOV, MP3_DECODER) += 
fate-mov-mp4-mp3-remux
+fate-mov-mp4-mp3-remux: CMD = transcode mov 
$(TARGET_SAMPLES)/mpegaudio/packed_maindata.mp3.mp4 mp4 "-c copy" "-c copy -t 
0.5" "-show_entries 
stream=codec_name,codec_tag_string,sample_rate,channels,extradata_size"
+
 # The QuickTime user data list has to carry the composer atom the demuxer
 # already reads: without it a mov to mov remux dropped the tag.
 FATE_MOV_FFMPEG_FFPROBE-$(call TRANSCODE, PCM_S16LE, MOV, WAV_DEMUXER 
ARESAMPLE_FILTER) += fate-mov-composer-metadata
diff --git a/tests/ref/fate/dash-big-init b/tests/ref/fate/dash-big-init
index 07a81414c69..797bd1edf24 100644
--- a/tests/ref/fate/dash-big-init
+++ b/tests/ref/fate/dash-big-init
@@ -1,6 +1,6 @@
 #tb 0: 1/16000
 #media_type 0: audio
-#codec_id 0: mp3
+#codec_id 0: mp2
 #sample_rate 0: 16000
 #channel_layout_name 0: mono
 0,          0,          0,     1152,       72, 0x40951fab
diff --git a/tests/ref/fate/dash-seek-zero b/tests/ref/fate/dash-seek-zero
index c2190258fd4..f7c6cca940e 100644
--- a/tests/ref/fate/dash-seek-zero
+++ b/tests/ref/fate/dash-seek-zero
@@ -1,6 +1,6 @@
 #tb 0: 1/16000
 #media_type 0: audio
-#codec_id 0: mp3
+#codec_id 0: mp2
 #sample_rate 0: 16000
 #channel_layout_name 0: mono
 0,          0,          0,     1152,       72, 0x76b21f9b
diff --git a/tests/ref/fate/generic-tags-remux-mov 
b/tests/ref/fate/generic-tags-remux-mov
index 9db9db4b4db..ff621e082d6 100644
--- a/tests/ref/fate/generic-tags-remux-mov
+++ b/tests/ref/fate/generic-tags-remux-mov
@@ -1,5 +1,5 @@
-be5e00e4528774f7dc753416db07450a *tests/data/fate/generic-tags-remux-mov.mp4
-18063 tests/data/fate/generic-tags-remux-mov.mp4
+29f781ccaa7a0a7e1b6ac798dac8493a *tests/data/fate/generic-tags-remux-mov.mp4
+18019 tests/data/fate/generic-tags-remux-mov.mp4
 #tb 0: 1/44100
 #media_type 0: audio
 #codec_id 0: mp3
diff --git a/tests/ref/fate/hls-fmp4-big-init b/tests/ref/fate/hls-fmp4-big-init
index 07a81414c69..797bd1edf24 100644
--- a/tests/ref/fate/hls-fmp4-big-init
+++ b/tests/ref/fate/hls-fmp4-big-init
@@ -1,6 +1,6 @@
 #tb 0: 1/16000
 #media_type 0: audio
-#codec_id 0: mp3
+#codec_id 0: mp2
 #sample_rate 0: 16000
 #channel_layout_name 0: mono
 0,          0,          0,     1152,       72, 0x40951fab
diff --git a/tests/ref/fate/mov-mp4-mp2-aot33 b/tests/ref/fate/mov-mp4-mp2-aot33
new file mode 100644
index 00000000000..4bf1ca10001
--- /dev/null
+++ b/tests/ref/fate/mov-mp4-mp2-aot33
@@ -0,0 +1,23 @@
+d2e3b37bd117d5eedbfdd86565ef2dd4 *tests/data/fate/mov-mp4-mp2-aot33.mp4
+13304 tests/data/fate/mov-mp4-mp2-aot33.mp4
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: mp2
+#sample_rate 0: 44100
+#channel_layout_name 0: mono
+0,       -481,       -481,     1152,     1253, 0x5c89ebe2, S=1, Skip Samples,  
     10, 0x08d300e2
+0,        671,        671,     1152,     1254, 0x441e219e
+0,       1823,       1823,     1152,     1254, 0xbc8ed1b7
+0,       2975,       2975,     1152,     1254, 0xcf6eda5f
+0,       4127,       4127,     1152,     1254, 0x880ff8dc
+0,       5279,       5279,     1152,     1254, 0x2827edb9
+0,       6431,       6431,     1152,     1254, 0xb3dfbaae
+0,       7583,       7583,     1152,     1254, 0x0053dc95
+0,       8735,       8735,     1152,     1253, 0x37d4ed14
+0,       9887,       9887,     1152,     1254, 0xb106f757
+[STREAM]
+codec_name=mp2
+codec_tag_string=mp4a
+sample_rate=44100
+channels=1
+[/STREAM]
diff --git a/tests/ref/fate/mov-mp4-mp3-remux b/tests/ref/fate/mov-mp4-mp3-remux
new file mode 100644
index 00000000000..a5841f1f69e
--- /dev/null
+++ b/tests/ref/fate/mov-mp4-mp3-remux
@@ -0,0 +1,33 @@
+ede80152702d5101e73085560b20cd9e *tests/data/fate/mov-mp4-mp3-remux.mp4
+144788 tests/data/fate/mov-mp4-mp3-remux.mp4
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: mp3
+#sample_rate 0: 44100
+#channel_layout_name 0: stereo
+0,          0,          0,     1152,       36, 0x8e260589
+0,       1152,       1152,     1152,       36, 0x8e260589
+0,       2304,       2304,     1152,       36, 0x8e260589
+0,       3456,       3456,     1152,       36, 0x8e260589
+0,       4608,       4608,     1152,       36, 0x8e260589
+0,       5760,       5760,     1152,       36, 0x8e260589
+0,       6912,       6912,     1152,       69, 0xdb550f09
+0,       8064,       8064,     1152,      104, 0xbaeb1aa8
+0,       9216,       9216,     1152,      104, 0xbaeb1aa8
+0,      10368,      10368,     1152,      104, 0xbaeb1aa8
+0,      11520,      11520,     1152,      104, 0xbaeb1aa8
+0,      12672,      12672,     1152,      104, 0xbaeb1aa8
+0,      13824,      13824,     1152,      104, 0xbaeb1aa8
+0,      14976,      14976,     1152,       36, 0x8e260589
+0,      16128,      16128,     1152,      601, 0xc34f1dc9
+0,      17280,      17280,     1152,      716, 0x6c2665e5
+0,      18432,      18432,     1152,      672, 0xf9873f4b
+0,      19584,      19584,     1152,      631, 0xd13333cc
+0,      20736,      20736,     1152,      604, 0xc0bb13e5
+0,      21888,      21888,     1152,      642, 0x4e873319
+[STREAM]
+codec_name=mp3
+codec_tag_string=.mp3
+sample_rate=44100
+channels=2
+[/STREAM]
-- 
2.54.1


From 2c9a40bead6ef52baf67390fad502c911bf199bc Mon Sep 17 00:00:00 2001
From: Baptiste Coudurier <[email protected]>
Date: Sat, 21 Nov 2026 12:12:53 -0800
Subject: [PATCH 3/4] avformat/dashenc: drop copied codec tags that map to
 another codec

As hlsenc does, so MP3 copied from mp4a gets the .mp3 sample entry.

Signed-off-by: Baptiste Coudurier <[email protected]>
---
 libavformat/dashenc.c        |  4 ++++
 tests/fate/dashenc.mak       | 13 ++++++++++++-
 tests/ref/fate/dash-mp3-copy |  2 ++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/fate/dash-mp3-copy

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 219b200d585..b63c65d5682 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1414,6 +1414,10 @@ static int dash_init(AVFormatContext *s)
         if (!(st = avformat_new_stream(ctx, NULL)))
             return AVERROR(ENOMEM);
         avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar);
+        if (ctx->oformat->codec_tag &&
+            av_codec_get_id (ctx->oformat->codec_tag, st->codecpar->codec_tag) 
!= st->codecpar->codec_id &&
+            av_codec_get_tag(ctx->oformat->codec_tag, st->codecpar->codec_id) 
> 0)
+            st->codecpar->codec_tag = 0;
         st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
         st->time_base = s->streams[i]->time_base;
         st->avg_frame_rate = s->streams[i]->avg_frame_rate;
diff --git a/tests/fate/dashenc.mak b/tests/fate/dashenc.mak
index a359dfdfd1f..70f4d71ec5a 100644
--- a/tests/fate/dashenc.mak
+++ b/tests/fate/dashenc.mak
@@ -56,5 +56,16 @@ fate-dash-seek-zero: CMD = framecrc -ss 0 -i 
$(TARGET_PATH)/tests/data/dash_seek
 fate-dash-seek-reference: CMD = framecrc -i 
$(TARGET_PATH)/tests/data/dash_seek.mpd -c copy
 fate-dash-seek-reference: REF = $(SRC_PATH)/tests/ref/fate/dash-seek-zero
 
+# MP3 copied from mp4a has to get the .mp3 sample entry.
+FATE_DASHENC_FFPROBE_SAMPLES-$(call REMUX, DASH MOV, MP4_MUXER) += 
fate-dash-mp3-copy
+fate-dash-mp3-copy: CLEANFILES = tests/data/fate/dash-mp3-copy*
+fate-dash-mp3-copy: CMD = ffmpeg -i 
$(TARGET_SAMPLES)/mpegaudio/packed_maindata.mp3.mp4 -c copy -f dash \
+       -init_seg_name dash-mp3-copy-init.mp4 -media_seg_name 
dash-mp3-copy-\$$Number\$$.m4s \
+       $(TARGET_PATH)/tests/data/fate/dash-mp3-copy.mpd && \
+       sed -n "s/.*\(codecs=[^ >]*\).*/\1/p" 
$(TARGET_PATH)/tests/data/fate/dash-mp3-copy.mpd && \
+       run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=codec_name,codec_tag_string -of compact \
+       $(TARGET_PATH)/tests/data/fate/dash-mp3-copy-init.mp4
+
 FATE_FFMPEG += $(FATE_DASHENC_LAVFI-yes)
-fate-dashenc: $(FATE_DASHENC_LAVFI-yes)
+FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_DASHENC_FFPROBE_SAMPLES-yes)
+fate-dashenc: $(FATE_DASHENC_LAVFI-yes) $(FATE_DASHENC_FFPROBE_SAMPLES-yes)
diff --git a/tests/ref/fate/dash-mp3-copy b/tests/ref/fate/dash-mp3-copy
new file mode 100644
index 00000000000..5a9613069e4
--- /dev/null
+++ b/tests/ref/fate/dash-mp3-copy
@@ -0,0 +1,2 @@
+codecs="mp4a.40.34"
+stream|codec_name=mp3|codec_tag_string=.mp3
-- 
2.54.1


From 09d71f6f1d12a225813e5616f1dd273cf8d5b8f4 Mon Sep 17 00:00:00 2001
From: Baptiste Coudurier <[email protected]>
Date: Sat, 21 Nov 2026 12:13:22 -0800
Subject: [PATCH 4/4] avformat/dashenc: declare mp3 for the .mp3 sample entry

mp4a.40.34 is MPEG-4 Audio object type 34, which this entry does not carry.

Signed-off-by: Baptiste Coudurier <[email protected]>
---
 libavformat/dashenc.c        | 6 +++++-
 tests/fate/dashenc.mak       | 3 ++-
 tests/ref/fate/dash-mp3-copy | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index b63c65d5682..97fcecfee1c 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1572,7 +1572,11 @@ static int dash_init(AVFormatContext *s)
         }
 
         av_bprint_init_for_buffer(&buffer, os->codec_str, 
sizeof(os->codec_str));
-        ff_make_codec_str(s, st->codecpar, &st->avg_frame_rate, &buffer);
+        // mp4a.40.34 would declare mp3_channel_elements, name the sample entry
+        if (st->codecpar->codec_tag == MKTAG('.','m','p','3'))
+            av_bprintf(&buffer, "mp3");
+        else
+            ff_make_codec_str(s, st->codecpar, &st->avg_frame_rate, &buffer);
         os->first_pts = AV_NOPTS_VALUE;
         os->max_pts = AV_NOPTS_VALUE;
         os->last_dts = AV_NOPTS_VALUE;
diff --git a/tests/fate/dashenc.mak b/tests/fate/dashenc.mak
index 70f4d71ec5a..6725c9bb3f7 100644
--- a/tests/fate/dashenc.mak
+++ b/tests/fate/dashenc.mak
@@ -56,7 +56,8 @@ fate-dash-seek-zero: CMD = framecrc -ss 0 -i 
$(TARGET_PATH)/tests/data/dash_seek
 fate-dash-seek-reference: CMD = framecrc -i 
$(TARGET_PATH)/tests/data/dash_seek.mpd -c copy
 fate-dash-seek-reference: REF = $(SRC_PATH)/tests/ref/fate/dash-seek-zero
 
-# MP3 copied from mp4a has to get the .mp3 sample entry.
+# MP3 copied from mp4a has to get the .mp3 sample entry, and the manifest
+# has to name it rather than declare mp4a.40.34.
 FATE_DASHENC_FFPROBE_SAMPLES-$(call REMUX, DASH MOV, MP4_MUXER) += 
fate-dash-mp3-copy
 fate-dash-mp3-copy: CLEANFILES = tests/data/fate/dash-mp3-copy*
 fate-dash-mp3-copy: CMD = ffmpeg -i 
$(TARGET_SAMPLES)/mpegaudio/packed_maindata.mp3.mp4 -c copy -f dash \
diff --git a/tests/ref/fate/dash-mp3-copy b/tests/ref/fate/dash-mp3-copy
index 5a9613069e4..af4f3057585 100644
--- a/tests/ref/fate/dash-mp3-copy
+++ b/tests/ref/fate/dash-mp3-copy
@@ -1,2 +1,2 @@
-codecs="mp4a.40.34"
+codecs="mp3"
 stream|codec_name=mp3|codec_tag_string=.mp3
-- 
2.54.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to