ffmpeg-mappable-media/tests/src/FFMpeg/FFMpegTest.php

243 lines
5.9 KiB
PHP
Raw Normal View History

2012-04-13 10:20:54 +02:00
<?php
namespace FFMpeg;
2012-05-25 16:21:16 +02:00
use Monolog\Logger;
use Monolog\Handler\NullHandler;
2012-04-13 10:20:54 +02:00
class FFMpegTest extends \PHPUnit_Framework_TestCase
{
/**
* @var FFMpeg
*/
protected $object;
2012-04-13 11:01:01 +02:00
/**
* @var FFProbe
*/
protected $probe;
2012-05-25 16:21:16 +02:00
protected $logger;
2012-04-13 11:01:01 +02:00
public function setUp()
{
2012-05-25 16:21:16 +02:00
$this->logger = new Logger('tests');
$this->logger->pushHandler(new NullHandler());
$this->object = FFMpeg::load($this->logger);
$this->probe = FFProbe::load($this->logger);
$this->object->setProber($this->probe);
2012-04-13 11:01:01 +02:00
}
/**
* @covers FFMpeg\FFMpeg::open
* @expectedException \InvalidArgumentException
*/
public function testOpenInvalid()
{
$this->object->open(__DIR__ . '/invalid.files');
}
2012-04-13 10:20:54 +02:00
/**
* @covers FFMpeg\FFMpeg::open
*/
public function testOpen()
{
2012-04-13 11:01:01 +02:00
$this->object->open(__DIR__ . '/../../files/Test.ogv');
2012-04-13 10:20:54 +02:00
}
/**
* @covers FFMpeg\FFMpeg::extractImage
*/
public function testExtractImage()
{
2012-04-13 11:01:01 +02:00
$dest = __DIR__ . '/../../files/extract_Test.jpg';
$this->object->open(__DIR__ . '/../../files/Test.ogv');
$this->object->extractImage(2, $dest);
$this->probe->probeFormat($dest);
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::extractImage
*/
public function testExtractImagePng()
{
$dest = __DIR__ . '/../../files/extract_Test.png';
$this->object->open(__DIR__ . '/../../files/Test.ogv');
$this->object->extractImage(2, $dest);
$this->probe->probeFormat($dest);
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::extractImage
*/
public function testExtractImageGif()
{
$dest = __DIR__ . '/../../files/extract_Test.gif';
$this->object->open(__DIR__ . '/../../files/Test.ogv');
$this->object->extractImage(2, $dest);
2012-04-13 11:01:01 +02:00
$this->probe->probeFormat($dest);
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::extractImage
2012-04-13 15:26:57 +02:00
* @expectedException \FFMpeg\Exception\LogicException
2012-04-13 11:01:01 +02:00
*/
public function testExtractImageNoMovie()
{
$this->object->extractImage(2, 'Path');
2012-04-13 10:20:54 +02:00
}
/**
* @covers FFMpeg\FFMpeg::encode
2012-04-13 15:26:57 +02:00
* @expectedException \FFMpeg\Exception\LogicException
2012-04-13 10:20:54 +02:00
*/
2012-04-13 11:01:01 +02:00
public function testEncode()
2012-04-13 10:20:54 +02:00
{
2012-05-25 18:24:37 +02:00
$format = new Format\Video\WebM();
$format-> setDimensions(32, 32);
$this->object->encode($format, './invalid.file');
2012-04-13 11:01:01 +02:00
}
2012-04-13 10:20:54 +02:00
2012-04-13 11:01:01 +02:00
/**
* @covers FFMpeg\FFMpeg::encode
* @expectedException \RuntimeException
*/
public function testWrongBinary()
{
$logger = new \Monolog\Logger('test');
$logger->pushHandler(new \Monolog\Handler\NullHandler());
2012-04-13 10:20:54 +02:00
2012-04-13 11:01:01 +02:00
$ffmpeg = new FFMpeg('wrongbinary', $logger);
$ffmpeg->setProber($this->probe);
2012-04-13 10:20:54 +02:00
$ffmpeg->open(__DIR__ . '/../../files/Test.ogv');
2012-05-25 18:24:37 +02:00
$format = new Format\Video\WebM();
$format-> setDimensions(32, 32);
$ffmpeg->encode($format, './invalid.file');
2012-04-13 11:01:01 +02:00
}
/**
* @covers FFMpeg\FFMpeg::encode
2012-04-13 14:15:56 +02:00
* @covers FFMpeg\FFMpeg::encodeAudio
*/
public function testEncodeMp3()
{
$dest = __DIR__ . '/../../files/encode_test.mp3';
$this->object->open(__DIR__ . '/../../files/Audio.mp3');
$this->object->encode(new Format\Audio\Mp3(), $dest);
$this->probe->probeFormat($dest);
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::encode
* @covers FFMpeg\FFMpeg::encodeAudio
*/
public function testEncodeFlac()
{
$dest = __DIR__ . '/../../files/encode_test.flac';
$this->object->open(__DIR__ . '/../../files/Audio.mp3');
$this->object->encode(new Format\Audio\Flac(), $dest);
$this->probe->probeFormat($dest);
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::encode
* @covers FFMpeg\FFMpeg::encodeVideo
2012-04-13 11:01:01 +02:00
*/
public function testEncodeWebm()
{
$dest = __DIR__ . '/../../files/encode_test.webm';
2012-05-25 18:24:37 +02:00
$format = new Format\Video\WebM();
$format-> setDimensions(32, 32);
2012-04-13 11:01:01 +02:00
$this->object->open(__DIR__ . '/../../files/Test.ogv');
2012-05-25 18:24:37 +02:00
$this->object->encode($format, $dest);
2012-04-13 10:20:54 +02:00
2012-04-13 11:01:01 +02:00
$this->probe->probeFormat($dest);
2012-04-13 10:20:54 +02:00
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::encode
2012-04-13 14:15:56 +02:00
* @covers FFMpeg\FFMpeg::encodeVideo
2012-04-13 10:20:54 +02:00
*/
public function testEncodeOgg()
{
$dest = __DIR__ . '/../../files/encode_test.ogv';
2012-05-25 18:24:37 +02:00
$format = new Format\Video\Ogg();
$format->setDimensions(32, 32);
2012-05-25 18:27:18 +02:00
2012-04-13 11:01:01 +02:00
$this->object->open(__DIR__ . '/../../files/Test.ogv');
2012-05-25 18:24:37 +02:00
$this->object->encode($format, $dest);
2012-04-13 10:20:54 +02:00
2012-04-13 11:01:01 +02:00
$this->probe->probeFormat($dest);
2012-04-13 10:20:54 +02:00
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::encode
2012-04-13 14:15:56 +02:00
* @covers FFMpeg\FFMpeg::encodeVideo
2012-04-13 10:20:54 +02:00
*/
public function testEncodeX264()
{
$dest = __DIR__ . '/../../files/encode_test.mp4';
2012-05-25 18:24:37 +02:00
$format = new Format\Video\WebM();
$format-> setDimensions(32, 32);
2012-04-13 11:01:01 +02:00
$this->object->open(__DIR__ . '/../../files/Test.ogv');
2012-05-25 18:24:37 +02:00
$this->object->encode($format, $dest);
2012-04-13 10:20:54 +02:00
2012-04-13 11:01:01 +02:00
$this->probe->probeFormat($dest);
2012-04-13 10:20:54 +02:00
unlink($dest);
}
/**
* @covers FFMpeg\FFMpeg::getMultiple
*/
public function testGetMultiple()
{
$object = FFMpegTester::load($this->logger);
$this->assertEquals(320, $object->getMultipleTester(321, 16));
$this->assertEquals(320, $object->getMultipleTester(319, 16));
$this->assertEquals(320, $object->getMultipleTester(313, 16));
$this->assertEquals(304, $object->getMultipleTester(312, 16));
$this->assertEquals(336, $object->getMultipleTester(329, 16));
$this->assertEquals(16, $object->getMultipleTester(8, 16));
}
}
class FFMpegTester extends FFMpeg
{
public function getMultipleTester($value, $multiple)
{
return parent::getMultiple($value, $multiple);
}
2012-04-13 10:20:54 +02:00
}