Rename Interfaces

This commit is contained in:
grosroro 2012-05-30 12:22:22 +02:00
commit b1e6eeaf95
14 changed files with 238 additions and 76 deletions

View file

@ -11,6 +11,11 @@
namespace FFMpeg\Format;
/**
* The base audio interface
*
* @author Romain Neutron imprec@gmail.com
*/
interface Audio
{
@ -21,13 +26,6 @@ interface Audio
*/
public function getAudioCodec();
/**
* Get the audio sample rate
*
* @return integer
*/
public function getAudioSampleRate();
/**
* Get the kiloBitrate value
*
@ -35,10 +33,4 @@ interface Audio
*/
public function getKiloBitrate();
/**
* Returns the list of available audio codecs for this format
*
* @return array
*/
public function getAvailableAudioCodecs();
}

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace FFMpeg\Format;
namespace FFMpeg\Format\Audio;
use FFMpeg\Exception\InvalidArgumentException;
@ -18,7 +18,7 @@ use FFMpeg\Exception\InvalidArgumentException;
*
* @author Romain Neutron imprec@gmail.com
*/
abstract class DefaultAudio implements Audio
abstract class DefaultAudio implements ResamplableAudio, InteractiveAudio
{
protected $audioCodec;
protected $audioSampleRate = 44100;

View file

@ -11,8 +11,6 @@
namespace FFMpeg\Format\Audio;
use FFMpeg\Format\DefaultAudio;
/**
* The Flac audio format
*

View 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\Audio;
use FFMpeg\Format\Audio as BaseAudio;
/**
* The interactive audio 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 InteractiveAudio extends BaseAudio
{
/**
* Returns the list of available audio codecs for this format
*
* @return array
*/
public function getAvailableAudioCodecs();
}

View file

@ -11,8 +11,6 @@
namespace FFMpeg\Format\Audio;
use FFMpeg\Format\DefaultAudio;
/**
* The MP3 audio format
*

View 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\Audio;
use FFMpeg\Format\Audio as BaseAudio;
/**
* The resamplable audio interface
*
* This provide a method to define the AudiosampleRate
*
* @author Romain Neutron imprec@gmail.com
*/
interface ResamplableAudio extends BaseAudio
{
/**
* Get the audio sample rate
*
* @return integer
*/
public function getAudioSampleRate();
}

View file

@ -12,42 +12,12 @@
namespace FFMpeg\Format;
/**
* The video format interface
*
* The base video interface
*
* @author Romain Neutron imprec@gmail.com
*/
interface Video extends Audio
{
const RESIZEMODE_FIT = 'fit';
const RESIZEMODE_INSET = 'inset';
/**
* Returns the width
*
* @return integer
*/
public function getWidth();
/**
* Returns the height
*
* @return integer
*/
public function getHeight();
/**
* Get the current resize mode
*
* @return string
*/
public function getResizeMode();
/**
* Returns the frame rate
*
* @return integer
*/
public function getFrameRate();
/**
* Returns the video codec
@ -55,18 +25,4 @@ interface Video extends Audio
* @return string
*/
public function getVideoCodec();
/**
* Returns the GOP size
*
* @return integer
*/
public function getGOPSize();
/**
* Returns the list of available video codecs for this format
*
* @return array
*/
public function getAvailableVideoCodecs();
}

View file

@ -9,8 +9,9 @@
* file that was distributed with this source code.
*/
namespace FFMpeg\Format;
namespace FFMpeg\Format\Video;
use FFMpeg\Format\Audio\DefaultAudio;
use FFMpeg\Exception\InvalidArgumentException;
/**
@ -18,8 +19,10 @@ use FFMpeg\Exception\InvalidArgumentException;
*
* @author Romain Neutron imprec@gmail.com
*/
abstract class DefaultVideo extends DefaultAudio implements Video
abstract class DefaultVideo extends DefaultAudio implements InteractiveVideo, ResamplableVideo, ResizableVideo
{
const RESIZEMODE_FIT = 'fit';
const RESIZEMODE_INSET = 'inset';
protected $width;
protected $height;
@ -67,11 +70,39 @@ abstract class DefaultVideo extends DefaultAudio implements Video
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
*
*
* @param string $mode The mode, one of the self::RESIZEMODE_* constants
*
* @throws InvalidArgumentException
*/
public function setResizeMode($mode)

View 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();
}

View file

@ -11,8 +11,6 @@
namespace FFMpeg\Format\Video;
use FFMpeg\Format\DefaultVideo;
/**
* The Ogg video format
*

View 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();
}

View 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();
}

View file

@ -11,8 +11,6 @@
namespace FFMpeg\Format\Video;
use FFMpeg\Format\DefaultVideo;
/**
* The WebM video format
*

View file

@ -11,8 +11,6 @@
namespace FFMpeg\Format\Video;
use FFMpeg\Format\DefaultVideo;
/**
* The X264 video format
*