🚧 Add Map class
This commit is contained in:
parent
892265dcec
commit
2ed5a4f4f4
2 changed files with 84 additions and 17 deletions
28
src/Map.php
Normal file
28
src/Map.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Danjones\FFMpeg;
|
||||||
|
|
||||||
|
class Map
|
||||||
|
{
|
||||||
|
protected MappableMedia $media;
|
||||||
|
protected string $path;
|
||||||
|
|
||||||
|
public function __construct(MappableMedia $media)
|
||||||
|
{
|
||||||
|
$this->media = $media;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveMap(): MappableMedia
|
||||||
|
{
|
||||||
|
$this->media->saveMap($this);
|
||||||
|
|
||||||
|
return $this->media;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveAs(string $path): static
|
||||||
|
{
|
||||||
|
$this->path = $path;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ namespace Danjones\FFMpeg;
|
||||||
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
|
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
|
||||||
use FFMpeg\Driver\FFMpegDriver;
|
use FFMpeg\Driver\FFMpegDriver;
|
||||||
use FFMpeg\Exception\RuntimeException;
|
use FFMpeg\Exception\RuntimeException;
|
||||||
|
use FFMpeg\FFMpeg;
|
||||||
use FFMpeg\FFProbe;
|
use FFMpeg\FFProbe;
|
||||||
use FFMpeg\Filters\AdvancedMedia\ComplexCompatibleFilter;
|
use FFMpeg\Filters\AdvancedMedia\ComplexCompatibleFilter;
|
||||||
use FFMpeg\Filters\AdvancedMedia\ComplexFilterContainer;
|
use FFMpeg\Filters\AdvancedMedia\ComplexFilterContainer;
|
||||||
|
|
@ -32,6 +33,9 @@ class MappableMedia extends AbstractMediaType
|
||||||
*/
|
*/
|
||||||
protected array $inputs = [];
|
protected array $inputs = [];
|
||||||
|
|
||||||
|
/** @var Map[] */
|
||||||
|
protected array $maps = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
|
|
@ -42,21 +46,11 @@ class MappableMedia extends AbstractMediaType
|
||||||
*/
|
*/
|
||||||
protected array $additionalParameters = [];
|
protected array $additionalParameters = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected array $mapCommands = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var AbstractProgressListener[]
|
* @var AbstractProgressListener[]
|
||||||
*/
|
*/
|
||||||
protected array $listeners = [];
|
protected array $listeners = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* AdvancedMedia constructor.
|
|
||||||
*
|
|
||||||
* @param string[] $inputs array of files to be opened
|
|
||||||
*/
|
|
||||||
public function __construct(FFMpegDriver $driver, FFProbe $ffprobe)
|
public function __construct(FFMpegDriver $driver, FFProbe $ffprobe)
|
||||||
{
|
{
|
||||||
// In case of error user will see this text in the error log.
|
// In case of error user will see this text in the error log.
|
||||||
|
|
@ -67,11 +61,27 @@ class MappableMedia extends AbstractMediaType
|
||||||
parent::__construct($pathfile, $driver, $ffprobe);
|
parent::__construct($pathfile, $driver, $ffprobe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function make(FFMpeg $ffmpeg): static
|
||||||
|
{
|
||||||
|
return new static($ffmpeg->getFFMpegDriver(), $ffmpeg->getFFProbe());
|
||||||
|
}
|
||||||
|
|
||||||
public function filters()
|
public function filters()
|
||||||
{
|
{
|
||||||
return $this->filters;
|
return $this->filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addInput(string $path): static
|
||||||
|
{
|
||||||
|
if (empty($this->inputs)) {
|
||||||
|
$this->pathfile = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->inputs[] = $path;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
|
|
@ -83,7 +93,7 @@ class MappableMedia extends AbstractMediaType
|
||||||
/**
|
/**
|
||||||
* @param string[] $initialParameters
|
* @param string[] $initialParameters
|
||||||
*/
|
*/
|
||||||
public function setInitialParameters(array $initialParameters): self
|
public function setInitialParameters(array $initialParameters): static
|
||||||
{
|
{
|
||||||
$this->initialParameters = $initialParameters;
|
$this->initialParameters = $initialParameters;
|
||||||
|
|
||||||
|
|
@ -101,7 +111,7 @@ class MappableMedia extends AbstractMediaType
|
||||||
/**
|
/**
|
||||||
* @param string[] $additionalParameters
|
* @param string[] $additionalParameters
|
||||||
*/
|
*/
|
||||||
public function setAdditionalParameters(array $additionalParameters): self
|
public function setAdditionalParameters(array $additionalParameters): static
|
||||||
{
|
{
|
||||||
$this->additionalParameters = $additionalParameters;
|
$this->additionalParameters = $additionalParameters;
|
||||||
|
|
||||||
|
|
@ -126,6 +136,26 @@ class MappableMedia extends AbstractMediaType
|
||||||
return implode(' ', $this->buildCommand());
|
return implode(' ', $this->buildCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function map(callable $callback = null): Map|static
|
||||||
|
{
|
||||||
|
$map = new Map($this);
|
||||||
|
if (!$callback) {
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
|
||||||
|
$callback($map);
|
||||||
|
$this->addMap($map);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveMap($map): static
|
||||||
|
{
|
||||||
|
$this->maps[] = $map;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select the streams for output.
|
* Select the streams for output.
|
||||||
*
|
*
|
||||||
|
|
@ -139,7 +169,7 @@ class MappableMedia extends AbstractMediaType
|
||||||
* @todo Redo all of this.
|
* @todo Redo all of this.
|
||||||
* @see https://ffmpeg.org/ffmpeg.html#Manual-stream-selection
|
* @see https://ffmpeg.org/ffmpeg.html#Manual-stream-selection
|
||||||
*/
|
*/
|
||||||
public function map(
|
private function map2(
|
||||||
array $outs,
|
array $outs,
|
||||||
FormatInterface $format,
|
FormatInterface $format,
|
||||||
$outputFilename,
|
$outputFilename,
|
||||||
|
|
@ -246,7 +276,7 @@ class MappableMedia extends AbstractMediaType
|
||||||
$this->buildConfiguredGlobalOptions($globalOptions),
|
$this->buildConfiguredGlobalOptions($globalOptions),
|
||||||
$this->getInitialParameters(),
|
$this->getInitialParameters(),
|
||||||
$this->buildInputsPart($this->inputs),
|
$this->buildInputsPart($this->inputs),
|
||||||
$this->mapCommands,
|
$this->buildMaps($this->maps),
|
||||||
$this->getAdditionalParameters()
|
$this->getAdditionalParameters()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -275,10 +305,8 @@ class MappableMedia extends AbstractMediaType
|
||||||
* Build inputs part of the ffmpeg command.
|
* Build inputs part of the ffmpeg command.
|
||||||
*
|
*
|
||||||
* @param string[] $inputs
|
* @param string[] $inputs
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
protected function buildInputsPart(array $inputs)
|
protected function buildInputsPart(array $inputs): array
|
||||||
{
|
{
|
||||||
$commands = [];
|
$commands = [];
|
||||||
foreach ($inputs as $input) {
|
foreach ($inputs as $input) {
|
||||||
|
|
@ -288,4 +316,15 @@ class MappableMedia extends AbstractMediaType
|
||||||
|
|
||||||
return $commands;
|
return $commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Map[] $maps
|
||||||
|
*/
|
||||||
|
protected function buildMaps(array $maps): array
|
||||||
|
{
|
||||||
|
$out = [];
|
||||||
|
// @todo
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue