Version 0.3

This commit is contained in:
Romain Neutron 2013-06-25 10:03:20 +02:00
commit ad3a5af623
130 changed files with 7283 additions and 2627 deletions

View file

@ -0,0 +1,96 @@
<?php
namespace FFMpeg\Tests\Format\Audio;
use FFMpeg\Tests\TestCase;
use FFMpeg\Format\Audio\DefaultAudio;
abstract class AudioTestCase extends TestCase
{
public function testExtraParams()
{
foreach ($this->getFormat()->getExtraParams() as $param) {
$this->assertScalar($param);
}
}
public function testGetAudioCodec()
{
$this->assertScalar($this->getFormat()->getAudioCodec());
$this->assertContains($this->getFormat()->getAudioCodec(), $this->getFormat()->getAvailableAudioCodecs());
}
public function testSetAudioCodec()
{
$format = $this->getFormat();
foreach ($format->getAvailableAudioCodecs() as $codec) {
$format->setAudioCodec($codec);
$this->assertEquals($codec, $format->getAudioCodec());
}
}
/**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/
public function testSetInvalidAudioCodec()
{
$this->getFormat()->setAudioCodec('invalid-random-audio-codec');
}
public function testGetAvailableAudioCodecs()
{
$this->assertGreaterThan(0, count($this->getFormat()->getAvailableAudioCodecs()));
}
public function testGetAudioKiloBitrate()
{
$this->assertInternalType('integer', $this->getFormat()->getAudioKiloBitrate());
}
public function testSetAudioKiloBitrate()
{
$format = $this->getFormat();
$format->setAudioKiloBitrate(256);
$this->assertEquals(256, $format->getAudioKiloBitrate());
}
/**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/
public function testSetInvalidKiloBitrate()
{
$this->getFormat()->setAudioKiloBitrate(0);
}
/**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/
public function testSetNegativeKiloBitrate()
{
$this->getFormat()->setAudioKiloBitrate(-10);
}
public function testCreateProgressListener()
{
$media = $this->getMock('FFMpeg\Media\MediaTypeInterface');
$media->expects($this->any())
->method('getPathfile')
->will($this->returnValue(__FILE__));
$format = $this->getFormat();
$ffprobe = $this->getFFProbeMock();
foreach ($format->createProgressListener($media, $ffprobe, 1, 3) as $listener) {
$this->assertInstanceOf('FFMpeg\Format\ProgressListener\AudioProgressListener', $listener);
$this->assertSame($ffprobe, $listener->getFFProbe());
$this->assertSame(__FILE__, $listener->getPathfile());
$this->assertSame(1, $listener->getCurrentPass());
$this->assertSame(3, $listener->getTotalPass());
}
}
/**
* @return DefaultAudio
*/
abstract public function getFormat();
}

View file

@ -0,0 +1,13 @@
<?php
namespace FFMpeg\Tests\Format\Audio;
use FFMpeg\Format\Audio\Flac;
class FlacTest extends AudioTestCase
{
public function getFormat()
{
return new Flac();
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace FFMpeg\Tests\Format\Audio;
use FFMpeg\Format\Audio\Mp3;
class Mp3Test extends AudioTestCase
{
public function getFormat()
{
return new Mp3();
}
}

View file

@ -0,0 +1,87 @@
<?php
namespace FFMpeg\Tests\Format\ProgressListener;
use FFMpeg\Tests\TestCase;
use FFMpeg\Format\ProgressListener\AudioProgressListener;
use FFMpeg\FFProbe\DataMapping\Format;
class AudioProgressListenerTest extends TestCase
{
/**
* @dataProvider provideData
*/
public function testHandle($size, $duration,
$data, $expectedPercent, $expectedRemaining, $expectedRate,
$data2, $expectedPercent2, $expectedRemaining2, $expectedRate2,
$currentPass, $totalPass
)
{
$ffprobe = $this->getFFProbeMock();
$ffprobe->expects($this->once())
->method('format')
->with(__FILE__)
->will($this->returnValue(new Format(array(
'size' => $size,
'duration' => $duration,
))));
$listener = new AudioProgressListener($ffprobe, __FILE__, $currentPass, $totalPass);
$phpunit = $this;
$n = 0;
$listener->on('progress', function ($percent, $remaining, $rate) use (&$n, $phpunit, $expectedPercent, $expectedRemaining, $expectedRate, $expectedPercent2, $expectedRemaining2, $expectedRate2) {
if (0 === $n) {
$phpunit->assertEquals($expectedPercent, $percent);
$phpunit->assertEquals($expectedRemaining, $remaining);
$phpunit->assertEquals($expectedRate, $rate);
} elseif (1 === $n) {
$phpunit->assertEquals($expectedPercent2, $percent);
$phpunit->assertEquals($expectedRemaining2, $remaining);
$phpunit->assertLessThan($expectedRate2 + 3, $rate);
$phpunit->assertGreaterThan($expectedRate2 - 3, $rate);
}
$n++;
});
// first one does not trigger progress event
$listener->handle('any-type'.mt_rand(), $data);
sleep(1);
$listener->handle('any-type'.mt_rand(), $data);
sleep(1);
$listener->handle('any-type'.mt_rand(), $data2);
$this->assertEquals(2, $n);
}
public function provideData()
{
return array(
array(
2894412,
180.900750,
'size= 712kB time=00:00:45.50 bitrate= 128.1kbits/s',
25,
0,
0,
'size= 1274kB time=00:01:29.32 bitrate= 142.8kbits/s',
49,
2,
563,
1,
1
),
array(
2894412,
180.900750,
'size= 712kB time=00:00:45.50 bitrate= 128.1kbits/s',
12,
0,
0,
'size= 1274kB time=00:01:29.32 bitrate= 142.8kbits/s',
24,
2,
563,
1,
2
)
);
}
}

View file

@ -0,0 +1,87 @@
<?php
namespace FFMpeg\Tests\Format\ProgressListener;
use FFMpeg\Tests\TestCase;
use FFMpeg\Format\ProgressListener\VideoProgressListener;
use FFMpeg\FFProbe\DataMapping\Format;
class VideoProgressListenerTest extends TestCase
{
/**
* @dataProvider provideData
*/
public function testHandle($size, $duration,
$data, $expectedPercent, $expectedRemaining, $expectedRate,
$data2, $expectedPercent2, $expectedRemaining2, $expectedRate2,
$currentPass, $totalPass
)
{
$ffprobe = $this->getFFProbeMock();
$ffprobe->expects($this->once())
->method('format')
->with(__FILE__)
->will($this->returnValue(new Format(array(
'size' => $size,
'duration' => $duration,
))));
$listener = new VideoProgressListener($ffprobe, __FILE__, $currentPass, $totalPass);
$phpunit = $this;
$n = 0;
$listener->on('progress', function ($percent, $remaining, $rate) use (&$n, $phpunit, $expectedPercent, $expectedRemaining, $expectedRate, $expectedPercent2, $expectedRemaining2, $expectedRate2) {
if (0 === $n) {
$phpunit->assertEquals($expectedPercent, $percent);
$phpunit->assertEquals($expectedRemaining, $remaining);
$phpunit->assertEquals($expectedRate, $rate);
} elseif (1 === $n) {
$phpunit->assertEquals($expectedPercent2, $percent);
$phpunit->assertEquals($expectedRemaining2, $remaining);
$phpunit->assertLessThan($expectedRate2 + 10, $rate);
$phpunit->assertGreaterThan($expectedRate2 - 10, $rate);
}
$n++;
});
// first one does not trigger progress event
$listener->handle('any-type'.mt_rand(), $data);
sleep(1);
$listener->handle('any-type'.mt_rand(), $data);
sleep(1);
$listener->handle('any-type'.mt_rand(), $data2);
$this->assertEquals(2, $n);
}
public function provideData()
{
return array(
array(
147073958,
281.147533,
'frame= 206 fps=202 q=10.0 size= 571kB time=00:00:07.12 bitrate= 656.8kbits/s dup=9 drop=0',
2,
0,
0,
'frame= 854 fps=113 q=20.0 size= 4430kB time=00:00:33.04 bitrate=1098.5kbits/s dup=36 drop=0',
11,
32,
3868,
1,
1
),
array(
147073958,
281.147533,
'frame= 206 fps=202 q=10.0 size= 571kB time=00:00:07.12 bitrate= 656.8kbits/s dup=9 drop=0',
1,
0,
0,
'frame= 854 fps=113 q=20.0 size= 4430kB time=00:00:33.04 bitrate=1098.5kbits/s dup=36 drop=0',
5,
32,
3868,
1,
2
)
);
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace FFMpeg\Tests\Format\Video;
use FFMpeg\Format\Video\Ogg;
class OggTest extends VideoTestCase
{
public function getFormat()
{
return new Ogg();
}
}

View file

@ -0,0 +1,85 @@
<?php
namespace FFMpeg\Tests\Format\Video;
use FFMpeg\Tests\Format\Audio\AudioTestCase;
abstract class VideoTestCase extends AudioTestCase
{
public function testGetVideoCodec()
{
$this->assertScalar($this->getFormat()->getVideoCodec());
$this->assertContains($this->getFormat()->getVideoCodec(), $this->getFormat()->getAvailableVideoCodecs());
}
public function testSupportBFrames()
{
$this->assertInternalType('boolean', $this->getFormat()->supportBFrames());
}
public function testSetVideoCodec()
{
$format = $this->getFormat();
foreach ($format->getAvailableVideoCodecs() as $codec) {
$format->setVideoCodec($codec);
$this->assertEquals($codec, $format->getVideoCodec());
}
}
public function testGetKiloBitrate()
{
$this->assertInternalType('integer', $this->getFormat()->getKiloBitrate());
}
public function testSetKiloBitrate()
{
$format = $this->getFormat();
$format->setKiloBitrate(2560);
$this->assertEquals(2560, $format->getKiloBitrate());
}
/**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/
public function testSetInvalidVideoCodec()
{
$this->getFormat()->setVideoCodec('invalid-random-video-codec');
}
public function testGetAvailableVideoCodecs()
{
$this->assertGreaterThan(0, count($this->getFormat()->getAvailableVideoCodecs()));
}
public function testCreateProgressListener()
{
$media = $this->getMock('FFMpeg\Media\MediaTypeInterface');
$media->expects($this->any())
->method('getPathfile')
->will($this->returnValue(__FILE__));
$format = $this->getFormat();
$ffprobe = $this->getFFProbeMock();
foreach ($format->createProgressListener($media, $ffprobe, 1, 3) as $listener) {
$this->assertInstanceOf('FFMpeg\Format\ProgressListener\VideoProgressListener', $listener);
$this->assertSame($ffprobe, $listener->getFFProbe());
$this->assertSame(__FILE__, $listener->getPathfile());
$this->assertSame(1, $listener->getCurrentPass());
$this->assertSame(3, $listener->getTotalPass());
}
}
public function testGetPasses()
{
$this->assertInternalType('integer', $this->getFormat()->getPasses());
$this->assertGreaterThan(0, $this->getFormat()->getPasses());
}
public function testGetModulus()
{
$this->assertInternalType('integer', $this->getFormat()->getModulus());
$this->assertGreaterThan(0, $this->getFormat()->getModulus());
$this->assertEquals(0, $this->getFormat()->getModulus() % 2);
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace FFMpeg\Tests\Format\Video;
use FFMpeg\Format\Video\WMV3;
class WMV3Test extends VideoTestCase
{
public function getFormat()
{
return new WMV3();
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace FFMpeg\Tests\Format\Video;
use FFMpeg\Format\Video\WMV;
class WMVTest extends VideoTestCase
{
public function getFormat()
{
return new WMV();
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace FFMpeg\Tests\Format\Video;
use FFMpeg\Format\Video\WebM;
class WebMTest extends VideoTestCase
{
public function getFormat()
{
return new WebM();
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace FFMpeg\Tests\Format\Video;
use FFMpeg\Format\Video\X264;
class X264Test extends VideoTestCase
{
public function getFormat()
{
return new X264();
}
}