From cebdb33b2e30b180f1f194b57b43146b73dcae7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20P=C3=B6schel?= <github@basicmaster.de>
Date: Sun, 11 Feb 2024 10:37:03 +0100
Subject: [PATCH] Fix MPEG-2 TS detection

So far the MPEG-2 TS made assumptions which do not hold for the first packet of
every MPEG-2 TS, e.g. that the first packet contains a PAT (fixed PID 0).
This alternative approach exploits the fixed packet size of 188 bytes (192 bytes
with BDAV MPEG-2 TS) and checks the first five packets for the Sync Byte 0x47.
The used offsets partly seems to be a bit high in contrast to other formats, but
MPEG-2 TS files are usually much bigger than that.
---
 magic/Magdir/animation | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/magic/Magdir/animation b/magic/Magdir/animation
index 50c1a598..d1f916e4 100644
--- a/magic/Magdir/animation
+++ b/magic/Magdir/animation
@@ -927,15 +927,12 @@
 #
 # from Oskar Schirmer <schirmer@scara.com> Feb 3, 2001 (ISO 13818.1)
 # syncbyte      8 bit	0x47
-# error_ind     1 bit	-
-# payload_start 1 bit	1
-# priority      1 bit	-
-# PID          13 bit	0x0000
-# scrambling    2 bit	-
-# adaptfld_ctrl 2 bit	1 or 3
-# conti_count   4 bit	-
-0	belong&0xFF5FFF10	0x47400010
->188	byte			0x47		MPEG transport stream data
+# 188 bytes per packet
+0		byte			0x47
+>188	byte			0x47
+>>376	byte			0x47
+>>>564	byte			0x47
+>>>>752	byte			0x47		MPEG transport stream data
 !:mime  video/MP2T
 !:ext	ts
 
@@ -943,8 +940,11 @@
 # From: Alexandre Iooss <erdnaxe@crans.org>
 # URL: https://en.wikipedia.org/wiki/MPEG_transport_stream
 # Note: similar to ISO 13818.1 but with 4 extra bytes per packets
-4	belong&0xFF5FFF10	=0x47400010
->196	byte			=0x47		BDAV MPEG-2 Transport Stream (M2TS)
+4		byte			0x47
+>196	byte			0x47
+>>388	byte			0x47
+>>>580	byte			0x47
+>>>>772	byte			0x47		BDAV MPEG-2 Transport Stream (M2TS)
 !:mime	video/MP2T
 !:ext	m2ts/mts
 
-- 
2.39.2

