Add FFProbe#isValid

fixes #394
This commit is contained in:
jens1o 2017-09-19 19:28:34 +02:00
commit 74a1d6539c
No known key found for this signature in database
GPG key ID: C7437FC1B445CC49
2 changed files with 33 additions and 1 deletions

View file

@ -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(string $pathfile)
{
try {
return $this->format($pathfile)->get('duration') > 0;
} catch(\Exception $e) {
// complete invalid data
return false;
}
}
/**
* @api
*

View file

@ -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');