commit
				
					
						984dbd046b
					
				
			
		
					 6 changed files with 85 additions and 5 deletions
				
			
		
							
								
								
									
										12
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
										
									
									
									
								
							|  | @ -554,6 +554,18 @@ $format->setAdditionalParameters(array('foo', 'bar')); | ||||||
| $video->save($format, 'video.avi'); | $video->save($format, 'video.avi'); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
|  | ##### Add initial parameters | ||||||
|  | 
 | ||||||
|  | You can also add initial parameters to your encoding requests based on your video format. This can be expecially handy in overriding a default input codec in FFMpeg. | ||||||
|  | 
 | ||||||
|  | The argument of the setInitialParameters method is an array. | ||||||
|  | 
 | ||||||
|  | ```php | ||||||
|  | $format = new FFMpeg\Format\Video\X264(); | ||||||
|  | $format->setInitialParameters(array('-acodec', 'libopus')); | ||||||
|  | $video->save($format, 'video.avi'); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
| ##### Create your own format | ##### Create your own format | ||||||
| 
 | 
 | ||||||
| The easiest way to create a format is to extend the abstract | The easiest way to create a format is to extend the abstract | ||||||
|  |  | ||||||
|  | @ -35,6 +35,9 @@ abstract class DefaultVideo extends DefaultAudio implements VideoInterface | ||||||
|     /** @var Array */ |     /** @var Array */ | ||||||
|     protected $additionalParamaters; |     protected $additionalParamaters; | ||||||
| 
 | 
 | ||||||
|  |     /** @var Array */ | ||||||
|  |     protected $initialParamaters; | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * {@inheritdoc} |      * {@inheritdoc} | ||||||
|      */ |      */ | ||||||
|  | @ -122,6 +125,31 @@ abstract class DefaultVideo extends DefaultAudio implements VideoInterface | ||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * {@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; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * {@inheritdoc} |      * {@inheritdoc} | ||||||
|      */ |      */ | ||||||
|  |  | ||||||
|  | @ -56,9 +56,16 @@ interface VideoInterface extends AudioInterface | ||||||
|     public function getAvailableVideoCodecs(); |     public function getAvailableVideoCodecs(); | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Returns the list of available video codecs for this format. |      * Returns the list of additional parameters for this format. | ||||||
|      * |      * | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public function getAdditionalParameters(); |     public function getAdditionalParameters(); | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Returns the list of initial parameters for this format | ||||||
|  |      * | ||||||
|  |      * @return array | ||||||
|  |      */ | ||||||
|  |     public function getInitialParameters(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -134,7 +134,7 @@ abstract class AbstractVideo extends Audio | ||||||
|      */ |      */ | ||||||
|     protected function buildCommand(FormatInterface $format, $outputPathfile) |     protected function buildCommand(FormatInterface $format, $outputPathfile) | ||||||
|     { |     { | ||||||
|         $commands = $this->basePartOfCommand(); |         $commands = $this->basePartOfCommand($format); | ||||||
| 
 | 
 | ||||||
|         $filters = clone $this->filters; |         $filters = clone $this->filters; | ||||||
|         $filters->add(new SimpleFilter($format->getExtraParams(), 10)); |         $filters->add(new SimpleFilter($format->getExtraParams(), 10)); | ||||||
|  | @ -283,10 +283,25 @@ abstract class AbstractVideo extends Audio | ||||||
|     /** |     /** | ||||||
|      * Return base part of command. |      * Return base part of command. | ||||||
|      * |      * | ||||||
|  |      * @param FormatInterface $format | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     protected function basePartOfCommand() |     protected function basePartOfCommand(FormatInterface $format) | ||||||
|     { |     { | ||||||
|         return array('-y', '-i', $this->pathfile); |         $commands = array('-y'); | ||||||
|  | 
 | ||||||
|  |         // If the user passed some initial parameters
 | ||||||
|  |         if ($format instanceof VideoInterface) { | ||||||
|  |             if (null !== $format->getInitialParameters()) { | ||||||
|  |                 foreach ($format->getInitialParameters() as $initialParameter) { | ||||||
|  |                     $commands[] = $initialParameter; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         $commands[] = '-i'; | ||||||
|  |         $commands[] = $this->pathfile; | ||||||
|  | 
 | ||||||
|  |         return $commands; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ namespace FFMpeg\Media; | ||||||
| use FFMpeg\Driver\FFMpegDriver; | use FFMpeg\Driver\FFMpegDriver; | ||||||
| use FFMpeg\FFProbe; | use FFMpeg\FFProbe; | ||||||
| use FFMpeg\Coordinate\TimeCode; | use FFMpeg\Coordinate\TimeCode; | ||||||
|  | use FFMpeg\Format\FormatInterface; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Video clip. |  * Video clip. | ||||||
|  | @ -34,6 +35,7 @@ class Clip extends Video | ||||||
|     /** |     /** | ||||||
|      * Returns the video related to the frame. |      * Returns the video related to the frame. | ||||||
|      * |      * | ||||||
|  |      * @param FormatInterface $format | ||||||
|      * @return Video |      * @return Video | ||||||
|      */ |      */ | ||||||
|     public function getVideo() |     public function getVideo() | ||||||
|  | @ -46,7 +48,7 @@ class Clip extends Video | ||||||
|      * |      * | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     protected function basePartOfCommand() |     protected function basePartOfCommand(FormatInterface $format) | ||||||
|     { |     { | ||||||
|         $arr = array('-y', '-ss', (string) $this->start, '-i', $this->pathfile); |         $arr = array('-y', '-ss', (string) $this->start, '-i', $this->pathfile); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								tests/Unit/Format/Video/InitialParametersTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								tests/Unit/Format/Video/InitialParametersTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace Tests\FFMpeg\Unit\Format\Video; | ||||||
|  | 
 | ||||||
|  | use FFMpeg\Format\Video\X264; | ||||||
|  | use Tests\FFMpeg\Unit\TestCase; | ||||||
|  | 
 | ||||||
|  | class InitialParametersTest extends TestCase | ||||||
|  | { | ||||||
|  |     public function testApplyInitialParameters() | ||||||
|  |     { | ||||||
|  |         $format = new X264(); | ||||||
|  |         $format->setInitialParameters(array('-acodec', 'libopus')); | ||||||
|  |         $this->assertEquals(array('-acodec', 'libopus'), $format->getInitialParameters()); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue