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' ); 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; + } } /** diff --git a/src/FFMpeg/FFProbe.php b/src/FFMpeg/FFProbe.php index 7e25b0d..a1a0ba3 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($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'); 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()); + } }