From b1e6eeaf955aac4f62d438fd577329a1cd3b8818 Mon Sep 17 00:00:00 2001 From: grosroro Date: Wed, 30 May 2012 12:22:22 +0200 Subject: [PATCH] Rename Interfaces --- src/FFMpeg/Format/Audio.php | 18 ++---- .../Format/{ => Audio}/DefaultAudio.php | 4 +- src/FFMpeg/Format/Audio/Flac.php | 2 - src/FFMpeg/Format/Audio/InteractiveAudio.php | 32 ++++++++++ src/FFMpeg/Format/Audio/Mp3.php | 2 - src/FFMpeg/Format/Audio/ResamplableAudio.php | 32 ++++++++++ src/FFMpeg/Format/Video.php | 48 +-------------- .../Format/{ => Video}/DefaultVideo.php | 41 +++++++++++-- src/FFMpeg/Format/Video/InteractiveVideo.php | 32 ++++++++++ src/FFMpeg/Format/Video/Ogg.php | 2 - src/FFMpeg/Format/Video/ResamplableVideo.php | 39 +++++++++++++ src/FFMpeg/Format/Video/ResizableVideo.php | 58 +++++++++++++++++++ src/FFMpeg/Format/Video/WebM.php | 2 - src/FFMpeg/Format/Video/X264.php | 2 - 14 files changed, 238 insertions(+), 76 deletions(-) rename src/FFMpeg/Format/{ => Audio}/DefaultAudio.php (95%) create mode 100644 src/FFMpeg/Format/Audio/InteractiveAudio.php create mode 100644 src/FFMpeg/Format/Audio/ResamplableAudio.php rename src/FFMpeg/Format/{ => Video}/DefaultVideo.php (75%) create mode 100644 src/FFMpeg/Format/Video/InteractiveVideo.php create mode 100644 src/FFMpeg/Format/Video/ResamplableVideo.php create mode 100644 src/FFMpeg/Format/Video/ResizableVideo.php diff --git a/src/FFMpeg/Format/Audio.php b/src/FFMpeg/Format/Audio.php index 87fc8d4..7f02a09 100644 --- a/src/FFMpeg/Format/Audio.php +++ b/src/FFMpeg/Format/Audio.php @@ -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(); } diff --git a/src/FFMpeg/Format/DefaultAudio.php b/src/FFMpeg/Format/Audio/DefaultAudio.php similarity index 95% rename from src/FFMpeg/Format/DefaultAudio.php rename to src/FFMpeg/Format/Audio/DefaultAudio.php index 47948a9..7266531 100644 --- a/src/FFMpeg/Format/DefaultAudio.php +++ b/src/FFMpeg/Format/Audio/DefaultAudio.php @@ -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; diff --git a/src/FFMpeg/Format/Audio/Flac.php b/src/FFMpeg/Format/Audio/Flac.php index 1e83401..579ffc6 100644 --- a/src/FFMpeg/Format/Audio/Flac.php +++ b/src/FFMpeg/Format/Audio/Flac.php @@ -11,8 +11,6 @@ namespace FFMpeg\Format\Audio; -use FFMpeg\Format\DefaultAudio; - /** * The Flac audio format * diff --git a/src/FFMpeg/Format/Audio/InteractiveAudio.php b/src/FFMpeg/Format/Audio/InteractiveAudio.php new file mode 100644 index 0000000..03ce119 --- /dev/null +++ b/src/FFMpeg/Format/Audio/InteractiveAudio.php @@ -0,0 +1,32 @@ + + * + * 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(); +} diff --git a/src/FFMpeg/Format/Audio/Mp3.php b/src/FFMpeg/Format/Audio/Mp3.php index 7ba9d19..c7d45f3 100644 --- a/src/FFMpeg/Format/Audio/Mp3.php +++ b/src/FFMpeg/Format/Audio/Mp3.php @@ -11,8 +11,6 @@ namespace FFMpeg\Format\Audio; -use FFMpeg\Format\DefaultAudio; - /** * The MP3 audio format * diff --git a/src/FFMpeg/Format/Audio/ResamplableAudio.php b/src/FFMpeg/Format/Audio/ResamplableAudio.php new file mode 100644 index 0000000..a6b9901 --- /dev/null +++ b/src/FFMpeg/Format/Audio/ResamplableAudio.php @@ -0,0 +1,32 @@ + + * + * 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(); +} diff --git a/src/FFMpeg/Format/Video.php b/src/FFMpeg/Format/Video.php index 374e76f..6f2f1fa 100644 --- a/src/FFMpeg/Format/Video.php +++ b/src/FFMpeg/Format/Video.php @@ -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(); } diff --git a/src/FFMpeg/Format/DefaultVideo.php b/src/FFMpeg/Format/Video/DefaultVideo.php similarity index 75% rename from src/FFMpeg/Format/DefaultVideo.php rename to src/FFMpeg/Format/Video/DefaultVideo.php index 8f635c7..b28c74d 100644 --- a/src/FFMpeg/Format/DefaultVideo.php +++ b/src/FFMpeg/Format/Video/DefaultVideo.php @@ -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) diff --git a/src/FFMpeg/Format/Video/InteractiveVideo.php b/src/FFMpeg/Format/Video/InteractiveVideo.php new file mode 100644 index 0000000..accafcb --- /dev/null +++ b/src/FFMpeg/Format/Video/InteractiveVideo.php @@ -0,0 +1,32 @@ + + * + * 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(); +} diff --git a/src/FFMpeg/Format/Video/Ogg.php b/src/FFMpeg/Format/Video/Ogg.php index 463034f..0ff0673 100644 --- a/src/FFMpeg/Format/Video/Ogg.php +++ b/src/FFMpeg/Format/Video/Ogg.php @@ -11,8 +11,6 @@ namespace FFMpeg\Format\Video; -use FFMpeg\Format\DefaultVideo; - /** * The Ogg video format * diff --git a/src/FFMpeg/Format/Video/ResamplableVideo.php b/src/FFMpeg/Format/Video/ResamplableVideo.php new file mode 100644 index 0000000..a08c0c8 --- /dev/null +++ b/src/FFMpeg/Format/Video/ResamplableVideo.php @@ -0,0 +1,39 @@ + + * + * 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(); +} diff --git a/src/FFMpeg/Format/Video/ResizableVideo.php b/src/FFMpeg/Format/Video/ResizableVideo.php new file mode 100644 index 0000000..c0bc539 --- /dev/null +++ b/src/FFMpeg/Format/Video/ResizableVideo.php @@ -0,0 +1,58 @@ + + * + * 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(); +} diff --git a/src/FFMpeg/Format/Video/WebM.php b/src/FFMpeg/Format/Video/WebM.php index 9ebcd1e..3831d08 100644 --- a/src/FFMpeg/Format/Video/WebM.php +++ b/src/FFMpeg/Format/Video/WebM.php @@ -11,8 +11,6 @@ namespace FFMpeg\Format\Video; -use FFMpeg\Format\DefaultVideo; - /** * The WebM video format * diff --git a/src/FFMpeg/Format/Video/X264.php b/src/FFMpeg/Format/Video/X264.php index fcc7216..9fa2cde 100644 --- a/src/FFMpeg/Format/Video/X264.php +++ b/src/FFMpeg/Format/Video/X264.php @@ -11,8 +11,6 @@ namespace FFMpeg\Format\Video; -use FFMpeg\Format\DefaultVideo; - /** * The X264 video format *