diff --git a/src/FFMpeg/FFProbe.php b/src/FFMpeg/FFProbe.php index 7e25b0d..a1a0ba3 100644 --- a/src/FFMpeg/FFProbe.php +++ b/src/FFMpeg/FFProbe.php @@ -170,6 +170,25 @@ class FFProbe return $this->probe($pathfile, '-show_format', static::TYPE_FORMAT); } + /** + * @api + * + * Checks wether the given `$pathfile` is considered a valid media file. + * + * @param string $pathfile + * @return bool + * @since 0.10.0 + */ + public function isValid($pathfile) + { + try { + return $this->format($pathfile)->get('duration') > 0; + } catch(\Exception $e) { + // complete invalid data + return false; + } + } + /** * @api * diff --git a/tests/Functional/FFProbeTest.php b/tests/Functional/FFProbeTest.php index 10a98c0..b183e08 100644 --- a/tests/Functional/FFProbeTest.php +++ b/tests/Functional/FFProbeTest.php @@ -12,10 +12,23 @@ class FFProbeTest extends FunctionalTestCase $this->assertGreaterThan(0, count($ffprobe->streams(__DIR__ . '/../files/Audio.mp3'))); } + public function testValidateExistingFile() + { + $ffprobe = FFProbe::create(); + $this->assertTrue($ffprobe->isValid(__DIR__ . '/../files/sample.3gp')); + } + + + public function testValidateNonExistingFile() + { + $ffprobe = FFProbe::create(); + $this->assertFalse($ffprobe->isValid(__DIR__ . '/../files/WrongFile.mp4')); + } + /** * @expectedException FFMpeg\Exception\RuntimeException */ - public function testProbeOnUnexistantFile() + public function testProbeOnNonExistantFile() { $ffprobe = FFProbe::create(); $ffprobe->streams('/path/to/no/file');