Rename Interfaces
This commit is contained in:
parent
7003cdd1a9
commit
b1e6eeaf95
14 changed files with 238 additions and 76 deletions
211
src/FFMpeg/Format/Video/DefaultVideo.php
Normal file
211
src/FFMpeg/Format/Video/DefaultVideo.php
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
use FFMpeg\Format\Audio\DefaultAudio;
|
||||
use FFMpeg\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* The abstract default Video format
|
||||
*
|
||||
* @author Romain Neutron imprec@gmail.com
|
||||
*/
|
||||
abstract class DefaultVideo extends DefaultAudio implements InteractiveVideo, ResamplableVideo, ResizableVideo
|
||||
{
|
||||
const RESIZEMODE_FIT = 'fit';
|
||||
const RESIZEMODE_INSET = 'inset';
|
||||
|
||||
protected $width;
|
||||
protected $height;
|
||||
protected $frameRate = 25;
|
||||
protected $resizeMode = self::RESIZEMODE_FIT;
|
||||
protected $videoCodec;
|
||||
protected $GOPsize = 25;
|
||||
protected $kiloBitrate = 1000;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dimensions
|
||||
*
|
||||
* @param integer $width The heigth
|
||||
* @param integer $height The width
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
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 = $width;
|
||||
$this->height = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc)
|
||||
*/
|
||||
public function getComputedDimensions($originalWidth, $originalHeight)
|
||||
{
|
||||
switch ($this->getResizeMode()) {
|
||||
case self::RESIZEMODE_INSET:
|
||||
$originalRatio = $originalWidth / $originalHeight;
|
||||
$targetRatio = $this->width / $this->height;
|
||||
|
||||
if ($targetRatio > $originalRatio) {
|
||||
$height = $this->height;
|
||||
$width = round($originalRatio * $this->height);
|
||||
} else {
|
||||
$width = $this->width;
|
||||
$height = round($this->width / $originalRatio);
|
||||
}
|
||||
break;
|
||||
case self::RESIZEMODE_FIT:
|
||||
default:
|
||||
$width = $this->width;
|
||||
$height = $this->height;
|
||||
break;
|
||||
}
|
||||
|
||||
return array($width, $height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the resize mode
|
||||
*
|
||||
* @param string $mode The mode, one of the self::RESIZEMODE_* constants
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setResizeMode($mode)
|
||||
{
|
||||
if ( ! in_array($mode, array(self::RESIZEMODE_FIT, self::RESIZEMODE_INSET))) {
|
||||
throw new InvalidArgumentException(
|
||||
'Resize mode `%s` is not valid , avalaible values are %s',
|
||||
$mode,
|
||||
implode(', ', array(self::RESIZEMODE_FIT, self::RESIZEMODE_INSET))
|
||||
);
|
||||
}
|
||||
|
||||
$this->resizeMode = $mode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getResizeMode()
|
||||
{
|
||||
return $this->resizeMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFrameRate()
|
||||
{
|
||||
return $this->frameRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the framerate
|
||||
*
|
||||
* @param integer $frameRate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setFrameRate($frameRate)
|
||||
{
|
||||
if ($frameRate < 1) {
|
||||
throw new InvalidArgumentException('Wrong framerate value');
|
||||
}
|
||||
|
||||
$this->frameRate = (int) $frameRate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getVideoCodec()
|
||||
{
|
||||
return $this->videoCodec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the video codec, Should be in the available ones, otherwise an
|
||||
* exception is thrown
|
||||
*
|
||||
* @param string $videoCodec
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setVideoCodec($videoCodec)
|
||||
{
|
||||
if ( ! in_array($videoCodec, $this->getAvailableVideoCodecs())) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Wrong videocodec value for %s, available formats are %s'
|
||||
, $videoCodec, implode(', ', $this->getAvailableVideoCodecs())
|
||||
));
|
||||
}
|
||||
|
||||
$this->videoCodec = $videoCodec;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGOPsize()
|
||||
{
|
||||
return $this->GOPsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the GOP size
|
||||
*
|
||||
* @param integer $GOPsize
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setGOPsize($GOPsize)
|
||||
{
|
||||
if ($GOPsize < 1) {
|
||||
throw new InvalidArgumentException('Wrong GOP size value');
|
||||
}
|
||||
|
||||
$this->GOPsize = (int) $GOPsize;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
32
src/FFMpeg/Format/Video/InteractiveVideo.php
Normal file
32
src/FFMpeg/Format/Video/InteractiveVideo.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
use FFMpeg\Format\Video as BaseVideo;
|
||||
|
||||
/**
|
||||
* The interactive video interface. This provide a method to list available
|
||||
* codecs. This is usefull to build interactive development and switch between
|
||||
* different codecs
|
||||
*
|
||||
* @author Romain Neutron imprec@gmail.com
|
||||
*/
|
||||
interface InteractiveVideo extends BaseVideo
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the list of available video codecs for this format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableVideoCodecs();
|
||||
}
|
||||
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
use FFMpeg\Format\DefaultVideo;
|
||||
|
||||
/**
|
||||
* The Ogg video format
|
||||
*
|
||||
|
|
|
|||
39
src/FFMpeg/Format/Video/ResamplableVideo.php
Normal file
39
src/FFMpeg/Format/Video/ResamplableVideo.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
use FFMpeg\Format\Video as BaseVideo;
|
||||
|
||||
/**
|
||||
* The resamplable video interface
|
||||
*
|
||||
* This interface provides frame rate and GOP size settings for video encoding
|
||||
*
|
||||
* @author Romain Neutron imprec@gmail.com
|
||||
*/
|
||||
interface ResamplableVideo extends BaseVideo
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the frame rate
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getFrameRate();
|
||||
|
||||
/**
|
||||
* Returns the GOP size
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getGOPSize();
|
||||
}
|
||||
58
src/FFMpeg/Format/Video/ResizableVideo.php
Normal file
58
src/FFMpeg/Format/Video/ResizableVideo.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
use FFMpeg\Format\Video as BaseVideo;
|
||||
|
||||
/**
|
||||
* The resizable video interface
|
||||
*
|
||||
* This interface provides methods for video resizing.
|
||||
*
|
||||
* @author Romain Neutron imprec@gmail.com
|
||||
*/
|
||||
interface ResizableVideo extends BaseVideo
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the width setting.
|
||||
* The return of this method should not depend on a media file size
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getWidth();
|
||||
|
||||
/**
|
||||
* Returns the height setting
|
||||
* The return of this method should not depend on a media file size
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getHeight();
|
||||
|
||||
/**
|
||||
* Returns the computed dimensions for the resize, after operation.
|
||||
* This method return the actual dimensions that FFmpeg will use.
|
||||
*
|
||||
* @param integer $originalWidth
|
||||
* @param integer $originalHeight
|
||||
* @return array An indexed array containing the width and the height
|
||||
*/
|
||||
public function getComputedDimensions($originalWidth, $originalHeight);
|
||||
|
||||
/**
|
||||
* Get the current resize mode name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResizeMode();
|
||||
}
|
||||
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
use FFMpeg\Format\DefaultVideo;
|
||||
|
||||
/**
|
||||
* The WebM video format
|
||||
*
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
use FFMpeg\Format\DefaultVideo;
|
||||
|
||||
/**
|
||||
* The X264 video format
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue