From c7226654828600e0c44ac6689a07e741b32147dd Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 5 Sep 2013 12:09:39 +0200 Subject: [PATCH] Fix Invalid ratio computing --- CHANGELOG.md | 4 ++++ src/FFMpeg/FFProbe/DataMapping/Stream.php | 7 ++++++- .../Tests/FFProbe/DataMapping/StreamTest.php | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8c441d..60ed872 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG --------- +* 0.3.4 (05-09-2013) + + * Fix Invalid ratio computing. + * 0.3.3 (05-09-2013) * Add convenient Stream::getDimensions method to extract video dimension. diff --git a/src/FFMpeg/FFProbe/DataMapping/Stream.php b/src/FFMpeg/FFProbe/DataMapping/Stream.php index e74503e..5c32520 100644 --- a/src/FFMpeg/FFProbe/DataMapping/Stream.php +++ b/src/FFMpeg/FFProbe/DataMapping/Stream.php @@ -89,7 +89,12 @@ class Stream extends AbstractData if ($stream->has($name)) { $ratio = $stream->get($name); if (preg_match('/\d+:\d+/', $ratio)) { - return array_map(function ($int) { return (int) $int; }, explode(':', $ratio)); + $data = array_filter(explode(':', $ratio), function ($int) { + return $int > 0; + }); + if (2 === count($data)) { + return array_map(function ($int) { return (int) $int; }, $data); + } } } diff --git a/tests/FFMpeg/Tests/FFProbe/DataMapping/StreamTest.php b/tests/FFMpeg/Tests/FFProbe/DataMapping/StreamTest.php index c9f9c19..6f71d7e 100644 --- a/tests/FFMpeg/Tests/FFProbe/DataMapping/StreamTest.php +++ b/tests/FFMpeg/Tests/FFProbe/DataMapping/StreamTest.php @@ -82,4 +82,18 @@ class StreamTest extends TestCase $stream = new Stream(array('codec_type' => 'video', 'width' => 960, 'height' => 720, 'sample_aspect_ratio' => '4:3', 'display_aspect_ratio' => '16:9')); $this->assertEquals(new Dimension(1280, 720), $stream->getDimensions()); } + + /** + * @dataProvider provideInvalidRatios + */ + public function testGetDimensionsFromVideoWithInvalidDisplayRatio($invalidRatio) + { + $stream = new Stream(array('codec_type' => 'video', 'width' => 960, 'height' => 720, 'sample_aspect_ratio' => $invalidRatio, 'display_aspect_ratio' => '16:9')); + $this->assertEquals(new Dimension(960, 720), $stream->getDimensions()); + } + + public function provideInvalidRatios() + { + return array(array('0:1'), array('2:1:3')); + } }