From 169e63a5476dfbc04c81f797eca965a77580f0d1 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 10 Oct 2013 14:59:38 +0200 Subject: [PATCH] Fix video single pass encodings --- src/FFMpeg/Media/Video.php | 3 +- tests/FFMpeg/Tests/Media/VideoTest.php | 57 ++++++++++++++++++++------ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/FFMpeg/Media/Video.php b/src/FFMpeg/Media/Video.php index 082f168..b51549a 100644 --- a/src/FFMpeg/Media/Video.php +++ b/src/FFMpeg/Media/Video.php @@ -124,9 +124,10 @@ class Video extends Audio $pass[] = $i; $pass[] = '-passlogfile'; $pass[] = $passPrefix; - $pass[] = $outputPathfile; } + $pass[] = $outputPathfile; + $passes[] = $pass; } diff --git a/tests/FFMpeg/Tests/Media/VideoTest.php b/tests/FFMpeg/Tests/Media/VideoTest.php index de3985d..e0f0ee9 100644 --- a/tests/FFMpeg/Tests/Media/VideoTest.php +++ b/tests/FFMpeg/Tests/Media/VideoTest.php @@ -194,7 +194,7 @@ class VideoTest extends AbstractStreamableTestCase $capturedCommands = array(); $capturedListeners = null; - $driver->expects($this->exactly(2)) + $driver->expects($this->exactly(count($expectedCommands))) ->method('command') ->with($this->isType('array'), false, $this->anything()) ->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommands, &$capturedListeners) { @@ -207,22 +207,24 @@ class VideoTest extends AbstractStreamableTestCase $video = new Video(__FILE__, $driver, $ffprobe); $video->save($format, $outputPathfile); - $prefix = null; - foreach ($capturedCommands as $passKey => $pass) { - foreach ($pass as $command) { - $prefix = null; - if (false !== strpos($command, '/pass-')) { - $prefix = $command; - break; + $prefix = null; + if (count($expectedCommands) > 1) { + // look for pass commands only in multipass cases + foreach ($pass as $command) { + $prefix = null; + if (false !== strpos($command, '/pass-')) { + $prefix = $command; + break; + } + } + + if (null === $prefix) { + $this->fail('Unable to find pass prefix command.'); } } - if (null === $prefix) { - $this->fail('Unable to find pass prefix command.'); - } - - $found = false; + $found = false || (null === $prefix); foreach ($pass as $key => $command) { if ($command === $prefix) { $found = true; @@ -277,6 +279,26 @@ class VideoTest extends AbstractStreamableTestCase ->method('getPasses') ->will($this->returnValue(2)); + $audioVideoFormatSinglePass = $this->getMock('FFMpeg\Format\VideoInterface'); + $audioVideoFormatSinglePass->expects($this->any()) + ->method('getExtraParams') + ->will($this->returnValue(array())); + $audioVideoFormatSinglePass->expects($this->any()) + ->method('getVideoCodec') + ->will($this->returnValue('gloubi-boulga-video')); + $audioVideoFormatSinglePass->expects($this->any()) + ->method('getAudioCodec') + ->will($this->returnValue('patati-patata-audio')); + $audioVideoFormatSinglePass->expects($this->any()) + ->method('getKiloBitrate') + ->will($this->returnValue(664)); + $audioVideoFormatSinglePass->expects($this->any()) + ->method('getAudioKiloBitrate') + ->will($this->returnValue(92)); + $audioVideoFormatSinglePass->expects($this->any()) + ->method('getPasses') + ->will($this->returnValue(1)); + $formatExtra = $this->getMock('FFMpeg\Format\VideoInterface'); $formatExtra->expects($this->any()) ->method('getExtraParams') @@ -344,6 +366,15 @@ class VideoTest extends AbstractStreamableTestCase '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-pass', '2', '-passlogfile', '/target/file', )), null, $audioVideoFormat), + array(false, array(array( + '-y', '-i', __FILE__, + '-vcodec', 'gloubi-boulga-video', + '-acodec', 'patati-patata-audio', '-b:v', '664k', + '-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', + '/target/file', + )), null, $audioVideoFormatSinglePass), array(false, array(array( '-y', '-i', __FILE__, 'extra', 'param','-b:v', '665k',