PR #26339 opened by AYOUB NABIL BOUBAGRAT (ayoubnabil)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26339
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26339.patch

four AC-3 frames in a single program stream pack can tie the raw AC-3
probe at 25. count a valid private stream 1 packet when scoring short
program streams so the container wins with or without a system header.
this fixes #26249.

this can also identify other private streams earlier. pcm_aud.mpg is
now detected after 2048 bytes instead of 8192.




>From ff67357db4d4dccc7bb5b06594b722a33debb89d Mon Sep 17 00:00:00 2001
From: Ayoub Nabil Boubagrat <[email protected]>
Date: Mon, 23 Nov 2026 17:08:00 +0100
Subject: [PATCH] avformat/mpeg: count private stream 1 packets when probing
 short program streams

four AC-3 frames in a single program stream pack can tie the raw AC-3
probe at 25. count a valid private stream 1 packet when scoring short
program streams so the container wins with or without a system header.
this fixes #26249.

this can also identify other private streams earlier. pcm_aud.mpg is
now detected after 2048 bytes instead of 8192.

Signed-off-by: Ayoub Nabil Boubagrat 
<[email protected]>
---
 libavformat/mpeg.c    |  4 ++--
 tests/fate/mpegps.mak | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 43bbf0ef9f0..fd9791dc348 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -107,10 +107,10 @@ static int mpegps_probe(const AVProbeData *p)
 
     if (sys > invalid && sys * 9 <= pspack * 10)
         return (audio > 12 || vid > 3 || pspack > 2) ? AVPROBE_SCORE_EXTENSION 
+ 2
-                                                     : AVPROBE_SCORE_EXTENSION 
/ 2 + (audio + vid + pspack > 1); // 1 more than mp3
+                                                     : AVPROBE_SCORE_EXTENSION 
/ 2 + (priv1 + audio + vid + pspack > 1); // 1 more than mp3
     if (pspack > invalid && (priv1 + vid + audio) * 10 >= pspack * 9)
         return pspack > 2 ? AVPROBE_SCORE_EXTENSION + 2
-                          : AVPROBE_SCORE_EXTENSION / 2; // 1 more than .mpg
+                          : AVPROBE_SCORE_EXTENSION / 2 + (priv1 > 0);
     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 
+ 1
diff --git a/tests/fate/mpegps.mak b/tests/fate/mpegps.mak
index 8f796960e34..3f0a81034ab 100644
--- a/tests/fate/mpegps.mak
+++ b/tests/fate/mpegps.mak
@@ -6,6 +6,22 @@ fate-mpegps-remuxed-pcm-demux: CMD = stream_remux "mpeg" 
"$(TARGET_SAMPLES)/mpeg
 FATE_SAMPLES_FFMPEG += $(FATE_MPEGPS-yes)
 fate-mpegps: $(FATE_MPEGPS-yes)
 
+# Keep four contiguous AC-3 frames in one private-stream packet.
+tests/data/mpegps-ac3-probe.mpg: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+       $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin -v error \
+           -i $(TARGET_SAMPLES)/ac3/monsters_inc_2.0_192_small.ac3 -c:a copy \
+           -frames:a 4 -packetsize 4096 -f mpeg -y $(TARGET_PATH)/$@
+tests/data/mpegps-ac3-probe.mpg: $(SAMPLES)/ac3/monsters_inc_2.0_192_small.ac3
+
+FATE_MPEGPS_PROBE-$(call DEMMUX, AC3 MPEGPS, MPEG1SYSTEM, AC3_PARSER) += 
fate-mpegps-ac3-probe
+fate-mpegps-ac3-probe: tests/data/mpegps-ac3-probe.mpg
+fate-mpegps-ac3-probe: CMD = probe -show_entries format=format_name -of 
csv=p=0 $(TARGET_PATH)/tests/data/mpegps-ac3-probe.mpg
+fate-mpegps-ac3-probe: CMP = oneline
+fate-mpegps-ac3-probe: REF = mpeg
+fate-mpegps-ac3-probe: CLEANFILES = tests/data/mpegps-ac3-probe.mpg
+FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_MPEGPS_PROBE-yes)
+fate-mpegps: $(FATE_MPEGPS_PROBE-yes)
+
 # A sequence display extension can carry reserved colour values; they must not 
reach the frame
 FATE_SAMPLES_FFMPEG_FFPROBE-$(call REMUX, MPEG2VIDEO MPEGVIDEO, 
MPEGVIDEO_PARSER MPEG2_METADATA_BSF EXTRACT_EXTRADATA_BSF MPEG2VIDEO_DECODER) 
+= fate-mpeg2-reserved-color-tags
 fate-mpeg2-reserved-color-tags: CMD = stream_remux mpegvideo 
$(TARGET_SAMPLES)/mpeg2/tcela-6.bits "" mpeg2video \
-- 
2.54.1

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

Reply via email to