allow to set frame file type instead of hardcoded jpg
This commit is contained in:
parent
a1d5fa51ba
commit
ae92dd5887
2 changed files with 14 additions and 8 deletions
|
|
@ -35,6 +35,7 @@ class ExtractMultipleFramesFilter implements VideoFilterInterface
|
||||||
private $priority;
|
private $priority;
|
||||||
private $frameRate;
|
private $frameRate;
|
||||||
private $destinationFolder;
|
private $destinationFolder;
|
||||||
|
private $frameFileType = 'jpg';
|
||||||
|
|
||||||
public function __construct($frameRate = self::FRAMERATE_EVERY_SEC, $destinationFolder = __DIR__, $priority = 0)
|
public function __construct($frameRate = self::FRAMERATE_EVERY_SEC, $destinationFolder = __DIR__, $priority = 0)
|
||||||
{
|
{
|
||||||
|
|
@ -49,6 +50,10 @@ class ExtractMultipleFramesFilter implements VideoFilterInterface
|
||||||
$this->destinationFolder = $destinationFolder;
|
$this->destinationFolder = $destinationFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setFrameFileType($frameFileType) {
|
||||||
|
$this->frameFileType = $frameFileType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -117,7 +122,7 @@ class ExtractMultipleFramesFilter implements VideoFilterInterface
|
||||||
// Set the parameters
|
// Set the parameters
|
||||||
$commands[] = '-vf';
|
$commands[] = '-vf';
|
||||||
$commands[] = 'fps=' . $this->frameRate;
|
$commands[] = 'fps=' . $this->frameRate;
|
||||||
$commands[] = $this->destinationFolder . 'frame-%'.$nbDigitsInFileNames.'d.jpg';
|
$commands[] = $this->destinationFolder . 'frame-%'.$nbDigitsInFileNames.'d.' . $this->frameFileType;
|
||||||
}
|
}
|
||||||
catch (RuntimeException $e) {
|
catch (RuntimeException $e) {
|
||||||
throw new RuntimeException('An error occured while extracting the frames: ' . $e->getMessage() . '. The code: ' . $e->getCode());
|
throw new RuntimeException('An error occured while extracting the frames: ' . $e->getMessage() . '. The code: ' . $e->getCode());
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class ExtractMultipleFramesFilterTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideFrameRates
|
* @dataProvider provideFrameRates
|
||||||
*/
|
*/
|
||||||
public function testApply($frameRate, $destinationFolder, $duration, $modulus, $expected)
|
public function testApply($frameRate, $frameFileType,$destinationFolder, $duration, $modulus, $expected)
|
||||||
{
|
{
|
||||||
$video = $this->getVideoMock();
|
$video = $this->getVideoMock();
|
||||||
$pathfile = '/path/to/file'.mt_rand();
|
$pathfile = '/path/to/file'.mt_rand();
|
||||||
|
|
@ -34,18 +34,19 @@ class ExtractMultipleFramesFilterTest extends TestCase
|
||||||
->will($this->returnValue($streams));
|
->will($this->returnValue($streams));
|
||||||
|
|
||||||
$filter = new ExtractMultipleFramesFilter($frameRate, $destinationFolder);
|
$filter = new ExtractMultipleFramesFilter($frameRate, $destinationFolder);
|
||||||
|
$filter->setFrameFileType($frameFileType);
|
||||||
$this->assertEquals($expected, $filter->apply($video, $format));
|
$this->assertEquals($expected, $filter->apply($video, $format));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideFrameRates()
|
public function provideFrameRates()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_SEC, '/', 100, 2, array('-vf', 'fps=1/1', '/frame-%03d.jpg')),
|
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_SEC,'jpg', '/', 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_2SEC,'jpg', '/', 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_5SEC,'jpg', '/', 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_10SEC,'jpg', '/', 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_30SEC,'jpg', '/', 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_60SEC,'png', '/', 100, 2, array('-vf', 'fps=1/60', '/frame-%02d.png')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue