View Issue Details

IDProjectCategoryView StatusLast Update
0000306fileGeneralpublic2024-02-11 15:34
Reporteres20490446e Assigned Tochristos  
PrioritylowSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version5.41 
Fixed in VersionHEAD 
Summary0000306: Not recognized: MPEG-2 transport stream
Description"MPEG-2 transport stream" is recognized as "application/octet-stream".

Mime spec at:
/usr/share/mime/video/mp2t.xml
TagsNo tags attached.

Activities

christos

2022-01-10 16:19

manager   ~0003687

This is a data container format with no particular magic identifier. https://en.wikipedia.org/wiki/MPEG_transport_stream

es20490446e

2022-01-10 20:12

reporter   ~0003690

Do you mean it is okay as it is now?

Basic.Master

2024-02-11 09:48

reporter   ~0004004

The current detection of an MPEG-TS is quite restrictive and makes assumptions that don't apply to all transport streams, as has already been stated here:
https://github.com/file/file/commit/e657a2e200fb59979478aa6797c28ef4b2952495#diff-b5e20963b12b6811f0ca24ddd36790e9f3016bd5bb7af6083ca585c50ed34d4fL691

As the format has only a single magic byte, we can exploit the fixed packet size here.
Please find attached a corresponding patch and a short test file (playable e.g. in VLC) for which the patch fixes the recognition.

See also https://bugs.freedesktop.org/show_bug.cgi?id=51118
0001-Fix-MPEG-2-TS-detection.patch (1,946 bytes)   
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

hr_test.ts (141,000 bytes)

es20490446e

2024-02-11 14:41

reporter   ~0004005

Remember me which package this was about (name of the source code repo).

es20490446e

2024-02-11 14:43

reporter   ~0004006

Was it "file"?

Basic.Master

2024-02-11 15:03

reporter   ~0004007

Correct, as shown in the e-mail subject and in the project field here ;-)

es20490446e

2024-02-11 15:07

reporter   ~0004008

without patch:
hr_test.ts: data

whith patch:
hr_test.ts: MPEG transport stream data

so fixed, many thanks ;)

christos

2024-02-11 15:34

manager   ~0004009

Patch applied, thanks!

Issue History

Date Modified Username Field Change
2021-12-27 18:26 es20490446e New Issue
2022-01-10 16:17 christos Assigned To => christos
2022-01-10 16:17 christos Status new => assigned
2022-01-10 16:19 christos Status assigned => feedback
2022-01-10 16:19 christos Note Added: 0003687
2022-01-10 20:12 es20490446e Note Added: 0003690
2022-01-10 20:12 es20490446e Status feedback => assigned
2024-02-11 09:48 Basic.Master Note Added: 0004004
2024-02-11 09:48 Basic.Master File Added: 0001-Fix-MPEG-2-TS-detection.patch
2024-02-11 09:48 Basic.Master File Added: hr_test.ts
2024-02-11 14:41 es20490446e Note Added: 0004005
2024-02-11 14:43 es20490446e Note Added: 0004006
2024-02-11 15:03 Basic.Master Note Added: 0004007
2024-02-11 15:07 es20490446e Note Added: 0004008
2024-02-11 15:33 christos Assigned To christos =>
2024-02-11 15:33 christos Assigned To => christos
2024-02-11 15:34 christos Status assigned => resolved
2024-02-11 15:34 christos Resolution open => fixed
2024-02-11 15:34 christos Fixed in Version => HEAD
2024-02-11 15:34 christos Note Added: 0004009