| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  | namespace Danjones\FFMpeg; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | use Alchemy\BinaryDriver\Exception\ExecutionFailureException; | 
					
						
							|  |  |  | use FFMpeg\Driver\FFMpegDriver; | 
					
						
							|  |  |  | use FFMpeg\Exception\RuntimeException; | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  | use FFMpeg\FFMpeg; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | use FFMpeg\FFProbe; | 
					
						
							| 
									
										
										
										
											2020-03-23 17:47:36 +03:00
										 |  |  | use FFMpeg\Filters\AdvancedMedia\ComplexCompatibleFilter; | 
					
						
							|  |  |  | use FFMpeg\Filters\AdvancedMedia\ComplexFilterContainer; | 
					
						
							|  |  |  | use FFMpeg\Filters\AdvancedMedia\ComplexFilterInterface; | 
					
						
							|  |  |  | use FFMpeg\Filters\AdvancedMedia\ComplexFilters; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | use FFMpeg\Filters\FiltersCollection; | 
					
						
							|  |  |  | use FFMpeg\Format\AudioInterface; | 
					
						
							|  |  |  | use FFMpeg\Format\FormatInterface; | 
					
						
							|  |  |  | use FFMpeg\Format\ProgressableInterface; | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  | use FFMpeg\Format\ProgressListener\AbstractProgressListener; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | use FFMpeg\Format\VideoInterface; | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  | use FFMpeg\Media\AbstractMediaType; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-03-23 17:47:36 +03:00
										 |  |  |  * AdvancedMedia may have multiple inputs and multiple outputs. | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |  * This class accepts only filters for -filter_complex option. | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |  * But you can set initial and additional parameters of the ffmpeg command. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @see http://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  | class MappableMedia extends AbstractMediaType | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var string[] | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     protected array $inputs = []; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     /** @var Map[] */ | 
					
						
							|  |  |  |     protected array $maps = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @var string[] | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     protected array $initialParameters = []; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var string[] | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     protected array $additionalParameters = []; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |      * @var AbstractProgressListener[] | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     protected array $listeners = []; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     public function __construct(FFMpegDriver $driver, FFProbe $ffprobe) | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         // In case of error user will see this text in the error log.
 | 
					
						
							|  |  |  |         // But absence of inputs is a correct situation for some cases.
 | 
					
						
							|  |  |  |         // For example, if the user will use filters such as "testsrc".
 | 
					
						
							|  |  |  |         $pathfile = 'you_can_pass_empty_inputs_array_only_if_you_use_computed_inputs'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         parent::__construct($pathfile, $driver, $ffprobe); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     public static function make(FFMpeg $ffmpeg): static | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return new static($ffmpeg->getFFMpegDriver(), $ffmpeg->getFFProbe()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     public function filters() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |         return $this->filters; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     public function addInput(string $path): static | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (empty($this->inputs)) { | 
					
						
							|  |  |  |             $this->pathfile = $path; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->inputs[] = $path; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return string[] | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     public function getInitialParameters(): array | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $this->initialParameters; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param string[] $initialParameters | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     public function setInitialParameters(array $initialParameters): static | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->initialParameters = $initialParameters; | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return string[] | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     public function getAdditionalParameters(): array | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $this->additionalParameters; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param string[] $additionalParameters | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     public function setAdditionalParameters(array $additionalParameters): static | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->additionalParameters = $additionalParameters; | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return string[] | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     public function getInputs(): array | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $this->inputs; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     public function getInputsCount(): int | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         return count($this->inputs); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     public function getFinalCommand(): string | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         return implode(' ', $this->buildCommand()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     public function map(callable $callback = null): Map|static | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $map = new Map($this); | 
					
						
							|  |  |  |         if (!$callback) { | 
					
						
							|  |  |  |             return $map; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $callback($map); | 
					
						
							| 
									
										
										
										
											2022-08-21 21:09:57 -05:00
										 |  |  |         $this->saveMap($map); | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-23 15:25:27 -05:00
										 |  |  |     public function saveMap(Map $map): static | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->maps[] = $map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |      * Select the streams for output. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |      * @param string[]        $outs              output labels of the -filter_complex part | 
					
						
							|  |  |  |      * @param FormatInterface $format            format of the output file | 
					
						
							|  |  |  |      * @param string          $outputFilename    output filename | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |      * @param bool            $forceDisableAudio | 
					
						
							|  |  |  |      * @param bool            $forceDisableVideo | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return $this | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |      * @todo Redo all of this. | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |      * @see https://ffmpeg.org/ffmpeg.html#Manual-stream-selection
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     private function map2( | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         array $outs, | 
					
						
							|  |  |  |         FormatInterface $format, | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |         $outputFilename, | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         $forceDisableAudio = false, | 
					
						
							|  |  |  |         $forceDisableVideo = false | 
					
						
							|  |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $commands = []; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         foreach ($outs as $label) { | 
					
						
							|  |  |  |             $commands[] = '-map'; | 
					
						
							|  |  |  |             $commands[] = $label; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Apply format params.
 | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $commands = array_merge( | 
					
						
							|  |  |  |             $commands, | 
					
						
							|  |  |  |             $this->applyFormatParams($format, $forceDisableAudio, $forceDisableVideo) | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Set output file.
 | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |         $commands[] = $outputFilename; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |         // Create a listener.
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         if ($format instanceof ProgressableInterface) { | 
					
						
							|  |  |  |             $listener = $format->createProgressListener($this, $this->ffprobe, 1, 1, 0); | 
					
						
							|  |  |  |             $this->listeners = array_merge($this->listeners, $listener); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->mapCommands = array_merge($this->mapCommands, $commands); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Apply added filters and execute ffmpeg command. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-02-26 12:33:45 +03:00
										 |  |  |      * @throws RuntimeException | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     public function save(): void | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         $command = $this->buildCommand(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             $this->driver->command($command, false, $this->listeners); | 
					
						
							|  |  |  |         } catch (ExecutionFailureException $e) { | 
					
						
							|  |  |  |             throw new RuntimeException('Encoding failed', $e->getCode(), $e); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |      * @param bool $forceDisableAudio | 
					
						
							|  |  |  |      * @param bool $forceDisableVideo | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |      * @todo Redo it all | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     protected function applyFormatParams( | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         FormatInterface $format, | 
					
						
							|  |  |  |         $forceDisableAudio = false, | 
					
						
							|  |  |  |         $forceDisableVideo = false | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |         // Set format params.
 | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $commands = []; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         if (!$forceDisableVideo && $format instanceof VideoInterface) { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |             if (null !== $format->getVideoCodec()) { | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |                 $commands[] = '-vcodec'; | 
					
						
							|  |  |  |                 $commands[] = $format->getVideoCodec(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |             // If the user passed some additional format parameters.
 | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |             if (null !== $format->getAdditionalParameters()) { | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |                 $commands = array_merge($commands, $format->getAdditionalParameters()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!$forceDisableAudio && $format instanceof AudioInterface) { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |             if (null !== $format->getAudioCodec()) { | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |                 $commands[] = '-acodec'; | 
					
						
							|  |  |  |                 $commands[] = $format->getAudioCodec(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |             if (null !== $format->getAudioKiloBitrate()) { | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |                 $commands[] = '-b:a'; | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |                 $commands[] = $format->getAudioKiloBitrate().'k'; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |             if (null !== $format->getAudioChannels()) { | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |                 $commands[] = '-ac'; | 
					
						
							|  |  |  |                 $commands[] = $format->getAudioChannels(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // If the user passed some extra parameters.
 | 
					
						
							|  |  |  |         if ($format->getExtraParams()) { | 
					
						
							|  |  |  |             $commands = array_merge($commands, $format->getExtraParams()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $commands; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function buildCommand() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $globalOptions = ['threads', 'filter_threads', 'filter_complex_threads']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return array_merge( | 
					
						
							|  |  |  |             ['-y'], | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |             $this->buildConfiguredGlobalOptions($globalOptions), | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |             $this->getInitialParameters(), | 
					
						
							|  |  |  |             $this->buildInputsPart($this->inputs), | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |             $this->buildMaps($this->maps), | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |             $this->getAdditionalParameters() | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param string[] $optionNames | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 17:39:40 -05:00
										 |  |  |     protected function buildConfiguredGlobalOptions($optionNames) | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $commands = []; | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |         foreach ($optionNames as $optionName) { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |             if (!$this->driver->getConfiguration()->has('ffmpeg.'.$optionName)) { | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |             $commands[] = '-'.$optionName; | 
					
						
							|  |  |  |             $commands[] = $this->driver->getConfiguration()->get('ffmpeg.'.$optionName); | 
					
						
							| 
									
										
										
										
											2020-03-02 14:50:42 +03:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $commands; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Build inputs part of the ffmpeg command. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string[] $inputs | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     protected function buildInputsPart(array $inputs): array | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $commands = []; | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  |         foreach ($inputs as $input) { | 
					
						
							|  |  |  |             $commands[] = '-i'; | 
					
						
							|  |  |  |             $commands[] = $input; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $commands; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param Map[] $maps | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function buildMaps(array $maps): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-08-21 22:42:02 -05:00
										 |  |  |         $commands = []; | 
					
						
							|  |  |  |         foreach($maps as $map) { | 
					
						
							|  |  |  |             array_push($commands, ...$map->buildCommand()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-21 22:42:02 -05:00
										 |  |  |         return $commands; | 
					
						
							| 
									
										
										
										
											2022-08-21 20:47:05 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-02-18 13:49:32 +03:00
										 |  |  | } |