Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Lasse Lehtinen 2018-05-30 15:02:09 +03:00
commit 4f40ba9d96
5 changed files with 57 additions and 11 deletions

View file

@ -35,6 +35,10 @@ class ExtractMultipleFramesFilter implements VideoFilterInterface
private $priority; private $priority;
private $frameRate; private $frameRate;
private $destinationFolder; private $destinationFolder;
private $frameFileType = 'jpg';
/** @var array */
private static $supportedFrameFileTypes = ['jpg', 'jpeg', 'png'];
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 +53,20 @@ class ExtractMultipleFramesFilter implements VideoFilterInterface
$this->destinationFolder = $destinationFolder; $this->destinationFolder = $destinationFolder;
} }
/**
* @param string $frameFileType
* @throws \FFMpeg\Exception\InvalidArgumentException
* @return ExtractMultipleFramesFilter
*/
public function setFrameFileType($frameFileType) {
if (in_array($frameFileType, self::$supportedFrameFileTypes)) {
$this->frameFileType = $frameFileType;
return $this;
}
throw new InvalidArgumentException('Invalid frame file type, use: ' . implode(',', self::$supportedFrameFileTypes));
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -117,7 +135,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());

View file

@ -72,7 +72,7 @@ class Concat extends AbstractMediaType
/** /**
* Saves the concatenated video in the given array, considering that the sources videos are all encoded with the same codec. * Saves the concatenated video in the given array, considering that the sources videos are all encoded with the same codec.
* *
* @param array $outputPathfile * @param string $outputPathfile
* @param string $streamCopy * @param string $streamCopy
* *
* @return Concat * @return Concat
@ -144,6 +144,7 @@ class Concat extends AbstractMediaType
$this->driver->command($commands); $this->driver->command($commands);
} catch (ExecutionFailureException $e) { } catch (ExecutionFailureException $e) {
$this->cleanupTemporaryFile($outputPathfile); $this->cleanupTemporaryFile($outputPathfile);
// TODO@v1: paste this line into an `finally` block.
$this->cleanupTemporaryFile($sourcesFile); $this->cleanupTemporaryFile($sourcesFile);
throw new RuntimeException('Unable to save concatenated video', $e->getCode(), $e); throw new RuntimeException('Unable to save concatenated video', $e->getCode(), $e);
} }

View file

@ -115,7 +115,9 @@ class Frame extends AbstractMediaType
$commands = array_merge($commands, $filter->apply($this)); $commands = array_merge($commands, $filter->apply($this));
} }
$commands = array_merge($commands, array($pathfile)); if (!$returnBase64) {
$commands = array_merge($commands, array($pathfile));
}
try { try {
if(!$returnBase64) { if(!$returnBase64) {

View file

@ -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,41 @@ 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, 'jpg', '/', 100, 2, array('-vf', 'fps=1/60', '/frame-%02d.jpg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_SEC, 'jpeg', '/', 100, 2, array('-vf', 'fps=1/1', '/frame-%03d.jpeg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_2SEC, 'jpeg', '/', 100, 2, array('-vf', 'fps=1/2', '/frame-%02d.jpeg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_5SEC, 'jpeg', '/', 100, 2, array('-vf', 'fps=1/5', '/frame-%02d.jpeg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_10SEC, 'jpeg', '/', 100, 2, array('-vf', 'fps=1/10', '/frame-%02d.jpeg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_30SEC, 'jpeg', '/', 100, 2, array('-vf', 'fps=1/30', '/frame-%02d.jpeg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_60SEC, 'jpeg', '/', 100, 2, array('-vf', 'fps=1/60', '/frame-%02d.jpeg')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_SEC, 'png', '/', 100, 2, array('-vf', 'fps=1/1', '/frame-%03d.png')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_2SEC, 'png', '/', 100, 2, array('-vf', 'fps=1/2', '/frame-%02d.png')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_5SEC, 'png', '/', 100, 2, array('-vf', 'fps=1/5', '/frame-%02d.png')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_10SEC, 'png', '/', 100, 2, array('-vf', 'fps=1/10', '/frame-%02d.png')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_30SEC, 'png', '/', 100, 2, array('-vf', 'fps=1/30', '/frame-%02d.png')),
array(ExtractMultipleFramesFilter::FRAMERATE_EVERY_60SEC, 'png', '/', 100, 2, array('-vf', 'fps=1/60', '/frame-%02d.png')),
); );
} }
/**
* @expectedException \FFMpeg\Exception\InvalidArgumentException
*/
public function testInvalidFrameFileType() {
$filter = new ExtractMultipleFramesFilter('1/1', '/');
$filter->setFrameFileType('webm');
}
} }

View file

@ -61,7 +61,9 @@ class FrameTest extends AbstractMediaTestCase
$pathfile = '/target/destination'; $pathfile = '/target/destination';
array_push($commands, $pathfile); if (!$base64) {
array_push($commands, $pathfile);
}
$driver->expects($this->once()) $driver->expects($this->once())
->method('command') ->method('command')