* [FFmpeg-devel] [PR] lavf/aacdec: improve probe for AAC files with ID3v2 tags (PR #21472)
@ 2026-01-15 5:30 Jun Zhao via ffmpeg-devel
0 siblings, 0 replies; only message in thread
From: Jun Zhao via ffmpeg-devel @ 2026-01-15 5:30 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Jun Zhao
PR #21472 opened by Jun Zhao (mypopydev)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21472
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21472.patch
The AAC probe was returning low score (1) for valid ADTS AAC files
starting with ID3v2 tags, common in HLS streams, triggering:
"Format aac detected only with low score of 1, misdetection possible!"
Fix by skipping ID3v2 tags at the beginning and between ADTS frames
during probing, similar to mp3_read_probe() in mp3dec.c.
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
>From 1b222f5de992ccf36f1cc3573180286d3a4cd068 Mon Sep 17 00:00:00 2001
From: Jun Zhao <barryjzhao@tencent.com>
Date: Thu, 15 Jan 2026 12:54:22 +0800
Subject: [PATCH] lavf/aacdec: improve probe for AAC files with ID3v2 tags
The AAC probe was returning low score (1) for valid ADTS AAC files
starting with ID3v2 tags, common in HLS streams, triggering:
"Format aac detected only with low score of 1, misdetection possible!"
Fix by skipping ID3v2 tags at the beginning and between ADTS frames
during probing, similar to mp3_read_probe() in mp3dec.c.
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
libavformat/aacdec.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index fef3c69f0b..b87619ec7c 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -40,15 +40,39 @@ static int adts_aac_probe(const AVProbeData *p)
const uint8_t *buf2;
const uint8_t *buf;
const uint8_t *end = buf0 + p->buf_size - 7;
+ int id3_skip = 0;
buf = buf0;
+ // Skip ID3v2 tags at the beginning to find the actual ADTS data
+ while (buf + ID3v2_HEADER_SIZE < end &&
+ ff_id3v2_match(buf, ID3v2_DEFAULT_MAGIC)) {
+ int taglen = ff_id3v2_tag_len(buf);
+ if (id3_skip + taglen > p->buf_size)
+ break;
+ id3_skip += taglen;
+ buf = p->buf + id3_skip;
+ }
+
+ // Update buf0 to point after ID3v2 tags for first_frames calculation
+ buf0 = buf;
+
for (; buf < end; buf = buf2 + 1) {
buf2 = buf;
for (frames = 0; buf2 < end; frames++) {
uint32_t header = AV_RB16(buf2);
if ((header & 0xFFF6) != 0xFFF0) {
+ // Skip embedded ID3v2 tags (common in HLS AAC streams)
+ if (buf2 + ID3v2_HEADER_SIZE < end &&
+ ff_id3v2_match(buf2, ID3v2_DEFAULT_MAGIC)) {
+ int id3len = ff_id3v2_tag_len(buf2);
+ if (buf2 + id3len < end) {
+ buf2 += id3len;
+ frames--; // compensate for the frames++ in the loop
+ continue;
+ }
+ }
if (buf != buf0) {
// Found something that isn't an ADTS header, starting
// from a position other than the start of the buffer.
@@ -75,6 +99,9 @@ static int adts_aac_probe(const AVProbeData *p)
return AVPROBE_SCORE_EXTENSION;
else if (max_frames >= 3)
return AVPROBE_SCORE_EXTENSION / 2;
+ // If file starts with ID3v2 and we found ADTS frames after it, boost score
+ else if (id3_skip > 0 && max_frames >= 1)
+ return AVPROBE_SCORE_EXTENSION / 2;
else if (first_frames >= 1)
return 1;
else
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-01-15 5:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-15 5:30 [FFmpeg-devel] [PR] lavf/aacdec: improve probe for AAC files with ID3v2 tags (PR #21472) Jun Zhao via ffmpeg-devel
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git