Merge pull request #75 from alchemy-fr/rotate
Add a rotate filter (fix #15)
This commit is contained in:
		
				commit
				
					
						7d99f161cd
					
				
			
		
					 4 changed files with 111 additions and 0 deletions
				
			
		|  | @ -1,6 +1,10 @@ | ||||||
| CHANGELOG | CHANGELOG | ||||||
| --------- | --------- | ||||||
| 
 | 
 | ||||||
|  | * 0.4.2 (xx-xx-xx) | ||||||
|  | 
 | ||||||
|  |   * Add Rotate filter. | ||||||
|  | 
 | ||||||
| * 0.4.1 (11-26-2013) | * 0.4.1 (11-26-2013) | ||||||
| 
 | 
 | ||||||
|   * Add Clip filter (@guimeira) |   * Add Clip filter (@guimeira) | ||||||
|  |  | ||||||
							
								
								
									
										73
									
								
								src/FFMpeg/Filters/Video/RotateFilter.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								src/FFMpeg/Filters/Video/RotateFilter.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,73 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * This file is part of PHP-FFmpeg. | ||||||
|  |  * | ||||||
|  |  * (c) Alchemy <dev.team@alchemy.fr> | ||||||
|  |  * | ||||||
|  |  * 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\InvalidArgumentException; | ||||||
|  | use FFMpeg\Exception\RuntimeException; | ||||||
|  | use FFMpeg\Media\Video; | ||||||
|  | use FFMpeg\Format\VideoInterface; | ||||||
|  | 
 | ||||||
|  | class RotateFilter implements VideoFilterInterface | ||||||
|  | { | ||||||
|  |     const ROTATE_90 = 'transpose=1'; | ||||||
|  |     const ROTATE_180 = 'hflip,vflip'; | ||||||
|  |     const ROTATE_270 = 'transpose=2'; | ||||||
|  | 
 | ||||||
|  |     /** @var string */ | ||||||
|  |     private $angle; | ||||||
|  |     /** @var integer */ | ||||||
|  |     private $priority; | ||||||
|  | 
 | ||||||
|  |     public function __construct($angle, $priority = 0) | ||||||
|  |     { | ||||||
|  |         $this->setAngle($angle); | ||||||
|  |         $this->priority = (int) $priority; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * {@inheritdoc} | ||||||
|  |      */ | ||||||
|  |     public function getPriority() | ||||||
|  |     { | ||||||
|  |         return $this->priority; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @return Dimension | ||||||
|  |      */ | ||||||
|  |     public function getAngle() | ||||||
|  |     { | ||||||
|  |         return $this->angle; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * {@inheritdoc} | ||||||
|  |      */ | ||||||
|  |     public function apply(Video $video, VideoInterface $format) | ||||||
|  |     { | ||||||
|  |         return array('-vf', $this->angle, '-metadata:s:v:0', 'rotate=0'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private function setAngle($angle) | ||||||
|  |     { | ||||||
|  |         switch ($angle) { | ||||||
|  |             case self::ROTATE_90: | ||||||
|  |             case self::ROTATE_180: | ||||||
|  |             case self::ROTATE_270: | ||||||
|  |                 $this->angle = $angle; | ||||||
|  |                 break; | ||||||
|  |             default: | ||||||
|  |                 throw new InvalidArgumentException('Invalid angle value.'); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -95,4 +95,11 @@ class VideoFilters extends AudioFilters | ||||||
| 
 | 
 | ||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     public function rotate($angle, $priority = 0) | ||||||
|  |     { | ||||||
|  |         $this->media->addFilter(new RotateFilter($angle, $priority)); | ||||||
|  | 
 | ||||||
|  |         return $this; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										27
									
								
								tests/FFMpeg/Tests/Filters/Video/RotateFilterTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								tests/FFMpeg/Tests/Filters/Video/RotateFilterTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace FFMpeg\Tests\Filters\Video; | ||||||
|  | 
 | ||||||
|  | use FFMpeg\Filters\Video\RotateFilter; | ||||||
|  | use FFMpeg\Tests\TestCase; | ||||||
|  | 
 | ||||||
|  | class RotateFilterTest extends TestCase | ||||||
|  | { | ||||||
|  |     public function testApply() | ||||||
|  |     { | ||||||
|  |         $video = $this->getVideoMock(); | ||||||
|  |         $format = $this->getMock('FFMpeg\Format\VideoInterface'); | ||||||
|  | 
 | ||||||
|  |         $filter = new RotateFilter(RotateFilter::ROTATE_90); | ||||||
|  |         $this->assertEquals(array('-vf', RotateFilter::ROTATE_90, '-metadata:s:v:0', 'rotate=0'), $filter->apply($video, $format)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @expectedException \FFMpeg\Exception\InvalidArgumentException | ||||||
|  |      * @expectedExceptionMessage Invalid angle value. | ||||||
|  |      */ | ||||||
|  |     public function testApplyInvalidAngle() | ||||||
|  |     { | ||||||
|  |         new RotateFilter('90'); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue