ffmpeg-mappable-media/src/FFMpeg/Format/DefaultVideoFormat.php

201 lines
4 KiB
PHP
Raw Normal View History

2012-04-13 10:20:54 +02:00
<?php
2012-04-13 14:34:53 +02:00
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2012-04-13 10:20:54 +02:00
namespace FFMpeg\Format;
2012-04-13 15:42:34 +02:00
/**
* The abstract default Video format
*
* @author Romain Neutron imprec@gmail.com
*/
2012-04-13 12:45:41 +02:00
abstract class DefaultVideoFormat extends DefaultAudioFormat implements VideoFormat
2012-04-13 10:20:54 +02:00
{
protected $width;
protected $height;
2012-04-13 14:15:56 +02:00
protected $frameRate = 25;
2012-04-13 10:20:54 +02:00
protected $videoCodec;
2012-04-13 14:15:56 +02:00
protected $GOPsize = 25;
protected $kiloBitrate = 1000;
2012-04-13 10:20:54 +02:00
public function __construct($width, $height)
{
$this->setDimensions($width, $height);
}
2012-04-13 15:42:34 +02:00
/**
* Returns the width
*
* @return int
*/
2012-04-13 10:20:54 +02:00
public function getWidth()
{
return $this->width;
}
2012-04-13 15:42:34 +02:00
/**
* Returns the height
*
* @return int
*/
2012-04-13 10:20:54 +02:00
public function getHeight()
{
return $this->height;
}
2012-04-13 15:42:34 +02:00
/**
* Set the dimensions
*
* @param int $width The heigth
* @param int $height The width
* @throws \InvalidArgumentException
*/
2012-04-13 10:20:54 +02:00
public function setDimensions($width, $height)
{
if ($width < 1)
{
throw new \InvalidArgumentException('Wrong width value');
}
if ($height < 1)
{
throw new \InvalidArgumentException('Wrong height value');
}
$this->width = $this->getMultiple($width, 16);
$this->height = $this->getMultiple($height, 16);
}
2012-04-13 15:42:34 +02:00
/**
* Returns the framerate
*
* @return int
*/
2012-04-13 10:20:54 +02:00
public function getFrameRate()
{
return $this->frameRate;
}
2012-04-13 15:42:34 +02:00
/**
* Set the framerate
*
* @param int $frameRate
* @throws \InvalidArgumentException
*/
2012-04-13 10:20:54 +02:00
public function setFrameRate($frameRate)
{
if ($frameRate < 1)
{
throw new \InvalidArgumentException('Wrong framerate value');
}
$this->frameRate = (int) $frameRate;
}
2012-04-13 15:42:34 +02:00
/**
* Returns the video codec
*
* @return string
*/
2012-04-13 10:20:54 +02:00
public function getVideoCodec()
{
return $this->videoCodec;
}
2012-04-13 15:42:34 +02:00
/**
* Set the video codec, Should be in the available ones, otherwise an
* exception is thrown
*
* @param string $videoCodec
* @throws \InvalidArgumentException
*/
2012-04-13 10:20:54 +02:00
public function setVideoCodec($videoCodec)
{
if ( ! in_array($videoCodec, $this->getAvailableVideoCodecs()))
{
throw new \InvalidArgumentException('Wrong videocodec value');
}
$this->videoCodec = $videoCodec;
}
2012-04-13 15:42:34 +02:00
/**
* Returns the GOP size
*
* @return int
*/
2012-04-13 10:20:54 +02:00
public function getGOPsize()
{
return $this->GOPsize;
}
2012-04-13 15:42:34 +02:00
/**
* Set the GOP size
*
* @param int $GOPsize
* @throws \InvalidArgumentException
*/
2012-04-13 10:20:54 +02:00
public function setGOPsize($GOPsize)
{
2012-04-13 12:09:11 +02:00
if ($GOPsize < 1)
{
throw new \InvalidArgumentException('Wrong GOP size value');
}
2012-04-13 10:20:54 +02:00
$this->GOPsize = (int) $GOPsize;
}
2012-04-13 15:42:34 +02:00
/**
* Returns the nearest multiple for a value
*
* @param int $value
* @param int $multiple
* @return int
*/
2012-04-13 10:20:54 +02:00
protected function getMultiple($value, $multiple)
{
$modulo = $value % $multiple;
$ret = (int) $multiple;
$halfDistance = $multiple / 2;
if ($modulo <= $halfDistance)
$bound = 'bottom';
else
$bound = 'top';
switch ($bound)
{
default:
case 'top':
$ret = $value + $multiple - $modulo;
break;
case 'bottom':
$ret = $value - $modulo;
break;
}
if ($ret < $multiple)
{
$ret = (int) $multiple;
}
return (int) $ret;
}
2012-04-13 15:42:34 +02:00
/**
* Returns the list of available video codecs for this format
*
* @return array
*/
abstract public function getAvailableVideoCodecs();
2012-04-13 10:20:54 +02:00
2012-04-13 15:42:34 +02:00
}