Methods getAdditionalParams & setAdditionalParams which allow the user to pass additional parameters to the encoding request (#284)
* Modification of the format Video to add additional parameters based on user's desire * Update of the README * Working version of this feature. Still needs tests * Fixing the tests of FFMPeg\Media\Video * Setting up tests for the additionalParams feature * Correction des tests * Modifying tests. They work locally but not on Travis. * Still trying to understand why Travis is throwing errors when PHPUnit is not. * Add the additional params at the end of the command * Fixed the tests and the way we add the parameters * We remove log files
This commit is contained in:
parent
2b5d18f510
commit
6ba011de3a
5 changed files with 136 additions and 7 deletions
12
README.md
12
README.md
|
|
@ -441,6 +441,18 @@ $video->save($format, 'video.avi');
|
||||||
|
|
||||||
The callback provided for the event can be any callable.
|
The callback provided for the event can be any callable.
|
||||||
|
|
||||||
|
##### Add additional parameters
|
||||||
|
|
||||||
|
You can add additional parameters to your encoding requests based on your video format.
|
||||||
|
|
||||||
|
The argument of the setAdditionalParameters method is an array.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$format = new Format\Video\X264();
|
||||||
|
$format->setAdditionalParameters(array('foo', 'bar'));
|
||||||
|
$video->save($format, 'video.avi');
|
||||||
|
```
|
||||||
|
|
||||||
##### Create your own format
|
##### Create your own format
|
||||||
|
|
||||||
The easiest way to create a format is to extend the abstract
|
The easiest way to create a format is to extend the abstract
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,9 @@ abstract class DefaultVideo extends DefaultAudio implements VideoInterface
|
||||||
/** @var Integer */
|
/** @var Integer */
|
||||||
protected $modulus = 16;
|
protected $modulus = 16;
|
||||||
|
|
||||||
|
/** @var Array */
|
||||||
|
protected $additionalParamaters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -94,6 +97,31 @@ abstract class DefaultVideo extends DefaultAudio implements VideoInterface
|
||||||
return $this->modulus;
|
return $this->modulus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getAdditionalParameters()
|
||||||
|
{
|
||||||
|
return $this->additionalParamaters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets additional parameters.
|
||||||
|
*
|
||||||
|
* @param array $additionalParamaters
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function setAdditionalParameters($additionalParamaters)
|
||||||
|
{
|
||||||
|
if (!is_array($additionalParamaters)) {
|
||||||
|
throw new InvalidArgumentException('Wrong additionalParamaters value');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->additionalParamaters = $additionalParamaters;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -54,4 +54,11 @@ interface VideoInterface extends AudioInterface
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getAvailableVideoCodecs();
|
public function getAvailableVideoCodecs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of available video codecs for this format.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAdditionalParameters();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,15 @@ class Video extends Audio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the user passed some additional parameters
|
||||||
|
if ($format instanceof VideoInterface) {
|
||||||
|
if (null !== $format->getAdditionalParameters()) {
|
||||||
|
foreach ($format->getAdditionalParameters() as $additionalParameter) {
|
||||||
|
$commands[] = $additionalParameter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$fs = FsManager::create();
|
$fs = FsManager::create();
|
||||||
$fsId = uniqid('ffmpeg-passes');
|
$fsId = uniqid('ffmpeg-passes');
|
||||||
$passPrefix = $fs->createTemporaryDirectory(0777, 50, $fsId) . '/' . uniqid('pass-');
|
$passPrefix = $fs->createTemporaryDirectory(0777, 50, $fsId) . '/' . uniqid('pass-');
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,29 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
$format->expects($this->any())
|
$format->expects($this->any())
|
||||||
->method('getPasses')
|
->method('getPasses')
|
||||||
->will($this->returnValue(2));
|
->will($this->returnValue(2));
|
||||||
|
$format->expects($this->any())
|
||||||
|
->method('getAdditionalParameters')
|
||||||
|
->will($this->returnValue(array('foo', 'bar')));
|
||||||
|
|
||||||
|
$format2 = $this->getMock('FFMpeg\Format\VideoInterface');
|
||||||
|
$format2->expects($this->any())
|
||||||
|
->method('getExtraParams')
|
||||||
|
->will($this->returnValue(array()));
|
||||||
|
$format2->expects($this->any())
|
||||||
|
->method('getKiloBitrate')
|
||||||
|
->will($this->returnValue(663));
|
||||||
|
$format2->expects($this->any())
|
||||||
|
->method('getAudioKiloBitrate')
|
||||||
|
->will($this->returnValue(92));
|
||||||
|
$format2->expects($this->any())
|
||||||
|
->method('getAudioChannels')
|
||||||
|
->will($this->returnValue(2));
|
||||||
|
$format2->expects($this->any())
|
||||||
|
->method('getPasses')
|
||||||
|
->will($this->returnValue(2));
|
||||||
|
$format2->expects($this->any())
|
||||||
|
->method('getAdditionalParameters')
|
||||||
|
->will($this->returnValue(array('foo', 'bar')));
|
||||||
|
|
||||||
$audioFormat = $this->getMock('FFMpeg\Format\AudioInterface');
|
$audioFormat = $this->getMock('FFMpeg\Format\AudioInterface');
|
||||||
$audioFormat->expects($this->any())
|
$audioFormat->expects($this->any())
|
||||||
|
|
@ -289,6 +312,9 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
$audioVideoFormat->expects($this->any())
|
$audioVideoFormat->expects($this->any())
|
||||||
->method('getPasses')
|
->method('getPasses')
|
||||||
->will($this->returnValue(2));
|
->will($this->returnValue(2));
|
||||||
|
$audioVideoFormat->expects($this->any())
|
||||||
|
->method('getAdditionalParameters')
|
||||||
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
$audioVideoFormatSinglePass = $this->getMock('FFMpeg\Format\VideoInterface');
|
$audioVideoFormatSinglePass = $this->getMock('FFMpeg\Format\VideoInterface');
|
||||||
$audioVideoFormatSinglePass->expects($this->any())
|
$audioVideoFormatSinglePass->expects($this->any())
|
||||||
|
|
@ -312,6 +338,9 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
$audioVideoFormatSinglePass->expects($this->any())
|
$audioVideoFormatSinglePass->expects($this->any())
|
||||||
->method('getPasses')
|
->method('getPasses')
|
||||||
->will($this->returnValue(1));
|
->will($this->returnValue(1));
|
||||||
|
$audioVideoFormatSinglePass->expects($this->any())
|
||||||
|
->method('getAdditionalParameters')
|
||||||
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
$formatExtra = $this->getMock('FFMpeg\Format\VideoInterface');
|
$formatExtra = $this->getMock('FFMpeg\Format\VideoInterface');
|
||||||
$formatExtra->expects($this->any())
|
$formatExtra->expects($this->any())
|
||||||
|
|
@ -329,6 +358,29 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
$formatExtra->expects($this->any())
|
$formatExtra->expects($this->any())
|
||||||
->method('getPasses')
|
->method('getPasses')
|
||||||
->will($this->returnValue(2));
|
->will($this->returnValue(2));
|
||||||
|
$formatExtra->expects($this->any())
|
||||||
|
->method('getAdditionalParameters')
|
||||||
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
|
$formatExtra2 = $this->getMock('FFMpeg\Format\VideoInterface');
|
||||||
|
$formatExtra2->expects($this->any())
|
||||||
|
->method('getExtraParams')
|
||||||
|
->will($this->returnValue(array('extra', 'param')));
|
||||||
|
$formatExtra2->expects($this->any())
|
||||||
|
->method('getKiloBitrate')
|
||||||
|
->will($this->returnValue(665));
|
||||||
|
$formatExtra2->expects($this->any())
|
||||||
|
->method('getAudioKiloBitrate')
|
||||||
|
->will($this->returnValue(92));
|
||||||
|
$formatExtra2->expects($this->any())
|
||||||
|
->method('getAudioChannels')
|
||||||
|
->will($this->returnValue(2));
|
||||||
|
$formatExtra2->expects($this->any())
|
||||||
|
->method('getPasses')
|
||||||
|
->will($this->returnValue(2));
|
||||||
|
$formatExtra2->expects($this->any())
|
||||||
|
->method('getAdditionalParameters')
|
||||||
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
$listeners = array($this->getMock('Alchemy\BinaryDriver\Listeners\ListenerInterface'));
|
$listeners = array($this->getMock('Alchemy\BinaryDriver\Listeners\ListenerInterface'));
|
||||||
|
|
||||||
|
|
@ -353,6 +405,27 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
->method('getPasses')
|
->method('getPasses')
|
||||||
->will($this->returnValue(2));
|
->will($this->returnValue(2));
|
||||||
|
|
||||||
|
$progressableFormat2 = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\Prog')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$progressableFormat2->expects($this->any())
|
||||||
|
->method('getExtraParams')
|
||||||
|
->will($this->returnValue(array()));
|
||||||
|
$progressableFormat2->expects($this->any())
|
||||||
|
->method('createProgressListener')
|
||||||
|
->will($this->returnValue($listeners));
|
||||||
|
$progressableFormat2->expects($this->any())
|
||||||
|
->method('getKiloBitrate')
|
||||||
|
->will($this->returnValue(666));
|
||||||
|
$progressableFormat2->expects($this->any())
|
||||||
|
->method('getAudioKiloBitrate')
|
||||||
|
->will($this->returnValue(92));
|
||||||
|
$progressableFormat2->expects($this->any())
|
||||||
|
->method('getAudioChannels')
|
||||||
|
->will($this->returnValue(2));
|
||||||
|
$progressableFormat2->expects($this->any())
|
||||||
|
->method('getPasses')
|
||||||
|
->will($this->returnValue(2));
|
||||||
|
|
||||||
$progressableAudioFormat = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\AudioProg')
|
$progressableAudioFormat = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\AudioProg')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$progressableAudioFormat->expects($this->any())
|
$progressableAudioFormat->expects($this->any())
|
||||||
|
|
@ -379,14 +452,14 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
'-y', '-i', __FILE__, '-b:v', '663k',
|
'-y', '-i', __FILE__, '-b:v', '663k',
|
||||||
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
||||||
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
||||||
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '1', '-passlogfile',
|
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', 2, 'foo', 'bar', '-pass', 1, '-passlogfile',
|
||||||
'/target/file',
|
'/target/file',
|
||||||
), array(
|
), array(
|
||||||
'-y', '-i', __FILE__,
|
'-y', '-i', __FILE__,
|
||||||
'-b:v', '663k',
|
'-b:v', '663k',
|
||||||
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
||||||
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
||||||
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
|
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', 2, 'foo', 'bar', '-pass', 2, '-passlogfile',
|
||||||
'/target/file',
|
'/target/file',
|
||||||
)), null, $format),
|
)), null, $format),
|
||||||
array(false, array(array(
|
array(false, array(array(
|
||||||
|
|
@ -436,7 +509,7 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
'-threads', 24, '-b:v', '663k',
|
'-threads', 24, '-b:v', '663k',
|
||||||
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
||||||
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
||||||
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '1', '-passlogfile',
|
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', 2, 'foo', 'bar', '-pass', 1, '-passlogfile',
|
||||||
'/target/file',
|
'/target/file',
|
||||||
), array(
|
), array(
|
||||||
'-y', '-i', __FILE__,
|
'-y', '-i', __FILE__,
|
||||||
|
|
@ -444,9 +517,9 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
'-b:v', '663k',
|
'-b:v', '663k',
|
||||||
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
||||||
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
||||||
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
|
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', 2, 'foo', 'bar', '-pass', 2, '-passlogfile',
|
||||||
'/target/file',
|
'/target/file',
|
||||||
)), null, $format),
|
)), null, $format2),
|
||||||
array(true, array(array(
|
array(true, array(array(
|
||||||
'-y', '-i', __FILE__,
|
'-y', '-i', __FILE__,
|
||||||
'extra', 'param', '-threads', 24, '-b:v', '665k',
|
'extra', 'param', '-threads', 24, '-b:v', '665k',
|
||||||
|
|
@ -461,7 +534,7 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
||||||
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
|
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
|
||||||
'/target/file',
|
'/target/file',
|
||||||
)), null, $formatExtra),
|
)), null, $formatExtra2),
|
||||||
array(false, array(array(
|
array(false, array(array(
|
||||||
'-y', '-i', __FILE__, '-b:v', '666k',
|
'-y', '-i', __FILE__, '-b:v', '666k',
|
||||||
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
|
||||||
|
|
@ -475,7 +548,7 @@ class VideoTest extends AbstractStreamableTestCase
|
||||||
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
|
||||||
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
|
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
|
||||||
'/target/file',
|
'/target/file',
|
||||||
)), $listeners, $progressableFormat),
|
)), $listeners, $progressableFormat2),
|
||||||
array(true, array(array(
|
array(true, array(array(
|
||||||
'-y', '-i', __FILE__,
|
'-y', '-i', __FILE__,
|
||||||
'-threads', 24, '-b:v', '666k',
|
'-threads', 24, '-b:v', '666k',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue