Skip to content

Commit 8a4ca42

Browse files
committed
Add MXF #12
1 parent 86b0876 commit 8a4ca42

File tree

8 files changed

+45
-0
lines changed

8 files changed

+45
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@
3939
*.ogv binary
4040
*.wmv binary
4141
*.flv binary
42+
*.mxf binary

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Video type detection library for PHP.
2929
* **QuickTime**
3030
* **WMV** (Windows Media Video)
3131
* **FLV** (Adobe Flash Video)
32+
* **MXF** (Material Exchange Format)
3233

3334
## Requirements
3435

src/Detector/MxfDetector.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Selective\VideoType\Detector;
4+
5+
use Selective\VideoType\VideoFormat;
6+
use Selective\VideoType\VideoType;
7+
use Selective\VideoType\VideoMimeType;
8+
use SplFileObject;
9+
10+
/**
11+
* Detector.
12+
*/
13+
final class MxfDetector implements VideoDetectorInterface
14+
{
15+
/**
16+
* MXF - Material Exchange Format.
17+
*
18+
* http://fileformats.archiveteam.org/wiki/MXF#Identifiers
19+
*
20+
* @param SplFileObject $file The video file
21+
*
22+
* @return VideoType|null The video type
23+
*/
24+
public function detect(SplFileObject $file): ?VideoType
25+
{
26+
// Search at the end of the file
27+
$offset = $file->getSize() - 1024;
28+
$file->fseek($offset);
29+
30+
$magicBytes = (string)hex2bin('060e2b34020501010d0102');
31+
$hasMagicBytes = strpos((string)$file->fread(1024), $magicBytes) !== false;
32+
33+
return $hasMagicBytes ? new VideoType(
34+
VideoFormat::MXF,
35+
VideoMimeType::VIDEO_MXF
36+
) : null;
37+
}
38+
}

src/Provider/DefaultVideoProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Selective\VideoType\Detector\MpegDetector;
88
use Selective\VideoType\Detector\Mpeg4Detector;
99
use Selective\VideoType\Detector\MkvDetector;
10+
use Selective\VideoType\Detector\MxfDetector;
1011
use Selective\VideoType\Detector\OgvDetector;
1112
use Selective\VideoType\Detector\QuickTimeDetector;
1213
use Selective\VideoType\Detector\ThreeGp2Detector;
@@ -36,6 +37,7 @@ public function getDetectors(): array
3637
new QuickTimeDetector(),
3738
new WmvDetector(),
3839
new FlvDetector(),
40+
new MxfDetector(),
3941
];
4042
}
4143
}

src/VideoFormat.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ final class VideoFormat
1818
public const QUICK_TIME = 'mov';
1919
public const WMV = 'wmv';
2020
public const FLV = 'flv';
21+
public const MXF = 'mxf';
2122
}

src/VideoMimeType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ final class VideoMimeType
1818
public const VIDEO_QUICK_TIME = 'video/quicktime';
1919
public const VIDEO_WMV = 'video/x-ms-wmv';
2020
public const VIDEO_FLV = 'video/x-flv';
21+
public const VIDEO_MXF = 'application/mxf';
2122
}

tests/VideoTypeDetectorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function providerGetVideoTypeFromFile(): array
7575
[__DIR__ . '/videos/test.ogv', VideoFormat::OGV, VideoMimeType::VIDEO_OGG],
7676
[__DIR__ . '/videos/test.wmv', VideoFormat::WMV, VideoMimeType::VIDEO_WMV],
7777
[__DIR__ . '/videos/test.flv', VideoFormat::FLV, VideoMimeType::VIDEO_FLV],
78+
[__DIR__ . '/videos/test.mxf', VideoFormat::MXF, VideoMimeType::VIDEO_MXF],
7879
];
7980
}
8081

tests/videos/test.mxf

609 KB
Binary file not shown.

0 commit comments

Comments
 (0)