Add Audio and Video interfaces

This commit is contained in:
Romain Neutron 2012-04-13 12:45:41 +02:00
commit 94775176c9
14 changed files with 294 additions and 222 deletions

View file

@ -53,7 +53,6 @@ class FFMpegTest extends \PHPUnit_Framework_TestCase
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::extractImage
* @expectedException \RuntimeException
@ -69,7 +68,7 @@ class FFMpegTest extends \PHPUnit_Framework_TestCase
*/
public function testEncode()
{
$this->object->encode(new Format\WebM(32, 32), './invalid.file');
$this->object->encode(new Format\Video\WebM(32, 32), './invalid.file');
}
/**
@ -83,7 +82,7 @@ class FFMpegTest extends \PHPUnit_Framework_TestCase
$ffmpeg = new FFMpeg('wrongbinary', $logger);
$ffmpeg->open(__DIR__ . '/../../files/Test.ogv');
$ffmpeg->encode(new Format\WebM(32, 32), './invalid.file');
$ffmpeg->encode(new Format\Video\WebM(32, 32), './invalid.file');
}
/**
@ -94,7 +93,7 @@ class FFMpegTest extends \PHPUnit_Framework_TestCase
$dest = __DIR__ . '/../../files/encode_test.webm';
$this->object->open(__DIR__ . '/../../files/Test.ogv');
$this->object->encode(new Format\WebM(32, 32), $dest);
$this->object->encode(new Format\Video\WebM(32, 32), $dest);
$this->probe->probeFormat($dest);
@ -109,7 +108,7 @@ class FFMpegTest extends \PHPUnit_Framework_TestCase
$dest = __DIR__ . '/../../files/encode_test.ogv';
$this->object->open(__DIR__ . '/../../files/Test.ogv');
$this->object->encode(new Format\Ogg(32, 32), $dest);
$this->object->encode(new Format\Video\Ogg(32, 32), $dest);
$this->probe->probeFormat($dest);
@ -124,7 +123,7 @@ class FFMpegTest extends \PHPUnit_Framework_TestCase
$dest = __DIR__ . '/../../files/encode_test.mp4';
$this->object->open(__DIR__ . '/../../files/Test.ogv');
$this->object->encode(new Format\X264(32, 32), $dest);
$this->object->encode(new Format\Video\X264(32, 32), $dest);
$this->probe->probeFormat($dest);

View file

@ -0,0 +1,154 @@
<?php
namespace FFMpeg\Format;
require_once dirname(__FILE__) . '/../../../../src/FFMpeg/Format/DefaultAudioFormat.php';
/**
* Test class for DefaultAudioFormat.
* Generated by PHPUnit on 2012-04-13 at 12:32:39.
*/
class DefaultAudioFormatTest extends \PHPUnit_Framework_TestCase
{
/**
* @var DefaultAudioFormat
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new DefaultAudioFormatTester();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::getExtraParams
*/
public function testGetExtraParams()
{
$this->assertEquals('-f format', $this->object->getExtraParams());
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::getAudioCodec
*/
public function testGetAudioCodec()
{
$this->assertEquals('audiocodec1', $this->object->getAudioCodec());
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::setAudioCodec
*/
public function testSetAudioCodec()
{
$this->object->setAudioCodec('audiocodec2');
$this->assertEquals('audiocodec2', $this->object->getAudioCodec());
$this->object->setAudioCodec('audiocodec1');
$this->assertEquals('audiocodec1', $this->object->getAudioCodec());
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::setAudioCodec
* @expectedException \InvalidArgumentException
*/
public function testSetWrongAudioCodec()
{
$this->object->setAudioCodec('audiocodec4');
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::getAudioSampleRate
*/
public function testGetAudioSampleRate()
{
$this->assertEquals(44100, $this->object->getAudioSampleRate());
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::setAudioSampleRate
*/
public function testSetAudioSampleRate()
{
$this->object->setAudioSampleRate(22050);
$this->assertEquals(22050, $this->object->getAudioSampleRate());
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::setAudioSampleRate
* @expectedException \InvalidArgumentException
* @dataProvider getWrongAudioSampleRate
*/
public function testSetWrongAudioSampleRate($samplerate)
{
$this->object->setAudioSampleRate($samplerate);
}
public function getWrongAudioSampleRate()
{
return array(array(-5), array(0));
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::getKiloBitrate
*/
public function testGetKiloBitrate()
{
$this->assertEquals(1000, $this->object->getKiloBitrate());
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::setKiloBitrate
*/
public function testSetKiloBitrate()
{
$this->object->setKiloBitrate(500);
$this->assertEquals(500, $this->object->getKiloBitrate());
}
/**
* @covers FFMpeg\Format\DefaultAudioFormat::setKiloBitrate
* @dataProvider getWrongKiloBitrate
* @expectedException \InvalidArgumentException
*/
public function testSetWrongKiloBitrate($kbrate)
{
$this->object->setKiloBitrate($kbrate);
}
public function getWrongKiloBitrate()
{
return array(array(-5), array(0));
}
}
class DefaultAudioFormatTester extends DefaultAudioFormat
{
protected $audioCodec = 'audiocodec1';
protected function getAvailableAudioCodecs()
{
return array('audiocodec1', 'audiocodec2', 'audiocodec3');
}
public function getExtraParams()
{
return '-f format';
}
}

View file

@ -2,29 +2,33 @@
namespace FFMpeg\Format;
require_once dirname(__FILE__) . '/../../../../src/FFMpeg/Format/DefaultFormat.php';
require_once dirname(__FILE__) . '/../../../../src/FFMpeg/Format/DefaultVideoFormat.php';
/**
* Test class for DefaultFormat.
* Generated by PHPUnit on 2012-04-13 at 11:03:02.
* Test class for DefaultVideoFormat.
* Generated by PHPUnit on 2012-04-13 at 12:32:40.
*/
class DefaultFormatTest extends \PHPUnit_Framework_TestCase
class DefaultVideoFormatTest extends \PHPUnit_Framework_TestCase
{
/**
* @var DefaultFormat
* @var DefaultVideoFormat
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new DefaultFormatTester(320, 240);
$this->object = new DefaultVideoFormatTester(320, 240);
}
/**
* @covers FFMpeg\Format\DefaultFormat::__construct
* @covers FFMpeg\Format\DefaultFormat::getWidth
* @covers FFMpeg\Format\DefaultFormat::getHeight
* @covers FFMpeg\Format\DefaultVideoFormat::__construct
* @covers FFMpeg\Format\DefaultVideoFormat::getWidth
* @covers FFMpeg\Format\DefaultVideoFormat::getHeight
*/
public function testConstruct()
{
@ -33,15 +37,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::getExtraParams
*/
public function testGetExtraParams()
{
$this->assertEquals('-f format', $this->object->getExtraParams());
}
/**
* @covers FFMpeg\Format\DefaultFormat::setDimensions
* @covers FFMpeg\Format\DefaultVideoFormat::setDimensions
*/
public function testSetDimensions()
{
@ -55,7 +51,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::setDimensions
* @covers FFMpeg\Format\DefaultVideoFormat::setDimensions
* @dataProvider getWrongDimensions
* @expectedException \InvalidArgumentException
*/
@ -82,7 +78,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::getFrameRate
* @covers FFMpeg\Format\DefaultVideoFormat::getFrameRate
*/
public function testGetFrameRate()
{
@ -90,7 +86,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::setFrameRate
* @covers FFMpeg\Format\DefaultVideoFormat::setFrameRate
*/
public function testSetFrameRate()
{
@ -99,7 +95,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::setFrameRate
* @covers FFMpeg\Format\DefaultVideoFormat::setFrameRate
* @dataProvider getWrongFrameRates
* @expectedException \InvalidArgumentException
*/
@ -119,67 +115,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::getAudioCodec
*/
public function testGetAudioCodec()
{
$this->assertEquals('audiocodec1', $this->object->getAudioCodec());
}
/**
* @covers FFMpeg\Format\DefaultFormat::setAudioCodec
*/
public function testSetAudioCodec()
{
$this->object->setAudioCodec('audiocodec2');
$this->assertEquals('audiocodec2', $this->object->getAudioCodec());
$this->object->setAudioCodec('audiocodec1');
$this->assertEquals('audiocodec1', $this->object->getAudioCodec());
}
/**
* @covers FFMpeg\Format\DefaultFormat::setAudioCodec
* @expectedException \InvalidArgumentException
*/
public function testSetWrongAudioCodec()
{
$this->object->setAudioCodec('audiocodec4');
}
/**
* @covers FFMpeg\Format\DefaultFormat::getAudioSampleRate
*/
public function testGetAudioSampleRate()
{
$this->assertEquals(44100, $this->object->getAudioSampleRate());
}
/**
* @covers FFMpeg\Format\DefaultFormat::setAudioSampleRate
*/
public function testSetAudioSampleRate()
{
$this->object->setAudioSampleRate(22050);
$this->assertEquals(22050, $this->object->getAudioSampleRate());
}
/**
* @covers FFMpeg\Format\DefaultFormat::setAudioSampleRate
* @expectedException \InvalidArgumentException
* @dataProvider getWrongAudioSampleRate
*/
public function testSetWrongAudioSampleRate($samplerate)
{
$this->object->setAudioSampleRate($samplerate);
}
public function getWrongAudioSampleRate()
{
return array(array(-5), array(0));
}
/**
* @covers FFMpeg\Format\DefaultFormat::getVideoCodec
* @covers FFMpeg\Format\DefaultVideoFormat::getVideoCodec
*/
public function testGetVideoCodec()
{
@ -187,7 +123,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::setVideoCodec
* @covers FFMpeg\Format\DefaultVideoFormat::setVideoCodec
*/
public function testSetVideoCodec()
{
@ -198,7 +134,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::setVideoCodec
* @covers FFMpeg\Format\DefaultVideoFormat::setVideoCodec
* @expectedException \InvalidArgumentException
*/
public function testSetWrongVideoCodec()
@ -207,39 +143,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::getKiloBitrate
*/
public function testGetKiloBitrate()
{
$this->assertEquals(1000, $this->object->getKiloBitrate());
}
/**
* @covers FFMpeg\Format\DefaultFormat::setKiloBitrate
*/
public function testSetKiloBitrate()
{
$this->object->setKiloBitrate(500);
$this->assertEquals(500, $this->object->getKiloBitrate());
}
/**
* @covers FFMpeg\Format\DefaultFormat::setKiloBitrate
* @dataProvider getWrongKiloBitrate
* @expectedException \InvalidArgumentException
*/
public function testSetWrongKiloBitrate($kbrate)
{
$this->object->setKiloBitrate($kbrate);
}
public function getWrongKiloBitrate()
{
return array(array(-5), array(0));
}
/**
* @covers FFMpeg\Format\DefaultFormat::getGOPsize
* @covers FFMpeg\Format\DefaultVideoFormat::getGOPsize
*/
public function testGetGOPsize()
{
@ -247,7 +151,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::setGOPsize
* @covers FFMpeg\Format\DefaultVideoFormat::setGOPsize
*/
public function testSetGOPsize()
{
@ -256,7 +160,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::setGOPsize
* @covers FFMpeg\Format\DefaultVideoFormat::setGOPsize
* @dataProvider getWrongGOPsize
* @expectedException \InvalidArgumentException
*/
@ -271,7 +175,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\DefaultFormat::getMultiple
* @covers FFMpeg\Format\DefaultVideoFormat::getMultiple
*/
public function testGetMultiple()
{
@ -285,7 +189,7 @@ class DefaultFormatTest extends \PHPUnit_Framework_TestCase
}
class DefaultFormatTester extends DefaultFormat
class DefaultVideoFormatTester extends DefaultVideoFormat
{
protected $audioCodec = 'audiocodec1';
@ -312,3 +216,4 @@ class DefaultFormatTester extends DefaultFormat
}
}

View file

@ -1,8 +1,6 @@
<?php
namespace FFMpeg\Format;
require_once dirname(__FILE__) . '/../../../../src/FFMpeg/Format/Ogg.php';
namespace FFMpeg\Format\Video;
class OggTest extends \PHPUnit_Framework_TestCase
{
@ -19,11 +17,11 @@ class OggTest extends \PHPUnit_Framework_TestCase
public function testConstruct()
{
$this->assertInstanceOf('\\FFMpeg\\Format\\DefaultFormat', $this->object);
$this->assertInstanceOf('\\FFMpeg\\Format\\DefaultVideoFormat', $this->object);
}
/**
* @covers FFMpeg\Format\Ogg::getAvailableAudioCodecs
* @covers FFMpeg\Format\Video\Ogg::getAvailableAudioCodecs
*/
public function testGetAvailableAudioCodecs()
{
@ -31,7 +29,7 @@ class OggTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\Ogg::getAvailableVideoCodecs
* @covers FFMpeg\Format\Video\Ogg::getAvailableVideoCodecs
*/
public function testGetAvailableVideoCodecs()
{

View file

@ -1,8 +1,6 @@
<?php
namespace FFMpeg\Format;
require_once dirname(__FILE__) . '/../../../../src/FFMpeg/Format/WebM.php';
namespace FFMpeg\Format\Video;
class WebMTest extends \PHPUnit_Framework_TestCase
{
@ -18,7 +16,7 @@ class WebMTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\WebM::getAvailableAudioCodecs
* @covers FFMpeg\Format\Video\WebM::getAvailableAudioCodecs
*/
public function testGetAvailableAudioCodecs()
{
@ -26,7 +24,7 @@ class WebMTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\WebM::getAvailableVideoCodecs
* @covers FFMpeg\Format\Video\WebM::getAvailableVideoCodecs
*/
public function testGetAvailableVideoCodecs()
{
@ -34,7 +32,7 @@ class WebMTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\WebM::getExtraParams
* @covers FFMpeg\Format\Video\WebM::getExtraParams
*/
public function testGetExtraParams()
{
@ -43,7 +41,7 @@ class WebMTest extends \PHPUnit_Framework_TestCase
public function testConstruct()
{
$this->assertInstanceOf('\\FFMpeg\\Format\\DefaultFormat', $this->object);
$this->assertInstanceOf('\\FFMpeg\\Format\\DefaultVideoFormat', $this->object);
}
}

View file

@ -1,8 +1,6 @@
<?php
namespace FFMpeg\Format;
require_once dirname(__FILE__) . '/../../../../src/FFMpeg/Format/X264.php';
namespace FFMpeg\Format\Video;
class X264Test extends \PHPUnit_Framework_TestCase
{
@ -19,11 +17,11 @@ class X264Test extends \PHPUnit_Framework_TestCase
public function testConstruct()
{
$this->assertInstanceOf('\\FFMpeg\\Format\\DefaultFormat', $this->object);
$this->assertInstanceOf('\\FFMpeg\\Format\\DefaultVideoFormat', $this->object);
}
/**
* @covers FFMpeg\Format\X264::getAvailableAudioCodecs
* @covers FFMpeg\Format\Video\X264::getAvailableAudioCodecs
*/
public function testGetAvailableAudioCodecs()
{
@ -31,12 +29,11 @@ class X264Test extends \PHPUnit_Framework_TestCase
}
/**
* @covers FFMpeg\Format\X264::getAvailableVideoCodecs
* @covers FFMpeg\Format\Video\X264::getAvailableVideoCodecs
*/
public function testGetAvailableVideoCodecs()
{
$this->object->setVideoCodec('libx264');
}
}