From 892265dcec0f731427b237429ded10ee0b41504d Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 21 Aug 2022 17:39:40 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Initial=20edits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + src/MappableMedia.php | 181 ++++++------------------------------------ 2 files changed, 24 insertions(+), 158 deletions(-) diff --git a/composer.json b/composer.json index c58e0ca..116c2aa 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", "pestphp/pest": "^1.20", + "psy/psysh": "^0.11.8", "spatie/ray": "^1.28" }, "autoload": { diff --git a/src/MappableMedia.php b/src/MappableMedia.php index f0c061c..8835174 100644 --- a/src/MappableMedia.php +++ b/src/MappableMedia.php @@ -1,6 +1,6 @@ 0) { - $pathfile = $inputs[$inputsKeys[0]]; - } parent::__construct($pathfile, $driver, $ffprobe); - $this->filters = new FiltersCollection(); - $this->inputs = $inputs; - $this->initialParameters = []; - $this->additionalParameters = []; - $this->mapCommands = []; - $this->listeners = []; } - /** - * Returns the available filters. - * - * @return ComplexFilters - */ public function filters() { - return new ComplexFilters($this); - } - - /** - * Add complex filter. - * - * @param string $in - * @param string $out - * - * @return $this - */ - public function addFilter($in, ComplexCompatibleFilter $filter, $out) - { - $this->filters->add(new ComplexFilterContainer($in, $filter, $out)); - - return $this; - } - - /** - * {@inheritDoc} - */ - public function setFiltersCollection(FiltersCollection $filters) - { - foreach ($filters as $filter) { - if (!($filter instanceof ComplexFilterInterface)) { - throw new RuntimeException('For AdvancedMedia you can set filters collection'.' contains only objects that implement ComplexFilterInterface!'); - } - } - - return parent::setFiltersCollection($filters); + return $this->filters; } /** * @return string[] */ - public function getInitialParameters() + public function getInitialParameters(): array { return $this->initialParameters; } /** * @param string[] $initialParameters - * - * @return AdvancedMedia */ - public function setInitialParameters(array $initialParameters) + public function setInitialParameters(array $initialParameters): self { $this->initialParameters = $initialParameters; @@ -138,17 +93,15 @@ class AdvancedMedia extends AbstractMediaType /** * @return string[] */ - public function getAdditionalParameters() + public function getAdditionalParameters(): array { return $this->additionalParameters; } /** * @param string[] $additionalParameters - * - * @return AdvancedMedia */ - public function setAdditionalParameters(array $additionalParameters) + public function setAdditionalParameters(array $additionalParameters): self { $this->additionalParameters = $additionalParameters; @@ -158,23 +111,17 @@ class AdvancedMedia extends AbstractMediaType /** * @return string[] */ - public function getInputs() + public function getInputs(): array { return $this->inputs; } - /** - * @return int - */ - public function getInputsCount() + public function getInputsCount(): int { return count($this->inputs); } - /** - * @return string - */ - public function getFinalCommand() + public function getFinalCommand(): string { return implode(' ', $this->buildCommand()); } @@ -189,7 +136,7 @@ class AdvancedMedia extends AbstractMediaType * @param bool $forceDisableVideo * * @return $this - * + * @todo Redo all of this. * @see https://ffmpeg.org/ffmpeg.html#Manual-stream-selection */ public function map( @@ -228,13 +175,10 @@ class AdvancedMedia extends AbstractMediaType /** * Apply added filters and execute ffmpeg command. * - * @return void - * * @throws RuntimeException */ - public function save() + public function save(): void { - $this->assertFiltersAreCompatibleToCurrentFFMpegVersion(); $command = $this->buildCommand(); try { @@ -249,8 +193,9 @@ class AdvancedMedia extends AbstractMediaType * @param bool $forceDisableVideo * * @return array + * @todo Redo it all */ - private function applyFormatParams( + protected function applyFormatParams( FormatInterface $format, $forceDisableAudio = false, $forceDisableVideo = false @@ -289,64 +234,6 @@ class AdvancedMedia extends AbstractMediaType return $commands; } - - /** - * @return string - */ - private function applyComplexFilter(ComplexFilterInterface $filter) - { - /** @var $format VideoInterface */ - $filterCommands = $filter->applyComplex($this); - foreach ($filterCommands as $index => $command) { - if ('-vf' === $command || '-filter:v' === $command || '-filter_complex' === $command) { - unset($filterCommands[$index]); - } - } - - $strCommand = implode(' ', $filterCommands); - - // Compatibility with the some existed filters: - // If the command contains [in], just replace it to inLabel. If not - to add it manually. - if (false !== stripos($strCommand, '[in]')) { - $strCommand = str_replace('[in]', $filter->getInLabels(), $strCommand); - $in = ''; - } else { - $in = $filter->getInLabels(); - } - - // If the command contains [out], just replace it to outLabel. If not - to add it manually. - if (false !== stripos($strCommand, '[out]')) { - $strCommand = str_replace('[out]', $filter->getOutLabels(), $strCommand); - $out = ''; - } else { - $out = $filter->getOutLabels(); - } - - return $in.$strCommand.$out; - } - - /** - * @return void - * - * @throws RuntimeException - */ - protected function assertFiltersAreCompatibleToCurrentFFMpegVersion() - { - $messages = []; - $currentVersion = $this->getFFMpegDriver()->getVersion(); - /** @var ComplexFilterInterface $filter */ - foreach ($this->filters as $filter) { - if (version_compare($currentVersion, $filter->getMinimalFFMpegVersion(), '<')) { - $messages[] = $filter->getName().' filter is supported starting from ' - .$filter->getMinimalFFMpegVersion().' ffmpeg version'; - } - } - - if (!empty($messages)) { - throw new RuntimeException(implode('; ', $messages).'; your ffmpeg version is '.$currentVersion); - } - } - /** * @return array */ @@ -359,7 +246,6 @@ class AdvancedMedia extends AbstractMediaType $this->buildConfiguredGlobalOptions($globalOptions), $this->getInitialParameters(), $this->buildInputsPart($this->inputs), - $this->buildComplexFilterPart($this->filters), $this->mapCommands, $this->getAdditionalParameters() ); @@ -370,7 +256,7 @@ class AdvancedMedia extends AbstractMediaType * * @return array */ - private function buildConfiguredGlobalOptions($optionNames) + protected function buildConfiguredGlobalOptions($optionNames) { $commands = []; foreach ($optionNames as $optionName) { @@ -392,7 +278,7 @@ class AdvancedMedia extends AbstractMediaType * * @return array */ - private function buildInputsPart(array $inputs) + protected function buildInputsPart(array $inputs) { $commands = []; foreach ($inputs as $input) { @@ -402,25 +288,4 @@ class AdvancedMedia extends AbstractMediaType return $commands; } - - /** - * Build "-filter_complex" part of the ffmpeg command. - * - * @return array - */ - private function buildComplexFilterPart(FiltersCollection $complexFilters) - { - $commands = []; - /** @var ComplexFilterInterface $filter */ - foreach ($complexFilters as $filter) { - $filterCommand = $this->applyComplexFilter($filter); - $commands[] = $filterCommand; - } - - if (empty($commands)) { - return []; - } - - return ['-filter_complex', implode(';', $commands)]; - } }