Add DisplayRatioFixer Frame filter
This commit is contained in:
		
					parent
					
						
							
								bcf3e5f65a
							
						
					
				
			
			
				commit
				
					
						1de948faba
					
				
			
		
					 3 changed files with 87 additions and 0 deletions
				
			
		|  | @ -4,6 +4,7 @@ CHANGELOG | ||||||
| * 0.3.3 (xx-xx-2013) | * 0.3.3 (xx-xx-2013) | ||||||
| 
 | 
 | ||||||
|   * Add convenient Stream::getDimensions method to extract video dimension. |   * Add convenient Stream::getDimensions method to extract video dimension. | ||||||
|  |   * Add DisplayRatioFixer Frame filter. | ||||||
| 
 | 
 | ||||||
| * 0.3.2 (08-08-2013) | * 0.3.2 (08-08-2013) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										58
									
								
								src/FFMpeg/Filters/Frame/DisplayRatioFixerFilter.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								src/FFMpeg/Filters/Frame/DisplayRatioFixerFilter.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,58 @@ | ||||||
|  | <?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\Frame; | ||||||
|  | 
 | ||||||
|  | use FFMpeg\Exception\RuntimeException; | ||||||
|  | use FFMpeg\Media\Frame; | ||||||
|  | 
 | ||||||
|  | class DisplayRatioFixerFilter implements FrameFilterInterface | ||||||
|  | { | ||||||
|  |     /** @var integer */ | ||||||
|  |     private $priority; | ||||||
|  | 
 | ||||||
|  |     public function __construct($priority = 0) | ||||||
|  |     { | ||||||
|  |         $this->priority = $priority; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * {@inheritdoc} | ||||||
|  |      */ | ||||||
|  |     public function getPriority() | ||||||
|  |     { | ||||||
|  |         return $this->priority; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * {@inheritdoc} | ||||||
|  |      */ | ||||||
|  |     public function apply(Frame $frame) | ||||||
|  |     { | ||||||
|  |         $dimensions = null; | ||||||
|  |         $commands = array(); | ||||||
|  | 
 | ||||||
|  |         foreach ($frame->getVideo()->getStreams() as $stream) { | ||||||
|  |             if ($stream->isVideo()) { | ||||||
|  |                 try { | ||||||
|  |                     $dimensions = $stream->getDimensions(); | ||||||
|  |                     $commands[] = '-s'; | ||||||
|  |                     $commands[] = $dimensions->getWidth() . 'x' . $dimensions->getHeight(); | ||||||
|  |                     break; | ||||||
|  |                 } catch (RuntimeException $e) { | ||||||
|  | 
 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return $commands; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,28 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace FFMpeg\Tests\Filters\Frame; | ||||||
|  | 
 | ||||||
|  | use FFMpeg\Tests\TestCase; | ||||||
|  | use FFMpeg\Filters\Frame\DisplayRatioFixerFilter; | ||||||
|  | use FFMpeg\Media\Frame; | ||||||
|  | use FFMpeg\Coordinate\TimeCode; | ||||||
|  | use FFMpeg\FFProbe\DataMapping\StreamCollection; | ||||||
|  | use FFMpeg\FFProbe\DataMapping\Stream; | ||||||
|  | 
 | ||||||
|  | class DisplayRatioFixerFilterTest extends TestCase | ||||||
|  | { | ||||||
|  |     public function testApply() | ||||||
|  |     { | ||||||
|  |         $stream = new Stream(array('codec_type' => 'video', 'width' => 960, 'height' => 720)); | ||||||
|  |         $streams = new StreamCollection(array($stream)); | ||||||
|  |          | ||||||
|  |         $video = $this->getVideoMock(__FILE__); | ||||||
|  |         $video->expects($this->once()) | ||||||
|  |                 ->method('getStreams') | ||||||
|  |                 ->will($this->returnValue($streams)); | ||||||
|  |          | ||||||
|  |         $frame = new Frame($video, $this->getFFMpegDriverMock(), $this->getFFProbeMock(), new TimeCode(0, 0, 0, 0)); | ||||||
|  |         $filter = new DisplayRatioFixerFilter(); | ||||||
|  |         $this->assertEquals(array('-s', '960x720'), $filter->apply($frame)); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue