| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											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'); | 
					
						
							| 
									
										
										
										
											2012-05-12 01:52:43 +02:00
										 |  |  |         $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'); | 
					
						
							| 
									
										
										
										
											2012-04-18 10:36:29 +02:00
										 |  |  |         $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() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-04-18 10:36:29 +02:00
										 |  |  |         $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-04-13 12:45:41 +02:00
										 |  |  |         $this->object->encode(new Format\Video\WebM(32, 32), './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); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         $ffmpeg->open(__DIR__ . '/../../files/Test.ogv'); | 
					
						
							| 
									
										
										
										
											2012-04-13 12:45:41 +02:00
										 |  |  |         $ffmpeg->encode(new Format\Video\WebM(32, 32), './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'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->object->open(__DIR__ . '/../../files/Test.ogv'); | 
					
						
							| 
									
										
										
										
											2012-04-13 12:45:41 +02:00
										 |  |  |         $this->object->encode(new Format\Video\WebM(32, 32), $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-04-13 11:01:01 +02:00
										 |  |  |         $this->object->open(__DIR__ . '/../../files/Test.ogv'); | 
					
						
							| 
									
										
										
										
											2012-04-13 12:45:41 +02:00
										 |  |  |         $this->object->encode(new Format\Video\Ogg(32, 32), $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-04-13 11:01:01 +02:00
										 |  |  |         $this->object->open(__DIR__ . '/../../files/Test.ogv'); | 
					
						
							| 
									
										
										
										
											2012-04-13 12:45:41 +02:00
										 |  |  |         $this->object->encode(new Format\Video\X264(32, 32), $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); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |