From: Jun Zhao via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Jun Zhao <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] lavf/aacdec: improve probe for AAC files with ID3v2 tags (PR #21472)
Date: Thu, 15 Jan 2026 05:30:44 -0000
Message-ID: <176845504547.25.17781000858282546285@4457048688e7> (raw)
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
reply other threads:[~2026-01-15 5:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176845504547.25.17781000858282546285@4457048688e7 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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