| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | use FFMpeg\FFProbe; | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  | use FFMpeg\Exception\InvalidArgumentException; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | use FFMpeg\Format\Audio\DefaultAudio; | 
					
						
							|  |  |  | use FFMpeg\Format\VideoInterface; | 
					
						
							|  |  |  | use FFMpeg\Media\MediaTypeInterface; | 
					
						
							| 
									
										
										
										
											2017-06-27 23:44:26 +02:00
										 |  |  | use FFMpeg\Format\Profile; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | use FFMpeg\Format\ProgressListener\VideoProgressListener; | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * The abstract default Video format | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | abstract class DefaultVideo extends DefaultAudio implements VideoInterface | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     /** @var string */ | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     protected $videoCodec; | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     /** @var Integer */ | 
					
						
							|  |  |  |     protected $kiloBitrate = 1000; | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     /** @var Integer */ | 
					
						
							|  |  |  |     protected $modulus = 16; | 
					
						
							| 
									
										
										
										
											2012-05-28 19:46:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 23:44:26 +02:00
										 |  |  |     /** @var string */ | 
					
						
							|  |  |  |     private $profile = Profile::MAIN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** @var float */ | 
					
						
							|  |  |  |     private $level = 3.1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** @var string[] */ | 
					
						
							|  |  |  |     protected $additionalParameters; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Sets the profile of this video | 
					
						
							|  |  |  |      * @var string  $profile    must be one of `baseline`, `main` or `high` | 
					
						
							|  |  |  |      * @throws \InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setProfile(string $profile) { | 
					
						
							|  |  |  |         switch($profile) { | 
					
						
							|  |  |  |             case Profile::BASELINE: | 
					
						
							|  |  |  |             case Profile::MAIN: | 
					
						
							|  |  |  |             case Profile::HIGH: | 
					
						
							|  |  |  |             // these are fine
 | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 throw new \InvalidArgumentException('Invalid profile given! Must be one of `baseline`, `main` or `high`!'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $this->profile = $profile; | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getProfile() { | 
					
						
							|  |  |  |         return $this->profile; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Sets the given level | 
					
						
							|  |  |  |      * @param   float   $level  The level(for example: 3.0, 3.1, 4.0, 4.1) | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setLevel(float $level) { | 
					
						
							|  |  |  |         $this->level = $level; | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getLevel() { | 
					
						
							|  |  |  |         return $this->level; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-24 15:19:32 -03: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
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     public function getKiloBitrate() | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         return $this->kiloBitrate; | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2013-06-25 10:40:20 +02:00
										 |  |  |      * Sets the kiloBitrate value. | 
					
						
							| 
									
										
										
										
											2012-05-25 16:21:16 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |      * @param  integer                  $kiloBitrate | 
					
						
							|  |  |  |      * @throws InvalidArgumentException | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     public function setKiloBitrate($kiloBitrate) | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         if ($kiloBitrate < 1) { | 
					
						
							|  |  |  |             throw new InvalidArgumentException('Wrong kiloBitrate value'); | 
					
						
							| 
									
										
										
										
											2012-04-13 10:20:54 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         $this->kiloBitrate = (int) $kiloBitrate; | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |      * Sets the video codec, Should be in the available ones, otherwise an | 
					
						
							| 
									
										
										
										
											2013-06-25 10:40:20 +02:00
										 |  |  |      * exception is thrown. | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |      * @param  string                   $videoCodec | 
					
						
							|  |  |  |      * @throws InvalidArgumentException | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |      * @return integer | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     public function getModulus() | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         return $this->modulus; | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |      * {@inheritdoc} | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total) | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         $format = $this; | 
					
						
							|  |  |  |         $listeners = array(new VideoProgressListener($ffprobe, $media->getPathfile(), $pass, $total)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach ($listeners as $listener) { | 
					
						
							|  |  |  |             $listener->on('progress', function () use ($format, $media) { | 
					
						
							|  |  |  |                $format->emit('progress', array_merge(array($media, $format), func_get_args())); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $listeners; | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-04-13 15:42:34 +02:00
										 |  |  | } |