From 18abae55a9fea75da3f9f03354fd268bf2b3cbc2 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 2 Dec 2013 12:47:27 +0100 Subject: [PATCH] Fix compatibility with avconv 0.9 --- README.md | 8 +++++ src/FFMpeg/FFProbe.php | 5 +++ .../FFMpeg/Functional/FunctionalTestCase.php | 3 ++ .../FFMpeg/Functional/VideoTranscodeTest.php | 32 ++++++++++++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d67c75f..d0c4864 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/src/FFMpeg/FFProbe.php b/src/FFMpeg/FFProbe.php index 7a32105..f4790bd 100644 --- a/src/FFMpeg/FFProbe.php +++ b/src/FFMpeg/FFProbe.php @@ -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; } diff --git a/tests/FFMpeg/Functional/FunctionalTestCase.php b/tests/FFMpeg/Functional/FunctionalTestCase.php index 062bf68..25e6461 100644 --- a/tests/FFMpeg/Functional/FunctionalTestCase.php +++ b/tests/FFMpeg/Functional/FunctionalTestCase.php @@ -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)); diff --git a/tests/FFMpeg/Functional/VideoTranscodeTest.php b/tests/FFMpeg/Functional/VideoTranscodeTest.php index bcc714c..6dde247 100644 --- a/tests/FFMpeg/Functional/VideoTranscodeTest.php +++ b/tests/FFMpeg/Functional/VideoTranscodeTest.php @@ -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); + } }