Fix compatibility with avconv 0.9

This commit is contained in:
Romain Neutron 2013-12-02 12:47:27 +01:00
commit 18abae55a9
4 changed files with 47 additions and 1 deletions

View file

@ -10,12 +10,20 @@ Check another amazing repo : [PHP FFMpeg extras](https://github.com/alchemy-fr/P
## Your attention please
### How this library works :
This library requires a working FFMpeg install. You will need both FFMpeg and FFProbe binaries to use it.
Be sure that these binaries can be located with system PATH to get the benefit of the binary detection,
otherwise you should have to explicitely give the binaries path on load.
For Windows users : Please find the binaries at http://ffmpeg.zeranoe.com/builds/.
### Known issues :
- Using rotate and resize will produce a corrupted output when using
[libav](http://libav.org/) 0.8. The bug is fixed in version 9. This bug does not
appear in latest ffmpeg version.
## Installation
The recommended way to install PHP-FFMpeg is through [Composer](https://getcomposer.org).

View file

@ -226,8 +226,13 @@ class FFProbe
$parseIsToDo = false;
if ($allowJson && $this->optionsTester->has('-print_format')) {
// allowed in latest PHP-FFmpeg version
$commands[] = '-print_format';
$commands[] = 'json';
} elseif ($allowJson && $this->optionsTester->has('-of')) {
// option has changed in avconv 9
$commands[] = '-of';
$commands[] = 'json';
} else {
$parseIsToDo = true;
}

View file

@ -6,6 +6,9 @@ use FFMpeg\FFMpeg;
abstract class FunctionalTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @return FFMpeg
*/
public function getFFMpeg()
{
return FFMpeg::create(array('timeout' => 300));

View file

@ -9,7 +9,7 @@ use FFMpeg\Format\Video\X264;
use FFMpeg\Media\Video;
class VideoTranscodeTest extends FunctionalTestCase
{
{
public function testSimpleTranscodeX264()
{
$filename = __DIR__ . '/output/output-x264.mp4';
@ -60,6 +60,12 @@ class VideoTranscodeTest extends FunctionalTestCase
public function testTranscodePortraitVideo()
{
$info = $this->getNameAndVersion();
if ($info['name'] === 'avconv' && version_compare($info['version'], '0.9', '<')) {
$this->markTestSkipped('This version of avconv is buggy and does not support this test.');
}
$filename = __DIR__ . '/output/output-x264.mp4';
if (is_file($filename)) {
unlink(__DIR__ . '/output/output-x264.mp4');
@ -85,4 +91,28 @@ class VideoTranscodeTest extends FunctionalTestCase
$this->assertFileExists($filename);
unlink($filename);
}
private function getNameAndVersion()
{
$binary = $this
->getFFMpeg()
->getFFMpegDriver()
->getProcessBuilderFactory()
->getBinary();
$output = $matches = null;
exec($binary . ' -version 2>&1', $output);
if (!isset($output[0])) {
return array('name' => null, 'version' => null);
}
preg_match('/^([a-z]+)\s+version\s+([0-9\.]+)/i', $output[0], $matches);
if (count($matches) > 0) {
return array('name' => $matches[1], 'version' => $matches[2]);
}
return array('name' => null, 'version' => null);
}
}