Add ability to share audio filters with video

This commit is contained in:
Romain Neutron 2013-06-25 21:43:01 +02:00
commit d7cf9231af
4 changed files with 68 additions and 25 deletions

View file

@ -15,7 +15,9 @@ use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
use FFMpeg\Filters\Audio\AudioFilters;
use FFMpeg\Format\FormatInterface;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Exception\InvalidArgumentException;
use FFMpeg\Filters\Audio\AudioFilterInterface;
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Format\ProgressableInterface;
class Audio extends AbstractStreamableMedia
@ -35,8 +37,12 @@ class Audio extends AbstractStreamableMedia
*
* @return Audio
*/
public function addFilter(AudioFilterInterface $filter)
public function addFilter(FilterInterface $filter)
{
if (!$filter instanceof AudioFilterInterface) {
throw new InvalidArgumentException('Audio only accepts AudioFilterInterface filters');
}
$this->filters->add($filter);
return $this;

View file

@ -15,12 +15,12 @@ use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
use FFMpeg\Coordinate\TimeCode;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Filters\Video\VideoFilters;
use FFMpeg\Filters\Video\VideoFilterInterface;
use FFMpeg\Format\VideoInterface;
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Format\FormatInterface;
use FFMpeg\Format\ProgressableInterface;
use FFMpeg\Media\Frame;
class Video extends AbstractStreamableMedia
class Video extends Audio
{
/**
* {@inheritdoc}
@ -37,7 +37,7 @@ class Video extends AbstractStreamableMedia
*
* @return Video
*/
public function addFilter(VideoFilterInterface $filter)
public function addFilter(FilterInterface $filter)
{
$this->filters->add($filter);
@ -54,7 +54,7 @@ class Video extends AbstractStreamableMedia
*
* @throws RuntimeException
*/
public function save(VideoInterface $format, $outputPathfile)
public function save(FormatInterface $format, $outputPathfile)
{
$commands = array_merge(array('-y', '-i', $this->pathfile), $format->getExtraParams());
@ -110,17 +110,12 @@ class Video extends AbstractStreamableMedia
$pass1[] = '1';
$pass1[] = '-passlogfile';
$pass1[] = $passPrefix;
$pass1[] = '-an';
$pass1[] = $outputPathfile;
$pass2[] = '-pass';
$pass2[] = '2';
$pass2[] = '-passlogfile';
$pass2[] = $passPrefix;
$pass2[] = '-ac';
$pass2[] = '2';
$pass2[] = '-ar';
$pass2[] = '44100';
$pass2[] = $outputPathfile;
$failure = null;

View file

@ -50,6 +50,27 @@ class AudioTest extends AbstractStreamableTestCase
$audio->addFilter($filter);
}
public function testAddAVideoFilterThrowsException()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
->disableOriginalConstructor()
->getMock();
$audio = new Audio(__FILE__, $driver, $ffprobe);
$audio->setFiltersCollection($filters);
$filter = $this->getMock('FFMpeg\Filters\Video\VideoFilterInterface');
$filters->expects($this->never())
->method('add');
$this->setExpectedException('FFMpeg\Exception\InvalidArgumentException');
$audio->addFilter($filter);
}
public function testSaveWithFailure()
{
$driver = $this->getFFMpegDriverMock();

View file

@ -50,6 +50,27 @@ class VideoTest extends AbstractStreamableTestCase
$video->addFilter($filter);
}
public function testAddAudioFilterAddsAFilter()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
->disableOriginalConstructor()
->getMock();
$video = new Video(__FILE__, $driver, $ffprobe);
$video->setFiltersCollection($filters);
$filter = $this->getMock('FFMpeg\Filters\Audio\AudioFilterInterface');
$filters->expects($this->once())
->method('add')
->with($filter);
$video->addFilter($filter);
}
public function testFrameShouldReturnAFrame()
{
$driver = $this->getFFMpegDriverMock();
@ -277,14 +298,14 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '1', '-passlogfile',
'-an', '/target/file',
'/target/file',
), array(
'-y', '-i', __FILE__,
'-b:v', '663k',
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '2', '-passlogfile',
'-ac', '2', '-ar', '44100', '/target/file',
'/target/file',
)), null, $format),
array(false, array(array(
'-y', '-i', __FILE__,
@ -293,7 +314,7 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '1', '-passlogfile',
'-an', '/target/file',
'/target/file',
), array(
'-y', '-i', __FILE__,
'-vcodec', 'gloubi-boulga-video',
@ -302,7 +323,7 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '2', '-passlogfile',
'-ac', '2', '-ar', '44100', '/target/file',
'/target/file',
)), null, $audioVideoFormat),
array(false, array(array(
'-y', '-i', __FILE__,
@ -310,14 +331,14 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '1', '-passlogfile',
'-an', '/target/file',
'/target/file',
), array(
'-y', '-i', __FILE__,
'extra', 'param', '-b:v', '665k',
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '2', '-passlogfile',
'-ac', '2', '-ar', '44100', '/target/file',
'/target/file',
)), null, $formatExtra),
array(true, array(array(
'-y', '-i', __FILE__,
@ -325,7 +346,7 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '1', '-passlogfile',
'-an', '/target/file',
'/target/file',
), array(
'-y', '-i', __FILE__,
'-threads', 24,
@ -333,7 +354,7 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '2', '-passlogfile',
'-ac', '2', '-ar', '44100', '/target/file',
'/target/file',
)), null, $format),
array(true, array(array(
'-y', '-i', __FILE__,
@ -341,28 +362,28 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '1', '-passlogfile',
'-an', '/target/file',
'/target/file',
), array(
'-y', '-i', __FILE__,
'extra', 'param', '-threads', 24, '-b:v', '665k',
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '2', '-passlogfile',
'-ac', '2', '-ar', '44100', '/target/file',
'/target/file',
)), null, $formatExtra),
array(false, array(array(
'-y', '-i', __FILE__, '-b:v', '666k',
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '1', '-passlogfile',
'-an', '/target/file',
'/target/file',
), array(
'-y', '-i', __FILE__,
'-b:v', '666k',
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '2', '-passlogfile',
'-ac', '2', '-ar', '44100', '/target/file',
'/target/file',
)), $listeners, $progressableFormat),
array(true, array(array(
'-y', '-i', __FILE__,
@ -370,7 +391,7 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '1', '-passlogfile',
'-an', '/target/file',
'/target/file',
), array(
'-y', '-i', __FILE__,
'-threads', 24,
@ -378,7 +399,7 @@ class VideoTest extends AbstractStreamableTestCase
'-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
'-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
'-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '2', '-passlogfile',
'-ac', '2', '-ar', '44100', '/target/file',
'/target/file',
)), $listeners, $progressableFormat),
);
}