Merge branch 'master' of https://github.com/PHP-FFMpeg/PHP-FFMpeg
This commit is contained in:
		
				commit
				
					
						1bf60e71cf
					
				
			
		
					 4 changed files with 91 additions and 52 deletions
				
			
		|  | @ -18,11 +18,8 @@ php: | ||||||
|   - 5.6 |   - 5.6 | ||||||
|   - 7.0 |   - 7.0 | ||||||
|   - 7.1 |   - 7.1 | ||||||
|   - hhvm |  | ||||||
| 
 | 
 | ||||||
| matrix: | matrix: | ||||||
|   allow_failures: |  | ||||||
|     - php: hhvm |  | ||||||
|   include: |   include: | ||||||
|     - php: 5.4 |     - php: 5.4 | ||||||
|       env: COMPOSER_FLAGS="--prefer-lowest" |       env: COMPOSER_FLAGS="--prefer-lowest" | ||||||
|  |  | ||||||
|  | @ -24,6 +24,11 @@ | ||||||
|             "name": "Romain Biard", |             "name": "Romain Biard", | ||||||
|             "email": "romain.biard@gmail.com", |             "email": "romain.biard@gmail.com", | ||||||
|             "homepage": "https://www.strime.io/" |             "homepage": "https://www.strime.io/" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "name": "Jens Hausdorf", | ||||||
|  |             "email": "hello@jens-hausdorf.de", | ||||||
|  |             "homepage": "https://jens-hausdorf.de" | ||||||
|         } |         } | ||||||
|     ], |     ], | ||||||
|     "require": { |     "require": { | ||||||
|  |  | ||||||
|  | @ -57,7 +57,7 @@ class Audio extends AbstractStreamableMedia | ||||||
|      * @return Audio |      * @return Audio | ||||||
|      * @throws RuntimeException |      * @throws RuntimeException | ||||||
|      */ |      */ | ||||||
|     public function save(FormatInterface $format, string $outputPathfile) |     public function save(FormatInterface $format, $outputPathfile) | ||||||
|     { |     { | ||||||
|         $listeners = null; |         $listeners = null; | ||||||
| 
 | 
 | ||||||
|  | @ -85,7 +85,7 @@ class Audio extends AbstractStreamableMedia | ||||||
|      * @return string |      * @return string | ||||||
|      * @since 0.11.0 |      * @since 0.11.0 | ||||||
|      */ |      */ | ||||||
|     public function getFinalCommand(FormatInterface $format, string $outputPathfile) { |     public function getFinalCommand(FormatInterface $format, $outputPathfile) { | ||||||
|         return implode(' ', $this->buildCommand($format, $outputPathfile)); |         return implode(' ', $this->buildCommand($format, $outputPathfile)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -97,7 +97,7 @@ class Audio extends AbstractStreamableMedia | ||||||
|      * @return string[] An array which are the components of the command |      * @return string[] An array which are the components of the command | ||||||
|      * @since 0.11.0 |      * @since 0.11.0 | ||||||
|      */ |      */ | ||||||
|     protected function buildCommand(FormatInterface $format, string $outputPathfile) { |     protected function buildCommand(FormatInterface $format, $outputPathfile) { | ||||||
|         $commands = array('-y', '-i', $this->pathfile); |         $commands = array('-y', '-i', $this->pathfile); | ||||||
| 
 | 
 | ||||||
|         $filters = clone $this->filters; |         $filters = clone $this->filters; | ||||||
|  |  | ||||||
|  | @ -28,8 +28,19 @@ use Neutron\TemporaryFilesystem\Manager as FsManager; | ||||||
| class Video extends Audio | class Video extends Audio | ||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * {@inheritdoc} |      * FileSystem Manager instance | ||||||
|      * |      * @var Manager | ||||||
|  |      */ | ||||||
|  |     protected $fs; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * FileSystem Manager ID | ||||||
|  |      * @var int | ||||||
|  |      */ | ||||||
|  |     protected $fsId; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @inheritDoc | ||||||
|      * @return VideoFilters |      * @return VideoFilters | ||||||
|      */ |      */ | ||||||
|     public function filters() |     public function filters() | ||||||
|  | @ -38,8 +49,7 @@ class Video extends Audio | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * {@inheritdoc} |      * @inheritDoc | ||||||
|      * |  | ||||||
|      * @return Video |      * @return Video | ||||||
|      */ |      */ | ||||||
|     public function addFilter(FilterInterface $filter) |     public function addFilter(FilterInterface $filter) | ||||||
|  | @ -52,15 +62,66 @@ class Video extends Audio | ||||||
|     /** |     /** | ||||||
|      * Exports the video in the desired format, applies registered filters. |      * Exports the video in the desired format, applies registered filters. | ||||||
|      * |      * | ||||||
|      * @param FormatInterface $format |      * @param FormatInterface   $format | ||||||
|      * @param string          $outputPathfile |      * @param string            $outputPathfile | ||||||
|      * |  | ||||||
|      * @return Video |      * @return Video | ||||||
|      * |  | ||||||
|      * @throws RuntimeException |      * @throws RuntimeException | ||||||
|      */ |      */ | ||||||
|     public function save(FormatInterface $format, $outputPathfile) |     public function save(FormatInterface $format, $outputPathfile) | ||||||
|     { |     { | ||||||
|  |         $passes = $this->buildCommand($format, $outputPathfile); | ||||||
|  | 
 | ||||||
|  |         $failure = null; | ||||||
|  |         $totalPasses = $format->getPasses(); | ||||||
|  | 
 | ||||||
|  |         foreach ($passes as $pass => $passCommands) { | ||||||
|  |             try { | ||||||
|  |                 /** add listeners here */ | ||||||
|  |                 $listeners = null; | ||||||
|  | 
 | ||||||
|  |                 if ($format instanceof ProgressableInterface) { | ||||||
|  |                     $listeners = $format->createProgressListener($this, $this->ffprobe, $pass + 1, $totalPasses); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 $this->driver->command($passCommands, false, $listeners); | ||||||
|  |             } catch (ExecutionFailureException $e) { | ||||||
|  |                 $failure = $e; | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         $this->fs->clean($this->fsId); | ||||||
|  | 
 | ||||||
|  |         if (null !== $failure) { | ||||||
|  |             throw new RuntimeException('Encoding failed', $failure->getCode(), $failure); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return $this; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * NOTE: This method is different to the Audio's one, because Video is using passes. | ||||||
|  |      * @inheritDoc | ||||||
|  |      */ | ||||||
|  |     public function getFinalCommand(FormatInterface $format, $outputPathfile) { | ||||||
|  |         $finalCommands = array(); | ||||||
|  | 
 | ||||||
|  |         foreach($this->buildCommand($format, $outputPathfile) as $pass => $passCommands) { | ||||||
|  |             $finalCommands[] = implode(' ', $passCommands); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         $this->fs->clean($this->fsId); | ||||||
|  | 
 | ||||||
|  |         return $finalCommands; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * **NOTE:** This creates passes instead of a single command! | ||||||
|  |      * | ||||||
|  |      * @inheritDoc | ||||||
|  |      * @return string[][] | ||||||
|  |      */ | ||||||
|  |     protected function buildCommand(FormatInterface $format, $outputPathfile) { | ||||||
|         $commands = array('-y', '-i', $this->pathfile); |         $commands = array('-y', '-i', $this->pathfile); | ||||||
| 
 | 
 | ||||||
|         $filters = clone $this->filters; |         $filters = clone $this->filters; | ||||||
|  | @ -164,7 +225,7 @@ class Video extends Audio | ||||||
|             $command = '[' . $lastInput .']'; |             $command = '[' . $lastInput .']'; | ||||||
|             $command .= $process; |             $command .= $process; | ||||||
|             $lastInput = 'p' . $i; |             $lastInput = 'p' . $i; | ||||||
|             if ( $i == count($videoFilterProcesses) - 1 ) { |             if($i === (count($videoFilterProcesses) - 1)) { | ||||||
|                 $command .= '[out]'; |                 $command .= '[out]'; | ||||||
|             } else { |             } else { | ||||||
|                 $command .= '[' . $lastInput . ']'; |                 $command .= '[' . $lastInput . ']'; | ||||||
|  | @ -172,24 +233,24 @@ class Video extends Audio | ||||||
| 
 | 
 | ||||||
|             $videoFilterCommands[] = $command; |             $videoFilterCommands[] = $command; | ||||||
|         } |         } | ||||||
|         $videoFilterCommand = implode(";", $videoFilterCommands); |         $videoFilterCommand = implode(';', $videoFilterCommands); | ||||||
| 
 | 
 | ||||||
|         if ( $videoFilterCommand ) { |         if($videoFilterCommand) { | ||||||
|             $commands[] = '-vf'; |             $commands[] = '-vf'; | ||||||
|             $commands[] = $videoFilterCommand; |             $commands[] = $videoFilterCommand; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $fs = FsManager::create(); |         $this->fs = FsManager::create(); | ||||||
|         $fsId = uniqid('ffmpeg-passes'); |         $this->fsId = uniqid('ffmpeg-passes'); | ||||||
|         $passPrefix = $fs->createTemporaryDirectory(0777, 50, $fsId) . '/' . uniqid('pass-'); |         $passPrefix = $this->fs->createTemporaryDirectory(0777, 50, $this->fsId) . '/' . uniqid('pass-'); | ||||||
|         $passes = array(); |         $passes = array(); | ||||||
|         $totalPasses = $format->getPasses(); |         $totalPasses = $format->getPasses(); | ||||||
| 
 | 
 | ||||||
|         if (1 > $totalPasses) { |         if(!$totalPasses) { | ||||||
|             throw new InvalidArgumentException('Pass number should be a positive value.'); |             throw new InvalidArgumentException('Pass number should be a positive value.'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         for ($i = 1; $i <= $totalPasses; $i++) { |         for($i = 1; $i <= $totalPasses; $i++) { | ||||||
|             $pass = $commands; |             $pass = $commands; | ||||||
| 
 | 
 | ||||||
|             if ($totalPasses > 1) { |             if ($totalPasses > 1) { | ||||||
|  | @ -204,31 +265,7 @@ class Video extends Audio | ||||||
|             $passes[] = $pass; |             $passes[] = $pass; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $failure = null; |         return $passes; | ||||||
| 
 |  | ||||||
|         foreach ($passes as $pass => $passCommands) { |  | ||||||
|             try { |  | ||||||
|                 /** add listeners here */ |  | ||||||
|                 $listeners = null; |  | ||||||
| 
 |  | ||||||
|                 if ($format instanceof ProgressableInterface) { |  | ||||||
|                     $listeners = $format->createProgressListener($this, $this->ffprobe, $pass + 1, $totalPasses); |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 $this->driver->command($passCommands, false, $listeners); |  | ||||||
|             } catch (ExecutionFailureException $e) { |  | ||||||
|                 $failure = $e; |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $fs->clean($fsId); |  | ||||||
| 
 |  | ||||||
|         if (null !== $failure) { |  | ||||||
|             throw new RuntimeException('Encoding failed', $failure->getCode(), $failure); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return $this; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue