Skip to content

Commit

Permalink
Add MXF #12
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Sep 3, 2019
1 parent 86b0876 commit 8a4ca42
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
*.ogv binary
*.wmv binary
*.flv binary
*.mxf binary
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Video type detection library for PHP.
* **QuickTime**
* **WMV** (Windows Media Video)
* **FLV** (Adobe Flash Video)
* **MXF** (Material Exchange Format)

## Requirements

Expand Down
38 changes: 38 additions & 0 deletions src/Detector/MxfDetector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Selective\VideoType\Detector;

use Selective\VideoType\VideoFormat;
use Selective\VideoType\VideoType;
use Selective\VideoType\VideoMimeType;
use SplFileObject;

/**
* Detector.
*/
final class MxfDetector implements VideoDetectorInterface
{
/**
* MXF - Material Exchange Format.
*
* http://fileformats.archiveteam.org/wiki/MXF#Identifiers
*
* @param SplFileObject $file The video file
*
* @return VideoType|null The video type
*/
public function detect(SplFileObject $file): ?VideoType
{
// Search at the end of the file
$offset = $file->getSize() - 1024;
$file->fseek($offset);

$magicBytes = (string)hex2bin('060e2b34020501010d0102');
$hasMagicBytes = strpos((string)$file->fread(1024), $magicBytes) !== false;

return $hasMagicBytes ? new VideoType(
VideoFormat::MXF,
VideoMimeType::VIDEO_MXF
) : null;
}
}
2 changes: 2 additions & 0 deletions src/Provider/DefaultVideoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Selective\VideoType\Detector\MpegDetector;
use Selective\VideoType\Detector\Mpeg4Detector;
use Selective\VideoType\Detector\MkvDetector;
use Selective\VideoType\Detector\MxfDetector;
use Selective\VideoType\Detector\OgvDetector;
use Selective\VideoType\Detector\QuickTimeDetector;
use Selective\VideoType\Detector\ThreeGp2Detector;
Expand Down Expand Up @@ -36,6 +37,7 @@ public function getDetectors(): array
new QuickTimeDetector(),
new WmvDetector(),
new FlvDetector(),
new MxfDetector(),
];
}
}
1 change: 1 addition & 0 deletions src/VideoFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ final class VideoFormat
public const QUICK_TIME = 'mov';
public const WMV = 'wmv';
public const FLV = 'flv';
public const MXF = 'mxf';
}
1 change: 1 addition & 0 deletions src/VideoMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ final class VideoMimeType
public const VIDEO_QUICK_TIME = 'video/quicktime';
public const VIDEO_WMV = 'video/x-ms-wmv';
public const VIDEO_FLV = 'video/x-flv';
public const VIDEO_MXF = 'application/mxf';
}
1 change: 1 addition & 0 deletions tests/VideoTypeDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function providerGetVideoTypeFromFile(): array
[__DIR__ . '/videos/test.ogv', VideoFormat::OGV, VideoMimeType::VIDEO_OGG],
[__DIR__ . '/videos/test.wmv', VideoFormat::WMV, VideoMimeType::VIDEO_WMV],
[__DIR__ . '/videos/test.flv', VideoFormat::FLV, VideoMimeType::VIDEO_FLV],
[__DIR__ . '/videos/test.mxf', VideoFormat::MXF, VideoMimeType::VIDEO_MXF],
];
}

Expand Down
Binary file added tests/videos/test.mxf
Binary file not shown.

0 comments on commit 8a4ca42

Please sign in to comment.