parent
ef0ece8e61
commit
74a1d6539c
2 changed files with 33 additions and 1 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue