Creation of a pad filters which adds padding (black bars) to a video
This commit is contained in:
		
					parent
					
						
							
								2586b6a282
							
						
					
				
			
			
				commit
				
					
						345656b1dc
					
				
			
		
					 2 changed files with 74 additions and 0 deletions
				
			
		
							
								
								
									
										60
									
								
								src/FFMpeg/Filters/Video/PadFilter.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src/FFMpeg/Filters/Video/PadFilter.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,60 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * This file is part of PHP-FFmpeg. | ||||||
|  |  * | ||||||
|  |  * (c) Strime <contact@strime.io> | ||||||
|  |  * | ||||||
|  |  * For the full copyright and license information, please view the LICENSE | ||||||
|  |  * file that was distributed with this source code. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | namespace FFMpeg\Filters\Video; | ||||||
|  | 
 | ||||||
|  | use FFMpeg\Coordinate\Dimension; | ||||||
|  | use FFMpeg\Exception\RuntimeException; | ||||||
|  | use FFMpeg\Media\Video; | ||||||
|  | use FFMpeg\Format\VideoInterface; | ||||||
|  | 
 | ||||||
|  | class PadFilter implements VideoFilterInterface | ||||||
|  | { | ||||||
|  |     /** @var Dimension */ | ||||||
|  |     private $dimension; | ||||||
|  |     /** @var integer */ | ||||||
|  |     private $priority; | ||||||
|  | 
 | ||||||
|  |     public function __construct(Dimension $dimension, $priority = 0) | ||||||
|  |     { | ||||||
|  |         $this->dimension = $dimension; | ||||||
|  |         $this->priority = $priority; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * {@inheritdoc} | ||||||
|  |      */ | ||||||
|  |     public function getPriority() | ||||||
|  |     { | ||||||
|  |         return $this->priority; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @return Dimension | ||||||
|  |      */ | ||||||
|  |     public function getDimension() | ||||||
|  |     { | ||||||
|  |         return $this->dimension; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * {@inheritdoc} | ||||||
|  |      */ | ||||||
|  |     public function apply(Video $video, VideoInterface $format) | ||||||
|  |     { | ||||||
|  |         $commands = array(); | ||||||
|  | 
 | ||||||
|  |         $commands[] = '-vf'; | ||||||
|  |         $commands[] = 'pad=' . $this->dimension->getWidth() . ':' . $this->dimension->getHeight() . ':(' . $this->dimension->getWidth() . '-iw)/2:(' . $this->dimension->getHeight() .'-ih)/2'; | ||||||
|  | 
 | ||||||
|  |         return $commands; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -98,6 +98,20 @@ class VideoFilters extends AudioFilters | ||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Adds padding (black bars) to a video. | ||||||
|  |      * | ||||||
|  |      * @param Dimension $dimension | ||||||
|  |      * | ||||||
|  |      * @return VideoFilters | ||||||
|  |      */ | ||||||
|  |     public function pad(Dimension $dimension) | ||||||
|  |     { | ||||||
|  |         $this->media->addFilter(new PadFilter($dimension)); | ||||||
|  | 
 | ||||||
|  |         return $this; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function rotate($angle) |     public function rotate($angle) | ||||||
|     { |     { | ||||||
|         $this->media->addFilter(new RotateFilter($angle, 30)); |         $this->media->addFilter(new RotateFilter($angle, 30)); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue