From 7ee0787183cd0065dd96168583a7b70251c2d5a2 Mon Sep 17 00:00:00 2001 From: Nicholas <39540565+nick-cd@users.noreply.github.com> Date: Tue, 2 Mar 2021 10:30:50 -0500 Subject: [PATCH 1/5] composer ... --prefer-dist now ignores dev files (#783) Suggested by issue: #710 Authored by @nick-cd --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitattributes b/.gitattributes index 7c6f5e1..88dfe64 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,6 @@ .gitignore export-ignore .github export-ignore docs export-ignore +tests export-ignore +phpunit.xml.dist export-ignore +.travis.yml export-ignore From 7a30ef4a3b5358363fa4ee2413624b66a2f99b6a Mon Sep 17 00:00:00 2001 From: h0rn3z0r <8987403+h0rn3z0r@users.noreply.github.com> Date: Tue, 2 Mar 2021 19:45:38 +0300 Subject: [PATCH 2/5] fix readme typo (#694) Co-authored-by: Jens Hausdorf Co-authored-by: Romain Biard --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 97650bc..5cbeab8 100644 --- a/README.md +++ b/README.md @@ -503,7 +503,7 @@ $video The boolean parameter of the save function allows you to use the copy parameter which accelerates drastically the generation of the encoded file. -To concatenate videos encoded with the same codec, do as follow: +To concatenate videos encoded with the different codec, do as follow: ```php // In order to instantiate the video object, you HAVE TO pass a path to a valid video file. From 08ccabcd7739495b577b82c201d0ba167bacd8ae Mon Sep 17 00:00:00 2001 From: 41i 6h0rb4n1 <41i.6h0rb4n1@gmail.com> Date: Wed, 3 Mar 2021 00:24:00 +0330 Subject: [PATCH 3/5] Issue 539 (#759) * Issue running ClipFilter with set to NULL #566 * Can't encode video Fatal error #539 Co-authored-by: Romain Biard --- src/FFMpeg/Format/Video/X264.php | 2 +- src/FFMpeg/Media/AbstractVideo.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/FFMpeg/Format/Video/X264.php b/src/FFMpeg/Format/Video/X264.php index c1fd453..7670910 100644 --- a/src/FFMpeg/Format/Video/X264.php +++ b/src/FFMpeg/Format/Video/X264.php @@ -22,7 +22,7 @@ class X264 extends DefaultVideo /** @var int */ private $passes = 2; - public function __construct($audioCodec = 'libfaac', $videoCodec = 'libx264') + public function __construct($audioCodec = 'aac', $videoCodec = 'libx264') { $this ->setAudioCodec($audioCodec) diff --git a/src/FFMpeg/Media/AbstractVideo.php b/src/FFMpeg/Media/AbstractVideo.php index 339e4da..8384b98 100644 --- a/src/FFMpeg/Media/AbstractVideo.php +++ b/src/FFMpeg/Media/AbstractVideo.php @@ -86,6 +86,10 @@ abstract class AbstractVideo extends Audio // FFMpeg\Format\ProgressListener\AbstractProgressListener class foreach ($filters as $filter) { if ($filter instanceof ClipFilter) { + if ($filter->getDuration() === NULL) { + continue; + } + $duration = $filter->getDuration()->toSeconds(); break; } From afffd627ff31b433782202e26585ff82a7fb8586 Mon Sep 17 00:00:00 2001 From: Ilya Chekalsky Date: Thu, 4 Mar 2021 19:17:34 +0100 Subject: [PATCH 4/5] Add ability to disable -b:v (#767) * adds ability to disable -b:v * Fixed a bug in the way the paths to the test files were defined in the AudioConcatenationTest.php file * Added a test to make sure that a negative kilobit rate returns an exception * Added a test to check that the -b:v options are not set if the kilo bitrate is set to 0 * Disable 2pass when -b:v is disabled Co-Authored-By: Philipp Doblhofer <6283313+philipp-doblhofer@users.noreply.github.com> * Changed the way we call the class FFMpeg\Exception\InvalidArgumentException in tests * Changed the way we call the class FFMpeg\Exception\InvalidArgumentException in tests * Updated the README to include this new option Co-authored-by: Romain Biard Co-authored-by: Philipp Doblhofer <6283313+philipp-doblhofer@users.noreply.github.com> --- README.md | 2 +- src/FFMpeg/Format/Video/DefaultVideo.php | 2 +- src/FFMpeg/Format/Video/X264.php | 2 +- src/FFMpeg/Media/AbstractVideo.php | 7 +++-- tests/Functional/AudioConcatenationTest.php | 12 ++++----- tests/Unit/Format/Video/VideoTestCase.php | 9 ++++++- tests/Unit/Media/VideoTest.php | 30 +++++++++++++++++++++ 7 files changed, 52 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5cbeab8..154455c 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ video. Frames can be extracted. You can transcode videos using the `FFMpeg\Media\Video:save` method. You will pass a `FFMpeg\Format\FormatInterface` for that. -Please note that audio and video bitrate are set on the format. +Please note that audio and video bitrate are set on the format. You can disable the `-b:v` option by setting the kilo bitrate to 0. ```php $format = new FFMpeg\Format\Video\X264(); diff --git a/src/FFMpeg/Format/Video/DefaultVideo.php b/src/FFMpeg/Format/Video/DefaultVideo.php index 9d827bb..733df44 100644 --- a/src/FFMpeg/Format/Video/DefaultVideo.php +++ b/src/FFMpeg/Format/Video/DefaultVideo.php @@ -54,7 +54,7 @@ abstract class DefaultVideo extends DefaultAudio implements VideoInterface */ public function setKiloBitrate($kiloBitrate) { - if ($kiloBitrate < 1) { + if ($kiloBitrate < 0) { throw new InvalidArgumentException('Wrong kiloBitrate value'); } diff --git a/src/FFMpeg/Format/Video/X264.php b/src/FFMpeg/Format/Video/X264.php index 7670910..c6cfb41 100644 --- a/src/FFMpeg/Format/Video/X264.php +++ b/src/FFMpeg/Format/Video/X264.php @@ -81,7 +81,7 @@ class X264 extends DefaultVideo */ public function getPasses() { - return $this->passes; + return $this->getKiloBitrate() === 0 ? 1 : $this->passes; } /** diff --git a/src/FFMpeg/Media/AbstractVideo.php b/src/FFMpeg/Media/AbstractVideo.php index 8384b98..1f68dad 100644 --- a/src/FFMpeg/Media/AbstractVideo.php +++ b/src/FFMpeg/Media/AbstractVideo.php @@ -162,8 +162,11 @@ abstract class AbstractVideo extends Audio } if ($format instanceof VideoInterface) { - $commands[] = '-b:v'; - $commands[] = $format->getKiloBitrate() . 'k'; + if ($format->getKiloBitrate() !== 0) { + $commands[] = '-b:v'; + $commands[] = $format->getKiloBitrate() . 'k'; + } + $commands[] = '-refs'; $commands[] = '6'; $commands[] = '-coder'; diff --git a/tests/Functional/AudioConcatenationTest.php b/tests/Functional/AudioConcatenationTest.php index f4ca197..cac6232 100644 --- a/tests/Functional/AudioConcatenationTest.php +++ b/tests/Functional/AudioConcatenationTest.php @@ -10,22 +10,22 @@ class AudioConcatenationTest extends FunctionalTestCase public function testSimpleAudioFileConcatTest() { $ffmpeg = $this->getFFMpeg(); - + $files = [ - __DIR__ . '/../files/Jahzzar_-_05_-_Siesta.mp3', - __DIR__ . '/../files/02_-_Favorite_Secrets.mp3', + realpath(__DIR__ . '/../files/Jahzzar_-_05_-_Siesta.mp3'), + realpath(__DIR__ . '/../files/02_-_Favorite_Secrets.mp3'), ]; $audio = $ffmpeg->open(reset($files)); $this->assertInstanceOf('FFMpeg\Media\Audio', $audio); - + clearstatcache(); $filename = __DIR__ . '/output/concat-output.mp3'; $audio->concat($files)->saveFromSameCodecs($filename, TRUE); - + $this->assertFileExists($filename); unlink($filename); } -} \ No newline at end of file +} diff --git a/tests/Unit/Format/Video/VideoTestCase.php b/tests/Unit/Format/Video/VideoTestCase.php index 0df42ee..b96b470 100644 --- a/tests/Unit/Format/Video/VideoTestCase.php +++ b/tests/Unit/Format/Video/VideoTestCase.php @@ -39,9 +39,16 @@ abstract class VideoTestCase extends AudioTestCase $this->assertEquals(2560, $format->getKiloBitrate()); } + public function testSetKiloBitrateBelowZero() + { + $this->expectException('FFMpeg\Exception\InvalidArgumentException'); + $format = $this->getFormat(); + $format->setKiloBitrate(-1); + } + public function testSetInvalidVideoCodec() { - $this->expectException('\FFMpeg\Exception\InvalidArgumentException'); + $this->expectException('FFMpeg\Exception\InvalidArgumentException'); $this->getFormat()->setVideoCodec('invalid-random-video-codec'); } diff --git a/tests/Unit/Media/VideoTest.php b/tests/Unit/Media/VideoTest.php index 03c42de..8352c45 100644 --- a/tests/Unit/Media/VideoTest.php +++ b/tests/Unit/Media/VideoTest.php @@ -4,6 +4,7 @@ namespace Tests\FFMpeg\Unit\Media; use FFMpeg\Exception\RuntimeException; use FFMpeg\Media\Video; +use FFMpeg\Format\Video\X264; use Alchemy\BinaryDriver\Exception\ExecutionFailureException; use FFMpeg\Format\VideoInterface; @@ -677,6 +678,35 @@ class VideoTest extends AbstractStreamableTestCase } } + public function testCaseWhereKiloBitRateIsEqualToZero() + { + $driver = $this->getFFMpegDriverMock(); + $ffprobe = $this->getFFProbeMock(); + + $pathfile = '/target/destination'; + $outputPathfile = '/target/file'; + + $format = new X264(); + $format->setKiloBitrate(0); + + $configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock(); + + $driver->expects($this->any()) + ->method('getConfiguration') + ->will($this->returnValue($configuration)); + + $driver->expects($this->exactly(1)) + ->method('command') + ->with($this->isType('array'), false, $this->anything()) + ->will($this->returnCallback(function ($commands, $errors, $listeners) { + var_dump($commands); + $this->assertTrue(!in_array('-b:v', $commands)); + })); + + $video = new Video(__FILE__, $driver, $ffprobe); + $video->save($format, $outputPathfile); + } + public function getClassName() { return 'FFMpeg\Media\Video'; From edc0a7729d8818ed883e77b3d26ceb6d49ec41de Mon Sep 17 00:00:00 2001 From: Romain Biard Date: Mon, 29 Mar 2021 22:20:00 +0200 Subject: [PATCH 5/5] Updated the README (#805) Removed a non-valid link to Windows build and added a link to the FFMPEG download page were all executables can be found. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 154455c..911fb64 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,10 @@ Check another amazing repo: [PHP FFMpeg extras](https://github.com/alchemy-fr/PH ### How this library works: -This library requires a working FFMpeg install. You will need both FFMpeg and FFProbe binaries to use it. +This library requires a working [FFMpeg install](https://ffmpeg.org/download.html). 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 explicitly 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