Fix Invalid ratio computing

This commit is contained in:
Romain Neutron 2013-09-05 12:09:39 +02:00
commit c722665482
3 changed files with 24 additions and 1 deletions

View file

@ -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.

View file

@ -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);
}
}
}

View file

@ -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'));
}
}