[BC] Upgraded dependencies, dropped support for anything below PHP 8.0. (#849)

* GitHub actions + style fixes + updated packages

* Fixed workflows dir

* Support for PHP 8.1 (#1)

* Update README.md

* Revert some changes from upstream
This commit is contained in:
Pascal Baljet 2022-02-09 14:32:43 +01:00 committed by GitHub
commit 111c153428
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
335 changed files with 4394 additions and 28116 deletions

View file

@ -0,0 +1,9 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use Tests\FFMpeg\Unit\TestCase;
abstract class AbstractMediaTestCase extends TestCase
{
}

View file

@ -0,0 +1,38 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
abstract class AbstractStreamableTestCase extends AbstractMediaTestCase
{
public function testGetStreams()
{
$classname = $this->getClassName();
$ffprobe = $this->getFFProbeMock();
$format = $this->getFormatMock();
$ffprobe->expects($this->once())
->method('format')
->with(__FILE__)
->will($this->returnValue($format));
$media = new $classname(__FILE__, $this->getFFMpegDriverMock(), $ffprobe);
$this->assertSame($format, $media->getFormat());
}
public function testGetFormat()
{
$classname = $this->getClassName();
$ffprobe = $this->getFFProbeMock();
$streams = $this->getStreamCollectionMock();
$ffprobe->expects($this->once())
->method('streams')
->with(__FILE__)
->will($this->returnValue($streams));
$media = new $classname(__FILE__, $this->getFFMpegDriverMock(), $ffprobe);
$this->assertSame($streams, $media->getStreams());
}
abstract protected function getClassName();
}

View file

@ -0,0 +1,35 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Media\AdvancedMedia;
class AdvancedMediaTest extends AbstractMediaTestCase
{
public function testGetInputs()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$advancedMedia = new AdvancedMedia([__FILE__, __FILE__], $driver, $ffprobe);
$this->assertSame([__FILE__, __FILE__], $advancedMedia->getInputs());
}
public function testGetInputsCount()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$advancedMedia = new AdvancedMedia([__FILE__, __FILE__], $driver, $ffprobe);
$this->assertEquals(2, $advancedMedia->getInputsCount());
}
public function testFiltersReturnFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$advancedMedia = new AdvancedMedia([__FILE__, __FILE__], $driver, $ffprobe);
$this->assertInstanceOf('FFMpeg\Filters\AdvancedMedia\ComplexFilters', $advancedMedia->filters());
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Format\AudioInterface;
use FFMpeg\Format\ProgressableInterface;
abstract class AudioProg implements ProgressableInterface, AudioInterface
{
}

View file

@ -0,0 +1,341 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Audio;
class AudioTest extends AbstractStreamableTestCase
{
public function testFiltersReturnsAudioFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$audio = new Audio(__FILE__, $driver, $ffprobe);
$this->assertInstanceOf('FFMpeg\Filters\Audio\AudioFilters', $audio->filters());
}
public function testAddFiltersAddsAFilter()
{
$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->getMockBuilder('FFMpeg\Filters\Audio\AudioFilterInterface')->getMock();
$filters->expects($this->once())
->method('add')
->with($filter);
$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->getMockBuilder('FFMpeg\Filters\Video\VideoFilterInterface')->getMock();
$filters->expects($this->never())
->method('add');
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$audio->addFilter($filter);
}
public function testSaveWithFailure()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$outputPathfile = '/target/file';
$format = $this->getMockBuilder('FFMpeg\Format\AudioInterface')->getMock();
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$failure = new RuntimeException('failed to encode');
$driver->expects($this->once())
->method('command')
->will($this->throwException($failure));
$audio = new Audio(__FILE__, $driver, $ffprobe);
$this->expectException('\FFMpeg\Exception\RuntimeException');
$audio->save($format, $outputPathfile);
}
public function testSaveAppliesFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$outputPathfile = '/target/file';
$format = $this->getMockBuilder('FFMpeg\Format\AudioInterface')->getMock();
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$audio = new Audio(__FILE__, $driver, $ffprobe);
$filter = $this->getMockBuilder('FFMpeg\Filters\Audio\AudioFilterInterface')->getMock();
$filter->expects($this->once())
->method('apply')
->with($audio, $format)
->will($this->returnValue(['extra-filter-command']));
$capturedCommands = [];
$driver->expects($this->once())
->method('command')
->with($this->isType('array'), false, $this->anything())
->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommands) {
$capturedCommands[] = $commands;
}));
$audio->addFilter($filter);
$audio->save($format, $outputPathfile);
foreach ($capturedCommands as $commands) {
$this->assertEquals('-y', $commands[0]);
$this->assertEquals('-i', $commands[1]);
$this->assertEquals(__FILE__, $commands[2]);
$this->assertEquals('extra-filter-command', $commands[3]);
}
}
/**
* @dataProvider provideSaveData
*/
public function testSaveShouldSave($threads, $expectedCommands, $expectedListeners, $format)
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$configuration->expects($this->once())
->method('has')
->with($this->equalTo('ffmpeg.threads'))
->will($this->returnValue($threads));
if ($threads) {
$configuration->expects($this->once())
->method('get')
->with($this->equalTo('ffmpeg.threads'))
->will($this->returnValue(24));
} else {
$configuration->expects($this->never())
->method('get');
}
$capturedCommand = $capturedListeners = null;
$driver->expects($this->once())
->method('command')
->with($this->isType('array'), false, $this->anything())
->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommand, &$capturedListeners) {
$capturedCommand = $commands;
$capturedListeners = $listeners;
}));
$outputPathfile = '/target/file';
$audio = new Audio(__FILE__, $driver, $ffprobe);
$audio->save($format, $outputPathfile);
$this->assertEquals($expectedCommands, $capturedCommand);
$this->assertEquals($expectedListeners, $capturedListeners);
}
public function provideSaveData()
{
$format = $this->getMockBuilder('FFMpeg\Format\AudioInterface')->getMock();
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$format->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(663));
$format->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(5));
$audioFormat = $this->getMockBuilder('FFMpeg\Format\AudioInterface')->getMock();
$audioFormat->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$audioFormat->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(664));
$audioFormat->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(5));
$audioFormat->expects($this->any())
->method('getAudioCodec')
->will($this->returnValue('patati-patata-audio'));
$formatExtra = $this->getMockBuilder('FFMpeg\Format\AudioInterface')->getMock();
$formatExtra->expects($this->any())
->method('getExtraParams')
->will($this->returnValue(['extra', 'param']));
$formatExtra->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(665));
$formatExtra->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(5));
$listeners = [$this->getMockBuilder('Alchemy\BinaryDriver\Listeners\ListenerInterface')->getMock()];
$progressableFormat = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\AudioProg')
->disableOriginalConstructor()->getMock();
$progressableFormat->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$progressableFormat->expects($this->any())
->method('createProgressListener')
->will($this->returnValue($listeners));
$progressableFormat->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(666));
$progressableFormat->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(5));
return [
[false, [
'-y', '-i', __FILE__,
'-b:a', '663k',
'-ac', '5',
'/target/file',
], null, $format],
[false, [
'-y', '-i', __FILE__,
'-acodec', 'patati-patata-audio',
'-b:a', '664k',
'-ac', '5',
'/target/file',
], null, $audioFormat],
[false, [
'-y', '-i', __FILE__,
'extra', 'param',
'-b:a', '665k',
'-ac', '5',
'/target/file',
], null, $formatExtra],
[true, [
'-y', '-i', __FILE__,
'-threads', 24,
'-b:a', '663k',
'-ac', '5',
'/target/file',
], null, $format],
[true, [
'-y', '-i', __FILE__,
'extra', 'param',
'-threads', 24,
'-b:a', '665k',
'-ac', '5',
'/target/file',
], null, $formatExtra],
[false, [
'-y', '-i', __FILE__,
'-b:a', '666k',
'-ac', '5',
'/target/file',
], $listeners, $progressableFormat],
[true, [
'-y', '-i', __FILE__,
'-threads', 24,
'-b:a', '666k',
'-ac', '5',
'/target/file',
], $listeners, $progressableFormat],
];
}
public function testSaveShouldNotStoreCodecFiltersInTheMedia()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$configuration->expects($this->any())
->method('has')
->with($this->equalTo('ffmpeg.threads'))
->will($this->returnValue(true));
$configuration->expects($this->any())
->method('get')
->with($this->equalTo('ffmpeg.threads'))
->will($this->returnValue(24));
$capturedCommands = [];
$driver->expects($this->exactly(2))
->method('command')
->with($this->isType('array'), false, $this->anything())
->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommands, &$capturedListeners) {
$capturedCommands[] = $commands;
}));
$outputPathfile = '/target/file';
$format = $this->getMockBuilder('FFMpeg\Format\AudioInterface')->getMock();
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue(['param']));
$audio = new Audio(__FILE__, $driver, $ffprobe);
$audio->save($format, $outputPathfile);
$audio->save($format, $outputPathfile);
$expected = [
'-y', '-i', __FILE__, 'param', '-threads', 24, '/target/file',
];
foreach ($capturedCommands as $capturedCommand) {
$this->assertEquals($expected, $capturedCommand);
}
}
public function getClassName()
{
return 'FFMpeg\Media\Audio';
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Media\Clip;
class ClipTest extends AbstractMediaTestCase
{
/**
* @dataProvider provideBuildOptions
*/
public function testBuildCommand($startValue, $durationValue, $commands)
{
$configuration = $this->getConfigurationMock();
$driver = $this->getFFMpegDriverMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$ffprobe = $this->getFFProbeMock();
$start = $this->getTimeCodeMock();
$start->expects($this->once())
->method('__toString')
->will($this->returnValue($startValue));
$duration = null;
if (null !== $durationValue) {
$duration = $this->getTimeCodeMock();
$duration->expects($this->once())
->method('__toString')
->will($this->returnValue($durationValue));
}
$outputPathfile = '/target/file';
$format = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$format->expects($this->any())
->method('getPasses')
->will($this->returnValue(1));
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$clip = new Clip($this->getVideoMock(__FILE__), $driver, $ffprobe, $start, $duration);
$fc = $clip->getFinalCommand($format, $outputPathfile);
$this->assertCount(1, $fc);
$this->assertStringStartsWith(implode(' ', $commands), $fc[0]);
}
public function provideBuildOptions()
{
return [
['SS01', null, [
'-y', '-ss', 'SS01',
'-i', __FILE__, ],
],
['SS02', 'D02', [
'-y', '-ss', 'SS02',
'-i', __FILE__,
'-t', 'D02', ],
],
];
}
}

View file

@ -0,0 +1,149 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Media\Concat;
use Spatie\TemporaryDirectory\TemporaryDirectory;
class ConcatTest extends AbstractMediaTestCase
{
public function testGetSources()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$concat = new Concat([__FILE__, __FILE__], $driver, $ffprobe);
$this->assertSame([__FILE__, __FILE__], $concat->getSources());
}
public function testFiltersReturnFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$concat = new Concat([__FILE__, __FILE__], $driver, $ffprobe);
$this->assertInstanceOf('FFMpeg\Filters\Concat\ConcatFilters', $concat->filters());
}
public function testAddFiltersAddsAFilter()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
->disableOriginalConstructor()
->getMock();
$filter = $this->getMockBuilder('FFMpeg\Filters\Concat\ConcatFilterInterface')->getMock();
$filters->expects($this->once())
->method('add')
->with($filter);
$concat = new Concat([__FILE__, __FILE__], $driver, $ffprobe);
$concat->setFiltersCollection($filters);
$concat->addFilter($filter);
}
/**
* @dataProvider provideSaveFromSameCodecsOptions
*/
public function testSaveFromSameCodecs($streamCopy, $commands)
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$pathfile = '/target/destination';
array_push($commands, $pathfile);
$driver->expects($this->exactly(1))
->method('command')
->with($this->isType('array'), false, $this->anything())
->will($this->returnCallback(function ($commands, $errors, $listeners) {
}));
$concat = new Concat([__FILE__, 'concat-2.mp4'], $driver, $ffprobe);
$concat->saveFromSameCodecs($pathfile, $streamCopy);
$this->assertEquals('-f', $commands[0]);
$this->assertEquals('concat', $commands[1]);
$this->assertEquals('-safe', $commands[2]);
$this->assertEquals('0', $commands[3]);
$this->assertEquals('-i', $commands[4]);
if (isset($commands[6]) && (0 == strcmp($commands[6], '-c'))) {
$this->assertEquals('-c', $commands[6]);
$this->assertEquals('copy', $commands[7]);
}
}
public function provideSaveFromSameCodecsOptions()
{
$fs = (new TemporaryDirectory())->create();
$tmpFile = $fs->path('ffmpeg-concat');
touch($tmpFile);
return [
[
true,
[
'-f', 'concat',
'-safe', '0',
'-i', $tmpFile,
'-c', 'copy',
],
],
[
false,
[
'-f', 'concat',
'-safe', '0',
'-i', $tmpFile,
],
],
];
}
/**
* @dataProvider provideSaveFromDifferentCodecsOptions
*/
public function testSaveFromDifferentCodecs($commands)
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$format = $this->getFormatInterfaceMock();
$pathfile = '/target/destination';
array_push($commands, $pathfile);
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$driver->expects($this->once())
->method('command')
->with($commands);
$concat = new Concat([__FILE__, 'concat-2.mp4'], $driver, $ffprobe);
$this->assertSame($concat, $concat->saveFromDifferentCodecs($format, $pathfile));
}
public function provideSaveFromDifferentCodecsOptions()
{
return [
[
[
'-i', __FILE__,
'-i', 'concat-2.mp4',
'-filter_complex',
'[0:v:0] [0:a:0] [1:v:0] [1:a:0] concat=n=2:v=1:a=1 [v] [a]',
'-map', '[v]',
'-map', '[a]',
],
],
];
}
}

View file

@ -0,0 +1,108 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Media\Frame;
class FrameTest extends AbstractMediaTestCase
{
public function testGetTimeCode()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$frame = new Frame($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode);
$this->assertSame($timecode, $frame->getTimeCode());
}
public function testFiltersReturnFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$frame = new Frame($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode);
$this->assertInstanceOf('FFMpeg\Filters\Frame\FrameFilters', $frame->filters());
}
public function testAddFiltersAddsAFilter()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
->disableOriginalConstructor()
->getMock();
$filter = $this->getMockBuilder('FFMpeg\Filters\Frame\FrameFilterInterface')->getMock();
$filters->expects($this->once())
->method('add')
->with($filter);
$frame = new Frame($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode);
$frame->setFiltersCollection($filters);
$frame->addFilter($filter);
}
/**
* @dataProvider provideSaveOptions
*/
public function testSave($accurate, $base64, $commands)
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$timecode->expects($this->once())
->method('__toString')
->will($this->returnValue('timecode'));
$pathfile = '/target/destination';
if (!$base64) {
array_push($commands, $pathfile);
}
$driver->expects($this->once())
->method('command')
->with($commands);
if (!$base64) {
$frame = new Frame($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode);
$this->assertSame($frame, $frame->save($pathfile, $accurate, $base64));
} else {
$frame = new Frame($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode);
$frame->save($pathfile, $accurate, $base64);
}
}
public function provideSaveOptions()
{
return [
[false, false, [
'-y', '-ss', 'timecode',
'-i', __FILE__,
'-vframes', '1',
'-f', 'image2', ],
],
[true, false, [
'-y', '-i', __FILE__,
'-vframes', '1', '-ss', 'timecode',
'-f', 'image2', ],
],
[false, true, [
'-y', '-ss', 'timecode',
'-i', __FILE__,
'-vframes', '1',
'-f', 'image2pipe', '-', ],
],
[true, true, [
'-y', '-i', __FILE__,
'-vframes', '1', '-ss', 'timecode',
'-f', 'image2pipe', '-', ],
],
];
}
}

View file

@ -0,0 +1,116 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Media\Gif;
class GifTest extends AbstractMediaTestCase
{
public function testGetTimeCode()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$dimension = $this->getDimensionMock();
$gif = new Gif($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode, $dimension);
$this->assertSame($timecode, $gif->getTimeCode());
}
public function testGetDimension()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$dimension = $this->getDimensionMock();
$gif = new Gif($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode, $dimension);
$this->assertSame($dimension, $gif->getDimension());
}
public function testFiltersReturnFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$dimension = $this->getDimensionMock();
$gif = new Gif($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode, $dimension);
$this->assertInstanceOf('FFMpeg\Filters\Gif\GifFilters', $gif->filters());
}
public function testAddFiltersAddsAFilter()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$dimension = $this->getDimensionMock();
$filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
->disableOriginalConstructor()
->getMock();
$filter = $this->getMockBuilder('FFMpeg\Filters\Gif\GifFilterInterface')->getMock();
$filters->expects($this->once())
->method('add')
->with($filter);
$gif = new Gif($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode, $dimension);
$gif->setFiltersCollection($filters);
$gif->addFilter($filter);
}
/**
* @dataProvider provideSaveOptions
*/
public function testSave($dimension, $duration, $commands)
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$timecode = $this->getTimeCodeMock();
$timecode->expects($this->once())
->method('__toString')
->will($this->returnValue('timecode'));
$pathfile = '/target/destination';
array_push($commands, $pathfile);
$driver->expects($this->once())
->method('command')
->with($commands);
$gif = new Gif($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode, $dimension, $duration);
$this->assertSame($gif, $gif->save($pathfile));
}
public function provideSaveOptions()
{
return [
[
new Dimension(320, 240), 3,
[
'-ss', 'timecode',
'-t', '3',
'-i', __FILE__,
'-vf',
'scale=320:-1', '-gifflags',
'+transdiff', '-y',
],
],
[
new Dimension(320, 240), null,
[
'-ss', 'timecode',
'-i', __FILE__,
'-vf',
'scale=320:-1', '-gifflags',
'+transdiff', '-y',
],
],
];
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Format\ProgressableInterface;
use FFMpeg\Format\VideoInterface;
abstract class Prog implements ProgressableInterface, VideoInterface
{
}

View file

@ -0,0 +1,713 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Format\Video\X264;
use FFMpeg\Media\Video;
class VideoTest extends AbstractStreamableTestCase
{
public function testFiltersReturnsVideoFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$video = new Video(__FILE__, $driver, $ffprobe);
$this->assertInstanceOf('FFMpeg\Filters\Video\VideoFilters', $video->filters());
}
public function testAddFiltersAddsAFilter()
{
$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->getMockBuilder('FFMpeg\Filters\Video\VideoFilterInterface')->getMock();
$filters->expects($this->once())
->method('add')
->with($filter);
$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->getMockBuilder('FFMpeg\Filters\Audio\AudioFilterInterface')->getMock();
$filters->expects($this->once())
->method('add')
->with($filter);
$video->addFilter($filter);
}
public function testFrameShouldReturnAFrame()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$at = $this->getTimeCodeMock();
$video = new Video(__FILE__, $driver, $ffprobe);
$frame = $video->frame($at);
$this->assertInstanceOf('FFMpeg\Media\Frame', $frame);
$this->assertSame($at, $frame->getTimeCode());
$this->assertSame(__FILE__, $frame->getPathfile());
}
public function testSaveWithFailure()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$outputPathfile = '/target/file';
$format = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$format->expects($this->any())
->method('getPasses')
->will($this->returnValue(1));
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$failure = new RuntimeException('failed to encode');
$driver->expects($this->once())
->method('command')
->will($this->throwException($failure));
$video = new Video(__FILE__, $driver, $ffprobe);
$this->expectException('\FFMpeg\Exception\RuntimeException');
$video->save($format, $outputPathfile);
}
public function testSaveAppliesFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$outputPathfile = '/target/file';
$format = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$format->expects($this->any())
->method('getPasses')
->will($this->returnValue(2));
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$video = new Video(__FILE__, $driver, $ffprobe);
$filter = $this->getMockBuilder('FFMpeg\Filters\Video\VideoFilterInterface')->getMock();
$filter->expects($this->once())
->method('apply')
->with($video, $format)
->will($this->returnValue(['extra-filter-command']));
$capturedCommands = [];
$driver->expects($this->exactly(2))
->method('command')
->with($this->isType('array'), false, $this->anything())
->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommands) {
$capturedCommands[] = $commands;
}));
$video->addFilter($filter);
$video->save($format, $outputPathfile);
foreach ($capturedCommands as $commands) {
$this->assertEquals('-y', $commands[0]);
$this->assertEquals('-i', $commands[1]);
$this->assertEquals(__FILE__, $commands[2]);
$this->assertEquals('extra-filter-command', $commands[3]);
}
}
/**
* @dataProvider provideSaveData
*/
public function testSaveShouldSave($threads, $expectedCommands, $expectedListeners, $format)
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$configuration->expects($this->once())
->method('has')
->with($this->equalTo('ffmpeg.threads'))
->will($this->returnValue($threads));
if ($threads) {
$configuration->expects($this->once())
->method('get')
->with($this->equalTo('ffmpeg.threads'))
->will($this->returnValue(24));
} else {
$configuration->expects($this->never())
->method('get');
}
$capturedCommands = [];
$capturedListeners = null;
$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) {
$capturedCommands[] = $commands;
$capturedListeners = $listeners;
}));
$outputPathfile = '/target/file';
$video = new Video(__FILE__, $driver, $ffprobe);
$video->save($format, $outputPathfile);
foreach ($capturedCommands as $passKey => $pass) {
$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.');
}
}
$found = false || (null === $prefix);
foreach ($pass as $key => $command) {
if ($command === $prefix) {
$found = true;
unset($capturedCommands[$passKey][$key]);
$capturedCommands[$passKey] = array_values($capturedCommands[$passKey]);
break;
}
}
if (!$found) {
$this->fail('Unable to find pass prefix command back.');
}
}
$this->assertEquals($expectedCommands, $capturedCommands);
$this->assertEquals($expectedListeners, $capturedListeners);
}
public function provideSaveData()
{
$format = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$format->expects($this->any())
->method('getKiloBitrate')
->will($this->returnValue(663));
$format->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(92));
$format->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(2));
$format->expects($this->any())
->method('getPasses')
->will($this->returnValue(2));
$format->expects($this->any())
->method('getAdditionalParameters')
->will($this->returnValue(['foo', 'bar']));
$format2 = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$format2->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$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(['foo', 'bar']));
$audioFormat = $this->getMockBuilder('FFMpeg\Format\AudioInterface')->getMock();
$audioFormat->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$audioFormat->expects($this->any())
->method('getAudioCodec')
->will($this->returnValue('patati-patata-audio'));
$audioFormat->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(92));
$audioFormat->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(2));
$audioFormat->expects($this->any())
->method('getPasses')
->will($this->returnValue(1));
$audioVideoFormat = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$audioVideoFormat->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$audioVideoFormat->expects($this->any())
->method('getVideoCodec')
->will($this->returnValue('gloubi-boulga-video'));
$audioVideoFormat->expects($this->any())
->method('getAudioCodec')
->will($this->returnValue('patati-patata-audio'));
$audioVideoFormat->expects($this->any())
->method('getKiloBitrate')
->will($this->returnValue(664));
$audioVideoFormat->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(92));
$audioVideoFormat->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(2));
$audioVideoFormat->expects($this->any())
->method('getPasses')
->will($this->returnValue(2));
$audioVideoFormat->expects($this->any())
->method('getAdditionalParameters')
->will($this->returnValue([]));
$audioVideoFormatSinglePass = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$audioVideoFormatSinglePass->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$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('getAudioChannels')
->will($this->returnValue(2));
$audioVideoFormatSinglePass->expects($this->any())
->method('getPasses')
->will($this->returnValue(1));
$audioVideoFormatSinglePass->expects($this->any())
->method('getAdditionalParameters')
->will($this->returnValue([]));
$formatExtra = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$formatExtra->expects($this->any())
->method('getExtraParams')
->will($this->returnValue(['extra', 'param']));
$formatExtra->expects($this->any())
->method('getKiloBitrate')
->will($this->returnValue(665));
$formatExtra->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(92));
$formatExtra->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(2));
$formatExtra->expects($this->any())
->method('getPasses')
->will($this->returnValue(2));
$formatExtra->expects($this->any())
->method('getAdditionalParameters')
->will($this->returnValue([]));
$formatExtra2 = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$formatExtra2->expects($this->any())
->method('getExtraParams')
->will($this->returnValue(['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([]));
$listeners = [$this->getMockBuilder('Alchemy\BinaryDriver\Listeners\ListenerInterface')->getMock()];
$progressableFormat = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\Prog')
->disableOriginalConstructor()->getMock();
$progressableFormat->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$progressableFormat->expects($this->any())
->method('createProgressListener')
->will($this->returnValue($listeners));
$progressableFormat->expects($this->any())
->method('getKiloBitrate')
->will($this->returnValue(666));
$progressableFormat->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(92));
$progressableFormat->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(2));
$progressableFormat->expects($this->any())
->method('getPasses')
->will($this->returnValue(2));
$progressableFormat2 = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\Prog')
->disableOriginalConstructor()->getMock();
$progressableFormat2->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$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')
->disableOriginalConstructor()->getMock();
$progressableAudioFormat->expects($this->any())
->method('getExtraParams')
->will($this->returnValue([]));
$progressableAudioFormat->expects($this->any())
->method('getAudioCodec')
->will($this->returnValue('patati-patata-audio'));
$progressableAudioFormat->expects($this->any())
->method('createProgressListener')
->will($this->returnValue($listeners));
$progressableAudioFormat->expects($this->any())
->method('getAudioKiloBitrate')
->will($this->returnValue(92));
$progressableAudioFormat->expects($this->any())
->method('getAudioChannels')
->will($this->returnValue(2));
$progressableAudioFormat->expects($this->any())
->method('getPasses')
->will($this->returnValue(1));
return [
[false, [[
'-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', '-ac', 2, 'foo', 'bar', '-pass', 1, '-passlogfile',
'/target/file',
], [
'-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', '-ac', 2, 'foo', 'bar', '-pass', 2, '-passlogfile',
'/target/file',
]], null, $format],
[false, [[
'-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', '-ac', '2', '-pass', '1', '-passlogfile',
'/target/file',
], [
'-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', '-ac', '2', '-pass', '2', '-passlogfile',
'/target/file',
]], null, $audioVideoFormat],
[false, [[
'-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', '-ac', '2',
'/target/file',
]], null, $audioVideoFormatSinglePass],
[false, [[
'-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', '-ac', '2', '-pass', '1', '-passlogfile',
'/target/file',
], [
'-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', '-ac', '2', '-pass', '2', '-passlogfile',
'/target/file',
]], null, $formatExtra],
[true, [[
'-y', '-i', __FILE__,
'-threads', 24, '-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', '-ac', 2, 'foo', 'bar', '-pass', 1, '-passlogfile',
'/target/file',
], [
'-y', '-i', __FILE__,
'-threads', 24,
'-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', '-ac', 2, 'foo', 'bar', '-pass', 2, '-passlogfile',
'/target/file',
]], null, $format2],
[true, [[
'-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', '-ac', '2', '-pass', '1', '-passlogfile',
'/target/file',
], [
'-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', '-ac', '2', '-pass', '2', '-passlogfile',
'/target/file',
]], null, $formatExtra2],
[false, [[
'-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', '-ac', '2', '-pass', '1', '-passlogfile',
'/target/file',
], [
'-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', '-ac', '2', '-pass', '2', '-passlogfile',
'/target/file',
]], $listeners, $progressableFormat2],
[true, [[
'-y', '-i', __FILE__,
'-threads', 24, '-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', '-ac', '2', '-pass', '1', '-passlogfile',
'/target/file',
], [
'-y', '-i', __FILE__,
'-threads', 24,
'-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', '-ac', '2', '-pass', '2', '-passlogfile',
'/target/file',
]], $listeners, $progressableFormat],
[true, [[
'-y', '-i', __FILE__,
'-threads', 24, '-acodec', 'patati-patata-audio',
'-b:a', '92k', '-ac', '2',
'/target/file',
]], null, $audioFormat],
[true, [[
'-y', '-i', __FILE__,
'-threads', 24, '-acodec', 'patati-patata-audio',
'-b:a', '92k', '-ac', '2',
'/target/file',
]], $listeners, $progressableAudioFormat],
];
}
public function testSaveShouldNotStoreCodecFiltersInTheMedia()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$configuration->expects($this->any())
->method('has')
->with($this->equalTo('ffmpeg.threads'))
->will($this->returnValue(true));
$configuration->expects($this->any())
->method('get')
->with($this->equalTo('ffmpeg.threads'))
->will($this->returnValue(24));
$capturedCommands = [];
$driver->expects($this->exactly(4))
->method('command')
->with($this->isType('array'), false, $this->anything())
->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommands, &$capturedListeners) {
$capturedCommands[] = $commands;
}));
$outputPathfile = '/target/file';
$format = $this->getMockBuilder('FFMpeg\Format\VideoInterface')->getMock();
$format->expects($this->any())
->method('getExtraParams')
->will($this->returnValue(['param']));
$format->expects($this->any())
->method('getPasses')
->will($this->returnValue(2));
$video = new Video(__FILE__, $driver, $ffprobe);
$video->save($format, $outputPathfile);
$video->save($format, $outputPathfile);
$expectedPass1 = [
'-y', '-i', __FILE__, 'param', '-threads', 24, '-b:v', 'k', '-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',
'-pass', '1', '-passlogfile', '/target/file',
];
$expectedPass2 = [
'-y', '-i', __FILE__, 'param', '-threads', 24, '-b:v', 'k', '-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',
'-pass', '2', '-passlogfile', '/target/file',
];
$n = 1;
foreach ($capturedCommands as $capturedCommand) {
$prefix = null;
foreach ($capturedCommand as $command) {
if (false !== strpos($command, '/pass-')) {
$prefix = $command;
break;
}
}
if (null === $prefix) {
$this->fail('Unable to find pass prefix command.');
}
$found = false;
foreach ($capturedCommand as $key => $command) {
if ($command === $prefix) {
$found = true;
unset($capturedCommand[$key]);
$capturedCommand = array_values($capturedCommand);
break;
}
}
if (!$found) {
$this->fail('Unable to find pass prefix command back.');
}
if (0 === $n % 2) {
$this->assertEquals($expectedPass2, $capturedCommand);
} else {
$this->assertEquals($expectedPass1, $capturedCommand);
}
++$n;
}
}
public function testCaseWhereKiloBitRateIsEqualToZero()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$pathfile = '/target/destination';
$outputPathfile = '/target/file';
$format = new X264();
$format->setKiloBitrate(0);
$configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($configuration));
$self = $this;
$driver->expects($this->exactly(1))
->method('command')
->with($this->isType('array'), false, $this->anything())
->will($this->returnCallback(function ($commands, $errors, $listeners) use ($self) {
$self->assertTrue(!in_array('-b:v', $commands));
}));
$video = new Video(__FILE__, $driver, $ffprobe);
$video->save($format, $outputPathfile);
}
public function getClassName()
{
return 'FFMpeg\Media\Video';
}
}

View file

@ -0,0 +1,70 @@
<?php
namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Media\Waveform;
class WaveformTest extends AbstractMediaTestCase
{
public function testFiltersReturnFilters()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$waveform = new Waveform($this->getAudioMock(__FILE__), $driver, $ffprobe, 640, 120);
$this->assertInstanceOf('FFMpeg\Filters\Waveform\WaveformFilters', $waveform->filters());
}
public function testAddFiltersAddsAFilter()
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
->disableOriginalConstructor()
->getMock();
$filter = $this->getMockBuilder('FFMpeg\Filters\Waveform\WaveformFilterInterface')->getMock();
$filters->expects($this->once())
->method('add')
->with($filter);
$waveform = new Waveform($this->getAudioMock(__FILE__), $driver, $ffprobe, 640, 120);
$waveform->setFiltersCollection($filters);
$waveform->addFilter($filter);
}
/**
* @dataProvider provideSaveOptions
*/
public function testSave($commands)
{
$driver = $this->getFFMpegDriverMock();
$ffprobe = $this->getFFProbeMock();
$pathfile = '/tests/files/Audio.mp3';
array_push($commands, $pathfile);
$driver->expects($this->once())
->method('command')
->with($commands);
$waveform = new Waveform($this->getAudioMock(__FILE__), $driver, $ffprobe, 640, 120, array('#FFFFFF'));
$this->assertSame($waveform, $waveform->save($pathfile));
}
public function provideSaveOptions()
{
return [
[
[
'-y', '-i', null, '-filter_complex',
'showwavespic=colors=#FFFFFF:s=640x120',
'-frames:v', '1',
],
],
];
}
}