| 
									
										
										
										
											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-05-30 12:22:22 +02:00
										 |  |  | namespace FFMpeg\Format\Video; | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-30 12:22:22 +02:00
										 |  |  | use FFMpeg\Format\Audio\DefaultAudio; | 
					
						
							| 
									
										
										
										
											2012-05-30 15:06:53 +02:00
										 |  |  | use FFMpeg\Format\Dimension; | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  | use FFMpeg\Exception\InvalidArgumentException; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * The abstract default Video format | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @author Romain Neutron imprec@gmail.com | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-05-30 15:06:53 +02:00
										 |  |  | abstract class DefaultVideo extends DefaultAudio implements Interactive, Resamplable, Resizable | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-30 12:22:22 +02:00
										 |  |  |     const RESIZEMODE_FIT = 'fit'; | 
					
						
							|  |  |  |     const RESIZEMODE_INSET = 'inset'; | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |     const RESIZEMODE_SCALE_WIDTH = 'width'; | 
					
						
							|  |  |  |     const RESIZEMODE_SCALE_HEIGHT = 'height'; | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     protected $width; | 
					
						
							|  |  |  |     protected $height; | 
					
						
							| 
									
										
										
										
											2012-04-27 00:48:57 +02:00
										 |  |  |     protected $frameRate = 25; | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  |     protected $resizeMode = self::RESIZEMODE_FIT; | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     protected $videoCodec; | 
					
						
							| 
									
										
										
										
											2012-04-27 00:48:57 +02:00
										 |  |  |     protected $GOPsize = 25; | 
					
						
							| 
									
										
										
										
											2012-04-13 14:15:56 +02:00
										 |  |  |     protected $kiloBitrate = 1000; | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |     protected $modulus = 16; | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2012-05-30 15:06:53 +02:00
										 |  |  |      * Returns the width setting. | 
					
						
							|  |  |  |      * The return of this method should not depend on a media file size | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return integer | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     public function getWidth() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->width; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2012-05-30 15:06:53 +02:00
										 |  |  |      * Returns the height setting | 
					
						
							|  |  |  |      * The return of this method should not depend on a media file size | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return integer | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-05-25 15:44:43 +02:00
										 |  |  |      * @param  integer                   $width  The heigth | 
					
						
							|  |  |  |      * @param  integer                   $height The width | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      * @throws \InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     public function setDimensions($width, $height) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-04-27 00:48:57 +02:00
										 |  |  |         if ($width < 1) { | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |             throw new InvalidArgumentException('Wrong width value'); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-04-27 00:48:57 +02:00
										 |  |  |         if ($height < 1) { | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |             throw new InvalidArgumentException('Wrong height value'); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  |         $this->width = $width; | 
					
						
							|  |  |  |         $this->height = $height; | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-30 12:22:22 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * {@inheritdoc) | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getComputedDimensions($originalWidth, $originalHeight) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |         $originalRatio = $originalWidth / $originalHeight; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-30 12:22:22 +02:00
										 |  |  |         switch ($this->getResizeMode()) { | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |             case self::RESIZEMODE_SCALE_WIDTH: | 
					
						
							|  |  |  |                 $height = $this->height; | 
					
						
							|  |  |  |                 $width = round($originalRatio * $this->height); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case self::RESIZEMODE_SCALE_HEIGHT: | 
					
						
							|  |  |  |                 $width = $this->width; | 
					
						
							|  |  |  |                 $height = round($this->width / $originalRatio); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2012-05-30 12:22:22 +02:00
										 |  |  |             case self::RESIZEMODE_INSET: | 
					
						
							|  |  |  |                 $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: | 
					
						
							| 
									
										
										
										
											2012-06-06 11:11:58 +02:00
										 |  |  |                 if (null !== $this->width && null !== $this->height) { | 
					
						
							|  |  |  |                     $width = $this->width; | 
					
						
							|  |  |  |                     $height = $this->height; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $width = $originalWidth; | 
					
						
							|  |  |  |                     $height = $originalHeight; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2012-05-30 12:22:22 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-30 15:06:53 +02:00
										 |  |  |         return new Dimension($width, $height); | 
					
						
							| 
									
										
										
										
											2012-05-30 12:22:22 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Set the resize mode | 
					
						
							| 
									
										
										
										
											2012-05-30 12:22:22 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param string $mode The mode, one of the self::RESIZEMODE_* constants | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  |      * @throws InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setResizeMode($mode) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |         if ( ! in_array($mode, array(self::RESIZEMODE_FIT, self::RESIZEMODE_INSET, self::RESIZEMODE_SCALE_WIDTH, self::RESIZEMODE_SCALE_HEIGHT))) { | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  |             throw new InvalidArgumentException( | 
					
						
							|  |  |  |                 'Resize mode `%s` is not valid , avalaible values are %s', | 
					
						
							|  |  |  |                 $mode, | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |                 implode(', ', array(self::RESIZEMODE_FIT, self::RESIZEMODE_INSET, self::RESIZEMODE_SCALE_WIDTH, self::RESIZEMODE_SCALE_HEIGHT)) | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  |             ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->resizeMode = $mode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2012-05-30 15:06:53 +02:00
										 |  |  |      * Get the current resize mode name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function getResizeMode() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->resizeMode; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |      * {@inheritdoc} | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-05-25 16:22:16 +02:00
										 |  |  |      * @param integer $frameRate | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      * @throws \InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     public function setFrameRate($frameRate) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-04-27 00:48:57 +02:00
										 |  |  |         if ($frameRate < 1) { | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |             throw new InvalidArgumentException('Wrong framerate value'); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->frameRate = (int) $frameRate; | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |      * {@inheritdoc} | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-05-25 15:44:43 +02:00
										 |  |  |      * @param  string                    $videoCodec | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      * @throws \InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     public function setVideoCodec($videoCodec) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-04-27 00:48:57 +02:00
										 |  |  |         if ( ! in_array($videoCodec, $this->getAvailableVideoCodecs())) { | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |             throw new InvalidArgumentException(sprintf( | 
					
						
							| 
									
										
										
										
											2012-04-27 00:48:57 +02:00
										 |  |  |                     'Wrong videocodec value for %s, available formats are %s' | 
					
						
							|  |  |  |                     , $videoCodec, implode(', ', $this->getAvailableVideoCodecs()) | 
					
						
							|  |  |  |             )); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->videoCodec = $videoCodec; | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |      * {@inheritdoc} | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-05-25 16:22:16 +02:00
										 |  |  |      * @param integer $GOPsize | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      * @throws \InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     public function setGOPsize($GOPsize) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-04-27 00:48:57 +02:00
										 |  |  |         if ($GOPsize < 1) { | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |             throw new InvalidArgumentException('Wrong GOP size value'); | 
					
						
							| 
									
										
										
										
											2012-04-13 12:09:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         $this->GOPsize = (int) $GOPsize; | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-10-31 00:30:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * {@inheritDoc} | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getPasses() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Used to determine what resolutions sizes are valid. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param int $value | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setModulus($value) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if(!in_array($value, array(2, 4, 8, 16))){ | 
					
						
							|  |  |  |             throw new InvalidArgumentException('Wrong modulus division value. Valid values are 2, 4, 8 or 16'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->modulus = $value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getModulus() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->modulus; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  | } |