| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 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-30 21:27:10 +02:00
										 |  |  |     /** @var Array */ | 
					
						
							|  |  |  |     protected $additionalParamaters; | 
					
						
							| 
									
										
										
										
											2017-01-24 15:19:32 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 21:42:38 +01:00
										 |  |  |     /** @var Array */ | 
					
						
							|  |  |  |     protected $initialParamaters; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-30 21:27:10 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * {@inheritdoc} | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getAdditionalParameters() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->additionalParamaters; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Sets additional parameters. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  array                    $additionalParamaters | 
					
						
							|  |  |  |      * @throws InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setAdditionalParameters($additionalParamaters) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (!is_array($additionalParamaters)) { | 
					
						
							|  |  |  |             throw new InvalidArgumentException('Wrong additionalParamaters value'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->additionalParamaters = $additionalParamaters; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 21:42:38 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * {@inheritdoc} | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getInitialParameters() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->initialParamaters; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Sets initial parameters. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  array                    $initialParamaters | 
					
						
							|  |  |  |      * @throws InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setInitialParameters($initialParamaters) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (!is_array($initialParamaters)) { | 
					
						
							|  |  |  |             throw new InvalidArgumentException('Wrong initialParamaters value'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->initialParamaters = $initialParamaters; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-02-18 13:57:06 +01:00
										 |  |  |     public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0) | 
					
						
							| 
									
										
										
										
											2013-04-16 11:22:49 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         $format = $this; | 
					
						
							| 
									
										
										
										
											2018-02-21 16:38:46 +01:00
										 |  |  |         $listeners = array(new VideoProgressListener($ffprobe, $media->getPathfile(), $pass, $total, $duration)); | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         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
										 |  |  | } |