From 3210b1d4fdd703aed410a948d2db55122f7de265 Mon Sep 17 00:00:00 2001 From: Le_Tung Date: Fri, 8 Sep 2017 16:03:14 +0900 Subject: [PATCH 1/5] support crop with dynamic point --- src/FFMpeg/Coordinate/Point.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/FFMpeg/Coordinate/Point.php b/src/FFMpeg/Coordinate/Point.php index c0688e8..710216c 100644 --- a/src/FFMpeg/Coordinate/Point.php +++ b/src/FFMpeg/Coordinate/Point.php @@ -16,10 +16,15 @@ class Point private $x; private $y; - public function __construct($x, $y) + public function __construct($x, $y, $dynamic = false) { - $this->x = (int) $x; - $this->y = (int) $y; + if ($dynamic) { + $this->x = $x; + $this->y = $y; + } else { + $this->x = (int)$x; + $this->y = (int)$y; + } } /** From 47b8d8497924ced78d5287e36a0030d2490e8de7 Mon Sep 17 00:00:00 2001 From: Le_Tung Date: Tue, 19 Sep 2017 10:44:11 +0900 Subject: [PATCH 2/5] add dynamic point Unit Test --- tests/Unit/Coordinate/PointTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Unit/Coordinate/PointTest.php b/tests/Unit/Coordinate/PointTest.php index 09bd22e..4d633ce 100644 --- a/tests/Unit/Coordinate/PointTest.php +++ b/tests/Unit/Coordinate/PointTest.php @@ -13,4 +13,11 @@ class PointTest extends TestCase $this->assertEquals(4, $point->getX()); $this->assertEquals(25, $point->getY()); } + + public function testDynamicPointGetters() + { + $point = new Point("t*100", "t", true); + $this->assertEquals("t*100", $point->getX()); + $this->assertEquals("t", $point->getY()); + } } From 07d1732300d9993fecbbaee1ca5d05a339bf1eab Mon Sep 17 00:00:00 2001 From: Jens Hausdorf Date: Tue, 19 Sep 2017 18:26:00 +0200 Subject: [PATCH 3/5] fix typo; closes #404 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41c9433..af59a56 100644 --- a/README.md +++ b/README.md @@ -178,8 +178,8 @@ $video = $ffmpeg->open( 'video.mp4' ); // Set an audio format $audio_format = new FFMpeg\Format\Audio\Mp3(); -// Extract the audio into a new file -$video->save('audio.mp3'); +// Extract the audio into a new file as mp3 +$video->save($audio_format, 'audio.mp3'); // Set the audio file $audio = $ffmpeg->open( 'audio.mp3' ); From 74a1d6539c569482ffea61e02c4cd16ae7067595 Mon Sep 17 00:00:00 2001 From: jens1o Date: Tue, 19 Sep 2017 19:28:34 +0200 Subject: [PATCH 4/5] Add FFProbe#isValid fixes #394 --- src/FFMpeg/FFProbe.php | 19 +++++++++++++++++++ tests/Functional/FFProbeTest.php | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/FFMpeg/FFProbe.php b/src/FFMpeg/FFProbe.php index 7e25b0d..3468969 100644 --- a/src/FFMpeg/FFProbe.php +++ b/src/FFMpeg/FFProbe.php @@ -170,6 +170,25 @@ class FFProbe return $this->probe($pathfile, '-show_format', static::TYPE_FORMAT); } + /** + * @api + * + * Checks wether the given `$pathfile` is considered a valid media file. + * + * @param string $pathfile + * @return bool + * @since 0.10.0 + */ + public function isValid(string $pathfile) + { + try { + return $this->format($pathfile)->get('duration') > 0; + } catch(\Exception $e) { + // complete invalid data + return false; + } + } + /** * @api * diff --git a/tests/Functional/FFProbeTest.php b/tests/Functional/FFProbeTest.php index 10a98c0..b183e08 100644 --- a/tests/Functional/FFProbeTest.php +++ b/tests/Functional/FFProbeTest.php @@ -12,10 +12,23 @@ class FFProbeTest extends FunctionalTestCase $this->assertGreaterThan(0, count($ffprobe->streams(__DIR__ . '/../files/Audio.mp3'))); } + public function testValidateExistingFile() + { + $ffprobe = FFProbe::create(); + $this->assertTrue($ffprobe->isValid(__DIR__ . '/../files/sample.3gp')); + } + + + public function testValidateNonExistingFile() + { + $ffprobe = FFProbe::create(); + $this->assertFalse($ffprobe->isValid(__DIR__ . '/../files/WrongFile.mp4')); + } + /** * @expectedException FFMpeg\Exception\RuntimeException */ - public function testProbeOnUnexistantFile() + public function testProbeOnNonExistantFile() { $ffprobe = FFProbe::create(); $ffprobe->streams('/path/to/no/file'); From ed5f21e0c8b78e40cb26310fcf5189a6a50f1d84 Mon Sep 17 00:00:00 2001 From: jens1o Date: Tue, 19 Sep 2017 20:18:43 +0200 Subject: [PATCH 5/5] php 5.x has problems with mocking with type hinting... --- src/FFMpeg/FFProbe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FFMpeg/FFProbe.php b/src/FFMpeg/FFProbe.php index 3468969..a1a0ba3 100644 --- a/src/FFMpeg/FFProbe.php +++ b/src/FFMpeg/FFProbe.php @@ -179,7 +179,7 @@ class FFProbe * @return bool * @since 0.10.0 */ - public function isValid(string $pathfile) + public function isValid($pathfile) { try { return $this->format($pathfile)->get('duration') > 0;