Add convenient Stream::getDimensions method to extract video dimension.

This commit is contained in:
Romain Neutron 2013-09-04 19:00:43 +02:00
commit 15711a0e50
5 changed files with 134 additions and 10 deletions

View file

@ -12,6 +12,7 @@
namespace FFMpeg\Filters\Video;
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Video;
use FFMpeg\Format\VideoInterface;
@ -80,23 +81,21 @@ class ResizeFilter implements VideoFilterInterface
*/
public function apply(Video $video, VideoInterface $format)
{
$originalWidth = $originalHeight = null;
$dimensions = null;
$commands = array();
foreach ($video->getStreams() as $stream) {
if ($stream->isVideo()) {
if ($stream->has('width')) {
$originalWidth = $stream->get('width');
}
if ($stream->has('height')) {
$originalHeight = $stream->get('height');
try {
$dimensions = $stream->getDimensions();
} catch (RuntimeException $e) {
}
}
}
$commands = array();
if ($originalHeight !== null && $originalWidth !== null) {
$dimensions = $this->getComputedDimensions(new Dimension($originalWidth, $originalHeight), $format->getModulus());
if (null !== $dimensions) {
$dimensions = $this->getComputedDimensions($dimensions, $format->getModulus());
$commands[] = '-s';
$commands[] = $dimensions->getWidth() . 'x' . $dimensions->getHeight();