Commit 2187fdc1c4 for ffmpeg
commit 2187fdc1c46f97d599180c012d83d05d5727168d
Author: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Date: Sat Nov 14 21:11:51 2026 -0800
avformat/isom: demux MPEG-4 Audio Layer I and II
These access units contain plain MPEG audio frames. Set the frame size
from the codec ID and discard the AudioSpecificConfig.
Signed-off-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Fairy
diff --git a/libavformat/isom.c b/libavformat/isom.c
index 3544f0dfec..e487911361 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -29,6 +29,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 */
@@ -50,7 +51,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 */
@@ -323,9 +324,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 },
};
@@ -374,6 +375,9 @@ int ff_mp4_read_dec_config_descr(void *logctx, AVStream *st, AVIOContext *pb)
st->codecpar->sample_rate = cfg.ext_sample_rate;
else
st->codecpar->sample_rate = cfg.sample_rate;
+ if (!(st->codecpar->codec_id = ff_codec_get_id(mp4_audio_types,
+ cfg.object_type)))
+ st->codecpar->codec_id = AV_CODEC_ID_AAC;
switch (cfg.object_type) {
case AOT_AAC_MAIN:
case AOT_AAC_LC:
@@ -385,15 +389,20 @@ int ff_mp4_read_dec_config_descr(void *logctx, AVStream *st, AVIOContext *pb)
case AOT_USAC:
st->codecpar->frame_size = cfg.frame_length;
break;
+ case AOT_L1:
+ case AOT_L2:
+ /* Access units are plain frames, the AudioSpecificConfig
+ * is not their extradata. */
+ st->codecpar->frame_size = av_get_audio_frame_duration2(st->codecpar, 0);
+ av_freep(&st->codecpar->extradata);
+ st->codecpar->extradata_size = 0;
+ break;
}
av_log(logctx, AV_LOG_TRACE, "mp4a config channels %d obj %d ext obj %d "
"sample rate %d ext sample rate %d frame_length %d\n", cfg.channels,
cfg.object_type, cfg.ext_object_type,
cfg.sample_rate, cfg.ext_sample_rate,
cfg.frame_length);
- if (!(st->codecpar->codec_id = ff_codec_get_id(mp4_audio_types,
- cfg.object_type)))
- st->codecpar->codec_id = AV_CODEC_ID_AAC;
}
}
return 0;