allow to set frame file type instead of hardcoded jpg

This commit is contained in:
Shaked Klein Orbach 2018-03-05 18:59:57 -06:00
commit ae92dd5887
2 changed files with 14 additions and 8 deletions

View file

@ -35,6 +35,7 @@ class ExtractMultipleFramesFilter implements VideoFilterInterface
private $priority;
private $frameRate;
private $destinationFolder;
private $frameFileType = 'jpg';
public function __construct($frameRate = self::FRAMERATE_EVERY_SEC, $destinationFolder = __DIR__, $priority = 0)
{
@ -49,6 +50,10 @@ class ExtractMultipleFramesFilter implements VideoFilterInterface
$this->destinationFolder = $destinationFolder;
}
public function setFrameFileType($frameFileType) {
$this->frameFileType = $frameFileType;
}
/**
* {@inheritdoc}
*/
@ -117,7 +122,7 @@ class ExtractMultipleFramesFilter implements VideoFilterInterface
// Set the parameters
$commands[] = '-vf';
$commands[] = 'fps=' . $this->frameRate;
$commands[] = $this->destinationFolder . 'frame-%'.$nbDigitsInFileNames.'d.jpg';
$commands[] = $this->destinationFolder . 'frame-%'.$nbDigitsInFileNames.'d.' . $this->frameFileType;
}
catch (RuntimeException $e) {
throw new RuntimeException('An error occured while extracting the frames: ' . $e->getMessage() . '. The code: ' . $e->getCode());

View file

@ -12,7 +12,7 @@ class ExtractMultipleFramesFilterTest extends TestCase
/**
* @dataProvider provideFrameRates
*/
public function testApply($frameRate, $destinationFolder, $duration, $modulus, $expected)
public function testApply($frameRate, $frameFileType,$destinationFolder, $duration, $modulus, $expected)
{
$video = $this->getVideoMock();
$pathfile = '/path/to/file'.mt_rand();
@ -34,18 +34,19 @@ class ExtractMultipleFramesFilterTest extends TestCase
->will($this->returnValue($streams));
$filter = new ExtractMultipleFramesFilter($frameRate, $destinationFolder);
$filter->setFrameFileType($frameFileType);
$this->assertEquals($expected, $filter->apply($video, $format));
}
public function provideFrameRates()
{
return array(
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_SEC, '/', 100, 2, array('-vf', 'fps=1/1', '/frame-%03d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_2SEC, '/', 100, 2, array('-vf', 'fps=1/2', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_5SEC, '/', 100, 2, array('-vf', 'fps=1/5', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_10SEC, '/', 100, 2, array('-vf', 'fps=1/10', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_30SEC, '/', 100, 2, array('-vf', 'fps=1/30', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_60SEC, '/', 100, 2, array('-vf', 'fps=1/60', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_SEC,'jpg', '/', 100, 2, array('-vf', 'fps=1/1', '/frame-%03d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_2SEC,'jpg', '/', 100, 2, array('-vf', 'fps=1/2', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_5SEC,'jpg', '/', 100, 2, array('-vf', 'fps=1/5', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_10SEC,'jpg', '/', 100, 2, array('-vf', 'fps=1/10', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_30SEC,'jpg', '/', 100, 2, array('-vf', 'fps=1/30', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_60SEC,'png', '/', 100, 2, array('-vf', 'fps=1/60', '/frame-%02d.png')),
);
}
}