Fix Invalid ratio computing
This commit is contained in:
parent
9b87e44505
commit
c722665482
3 changed files with 24 additions and 1 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue