PR #23247 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23247
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23247.patch

The heuristics run to detect PES streams are much laxer than mp3/ac3 ones, 
which check for valid headers, so it should not have a higher score than the 
latter.

Fixes misdetection of some mp3 files with big id3v2 tags at the beginning.


>From a944319833a969f24604ffa9f22231dd6a2724f6 Mon Sep 17 00:00:00 2001
From: James Almer <[email protected]>
Date: Tue, 26 May 2026 23:50:57 +0000
Subject: [PATCH] avformat/mpeg: lower PES stream score compared to mp3/ac3

The heuristics run to detect PES streams are much laxer than mp3/ac3 ones,
which check for valid headers, so it should not have a higher score than the
latter.

Fixes misdetection of some mp3 files with big id3v2 tags at the beginning.

Signed-off-by: James Almer <[email protected]>
---
 libavformat/ac3dec.c                 | 2 +-
 libavformat/mp3dec.c                 | 2 +-
 libavformat/mpeg.c                   | 2 +-
 tests/ref/fate/gapless-mp3-side-data | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c
index 0b1557d68c..d6bcaff245 100644
--- a/libavformat/ac3dec.c
+++ b/libavformat/ac3dec.c
@@ -92,7 +92,7 @@ static int ac3_eac3_probe(const AVProbeData *p, enum 
AVCodecID expected_codec_id
     if(codec_id != expected_codec_id) return 0;
     // keep this in sync with mp3 probe, both need to avoid
     // issues with MPEG-files!
-    if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
+    if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 2;
     else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
     else if(max_frames>=4) return AVPROBE_SCORE_EXTENSION/2;
     else if(max_frames>=1) return 1;
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 5b153c7c9e..bc1c927d80 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -119,7 +119,7 @@ static int mp3_read_probe(const AVProbeData *p)
     }
     // keep this in sync with ac3 probe, both need to avoid
     // issues with MPEG-files!
-    if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
+    if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 2;
     else if (max_frames>200 && p->buf_size < 2*max_framesizes)return 
AVPROBE_SCORE_EXTENSION;
     else if (max_frames>=4 && p->buf_size < 2*max_framesizes) return 
AVPROBE_SCORE_EXTENSION / 2;
     else if (ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size)
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index c78cc63603..ff5ced8107 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -113,7 +113,7 @@ static int mpegps_probe(const AVProbeData *p)
                           : AVPROBE_SCORE_EXTENSION / 2; // 1 more than .mpg
     if ((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys &&
         !pspack && p->buf_size > 2048 && vid + audio > invalid) /* PES stream 
*/
-        return (audio > 12 || vid > 6 + 2 * invalid) ? AVPROBE_SCORE_EXTENSION 
+ 2
+        return (audio > 12 || vid > 6 + 2 * invalid) ? AVPROBE_SCORE_EXTENSION 
+ 1
                                                      : AVPROBE_SCORE_EXTENSION 
/ 2;
 
     // 02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1
diff --git a/tests/ref/fate/gapless-mp3-side-data 
b/tests/ref/fate/gapless-mp3-side-data
index 99f1033e4b..083a07c4be 100644
--- a/tests/ref/fate/gapless-mp3-side-data
+++ b/tests/ref/fate/gapless-mp3-side-data
@@ -594,4 +594,4 @@ 
packet|codec_type=audio|stream_index=0|pts=218234880|pts_time=15.464490|dts=2182
 
packet|codec_type=audio|stream_index=0|pts=218603520|pts_time=15.490612|dts=218603520|dts_time=15.490612|duration=368640|duration_time=0.026122|size=418|pos=249300|flags=K__|data_hash=CRC32:d5fb5f9c|side_datum/skip_samples:side_data_type=Skip
 
Samples|side_datum/skip_samples:skip_samples=0|side_datum/skip_samples:discard_padding=303|side_datum/skip_samples:skip_reason=0|side_datum/skip_samples:discard_reason=0
 
packet|codec_type=audio|stream_index=0|pts=218972160|pts_time=15.516735|dts=218972160|dts_time=15.516735|duration=368640|duration_time=0.026122|size=418|pos=249718|flags=K__|data_hash=CRC32:3789f3cf|side_datum/skip_samples:side_data_type=Skip
 
Samples|side_datum/skip_samples:skip_samples=0|side_datum/skip_samples:discard_padding=1152|side_datum/skip_samples:skip_reason=0|side_datum/skip_samples:discard_reason=0
 
stream|index=0|codec_name=mp3|profile=unknown|codec_type=audio|codec_tag_string=[0][0][0][0]|codec_tag=0x0000|mime_codec_string=mp4a.40.34|sample_fmt=fltp|sample_rate=44100|channels=2|channel_layout=stereo|bits_per_sample=0|initial_padding=0|id=N/A|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/14112000|start_pts=353600|start_time=0.025057|duration_ts=218521600|duration=15.484807|bit_rate=128000|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=595|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:non_diegetic=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0|disposition:multilayer=0|tag:encoder=LAME3.93
 
-format|filename=gapless.mp3|nb_streams=1|nb_programs=0|nb_stream_groups=0|format_name=mp3|start_time=0.025057|duration=15.484807|size=250264|bit_rate=129295|probe_score=51|tag:title=test
+format|filename=gapless.mp3|nb_streams=1|nb_programs=0|nb_stream_groups=0|format_name=mp3|start_time=0.025057|duration=15.484807|size=250264|bit_rate=129295|probe_score=52|tag:title=test
-- 
2.52.0

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

Reply via email to