[BC] Upgraded dependencies, dropped support for anything below PHP 8.0. (#849)
* GitHub actions + style fixes + updated packages * Fixed workflows dir * Support for PHP 8.1 (#1) * Update README.md * Revert some changes from upstream
This commit is contained in:
parent
72c946dc7d
commit
111c153428
335 changed files with 4394 additions and 28116 deletions
|
|
@ -54,9 +54,7 @@ class AdvancedMedia extends AbstractMediaType
|
|||
/**
|
||||
* AdvancedMedia constructor.
|
||||
*
|
||||
* @param string[] $inputs Array of files to be opened.
|
||||
* @param FFMpegDriver $driver
|
||||
* @param FFProbe $ffprobe
|
||||
* @param string[] $inputs array of files to be opened
|
||||
*/
|
||||
public function __construct($inputs, FFMpegDriver $driver, FFProbe $ffprobe)
|
||||
{
|
||||
|
|
@ -72,10 +70,10 @@ class AdvancedMedia extends AbstractMediaType
|
|||
parent::__construct($pathfile, $driver, $ffprobe);
|
||||
$this->filters = new FiltersCollection();
|
||||
$this->inputs = $inputs;
|
||||
$this->initialParameters = array();
|
||||
$this->additionalParameters = array();
|
||||
$this->mapCommands = array();
|
||||
$this->listeners = array();
|
||||
$this->initialParameters = [];
|
||||
$this->additionalParameters = [];
|
||||
$this->mapCommands = [];
|
||||
$this->listeners = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -91,27 +89,26 @@ class AdvancedMedia extends AbstractMediaType
|
|||
/**
|
||||
* Add complex filter.
|
||||
*
|
||||
* @param string $in
|
||||
* @param ComplexCompatibleFilter $filter
|
||||
* @param string $out
|
||||
* @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
|
||||
* {@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!');
|
||||
throw new RuntimeException('For AdvancedMedia you can set filters collection'.' contains only objects that implement ComplexFilterInterface!');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,6 +131,7 @@ class AdvancedMedia extends AbstractMediaType
|
|||
public function setInitialParameters(array $initialParameters)
|
||||
{
|
||||
$this->initialParameters = $initialParameters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -153,6 +151,7 @@ class AdvancedMedia extends AbstractMediaType
|
|||
public function setAdditionalParameters(array $additionalParameters)
|
||||
{
|
||||
$this->additionalParameters = $additionalParameters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -183,13 +182,14 @@ class AdvancedMedia extends AbstractMediaType
|
|||
/**
|
||||
* Select the streams for output.
|
||||
*
|
||||
* @param string[] $outs Output labels of the -filter_complex part.
|
||||
* @param FormatInterface $format Format of the output file.
|
||||
* @param string $outputFilename Output filename.
|
||||
* @param string[] $outs output labels of the -filter_complex part
|
||||
* @param FormatInterface $format format of the output file
|
||||
* @param string $outputFilename output filename
|
||||
* @param bool $forceDisableAudio
|
||||
* @param bool $forceDisableVideo
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see https://ffmpeg.org/ffmpeg.html#Manual-stream-selection
|
||||
*/
|
||||
public function map(
|
||||
|
|
@ -199,15 +199,17 @@ class AdvancedMedia extends AbstractMediaType
|
|||
$forceDisableAudio = false,
|
||||
$forceDisableVideo = false
|
||||
) {
|
||||
$commands = array();
|
||||
$commands = [];
|
||||
foreach ($outs as $label) {
|
||||
$commands[] = '-map';
|
||||
$commands[] = $label;
|
||||
}
|
||||
|
||||
// Apply format params.
|
||||
$commands = array_merge($commands,
|
||||
$this->applyFormatParams($format, $forceDisableAudio, $forceDisableVideo));
|
||||
$commands = array_merge(
|
||||
$commands,
|
||||
$this->applyFormatParams($format, $forceDisableAudio, $forceDisableVideo)
|
||||
);
|
||||
|
||||
// Set output file.
|
||||
$commands[] = $outputFilename;
|
||||
|
|
@ -219,6 +221,7 @@ class AdvancedMedia extends AbstractMediaType
|
|||
}
|
||||
|
||||
$this->mapCommands = array_merge($this->mapCommands, $commands);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -226,6 +229,7 @@ class AdvancedMedia extends AbstractMediaType
|
|||
* Apply added filters and execute ffmpeg command.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function save()
|
||||
|
|
@ -241,9 +245,8 @@ class AdvancedMedia extends AbstractMediaType
|
|||
}
|
||||
|
||||
/**
|
||||
* @param FormatInterface $format
|
||||
* @param bool $forceDisableAudio
|
||||
* @param bool $forceDisableVideo
|
||||
* @param bool $forceDisableAudio
|
||||
* @param bool $forceDisableVideo
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -253,27 +256,27 @@ class AdvancedMedia extends AbstractMediaType
|
|||
$forceDisableVideo = false
|
||||
) {
|
||||
// Set format params.
|
||||
$commands = array();
|
||||
$commands = [];
|
||||
if (!$forceDisableVideo && $format instanceof VideoInterface) {
|
||||
if ($format->getVideoCodec() !== null) {
|
||||
if (null !== $format->getVideoCodec()) {
|
||||
$commands[] = '-vcodec';
|
||||
$commands[] = $format->getVideoCodec();
|
||||
}
|
||||
// If the user passed some additional format parameters.
|
||||
if ($format->getAdditionalParameters() !== null) {
|
||||
if (null !== $format->getAdditionalParameters()) {
|
||||
$commands = array_merge($commands, $format->getAdditionalParameters());
|
||||
}
|
||||
}
|
||||
if (!$forceDisableAudio && $format instanceof AudioInterface) {
|
||||
if ($format->getAudioCodec() !== null) {
|
||||
if (null !== $format->getAudioCodec()) {
|
||||
$commands[] = '-acodec';
|
||||
$commands[] = $format->getAudioCodec();
|
||||
}
|
||||
if ($format->getAudioKiloBitrate() !== null) {
|
||||
if (null !== $format->getAudioKiloBitrate()) {
|
||||
$commands[] = '-b:a';
|
||||
$commands[] = $format->getAudioKiloBitrate() . 'k';
|
||||
$commands[] = $format->getAudioKiloBitrate().'k';
|
||||
}
|
||||
if ($format->getAudioChannels() !== null) {
|
||||
if (null !== $format->getAudioChannels()) {
|
||||
$commands[] = '-ac';
|
||||
$commands[] = $format->getAudioChannels();
|
||||
}
|
||||
|
|
@ -288,8 +291,6 @@ class AdvancedMedia extends AbstractMediaType
|
|||
}
|
||||
|
||||
/**
|
||||
* @param ComplexFilterInterface $filter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function applyComplexFilter(ComplexFilterInterface $filter)
|
||||
|
|
@ -297,8 +298,8 @@ class AdvancedMedia extends AbstractMediaType
|
|||
/** @var $format VideoInterface */
|
||||
$filterCommands = $filter->applyComplex($this);
|
||||
foreach ($filterCommands as $index => $command) {
|
||||
if ($command === '-vf' || $command === '-filter:v' || $command === '-filter_complex') {
|
||||
unset ($filterCommands[$index]);
|
||||
if ('-vf' === $command || '-filter:v' === $command || '-filter_complex' === $command) {
|
||||
unset($filterCommands[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -306,7 +307,7 @@ class AdvancedMedia extends AbstractMediaType
|
|||
|
||||
// Compatibility with the some existed filters:
|
||||
// If the command contains [in], just replace it to inLabel. If not - to add it manually.
|
||||
if (stripos($strCommand, '[in]') !== false) {
|
||||
if (false !== stripos($strCommand, '[in]')) {
|
||||
$strCommand = str_replace('[in]', $filter->getInLabels(), $strCommand);
|
||||
$in = '';
|
||||
} else {
|
||||
|
|
@ -314,35 +315,35 @@ class AdvancedMedia extends AbstractMediaType
|
|||
}
|
||||
|
||||
// If the command contains [out], just replace it to outLabel. If not - to add it manually.
|
||||
if (stripos($strCommand, '[out]') !== false) {
|
||||
if (false !== stripos($strCommand, '[out]')) {
|
||||
$strCommand = str_replace('[out]', $filter->getOutLabels(), $strCommand);
|
||||
$out = '';
|
||||
} else {
|
||||
$out = $filter->getOutLabels();
|
||||
}
|
||||
|
||||
return $in . $strCommand . $out;
|
||||
return $in.$strCommand.$out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function assertFiltersAreCompatibleToCurrentFFMpegVersion()
|
||||
{
|
||||
$messages = array();
|
||||
$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';
|
||||
$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);
|
||||
throw new RuntimeException(implode('; ', $messages).'; your ffmpeg version is '.$currentVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -351,8 +352,10 @@ class AdvancedMedia extends AbstractMediaType
|
|||
*/
|
||||
protected function buildCommand()
|
||||
{
|
||||
$globalOptions = array('threads', 'filter_threads', 'filter_complex_threads');
|
||||
return array_merge(array('-y'),
|
||||
$globalOptions = ['threads', 'filter_threads', 'filter_complex_threads'];
|
||||
|
||||
return array_merge(
|
||||
['-y'],
|
||||
$this->buildConfiguredGlobalOptions($globalOptions),
|
||||
$this->getInitialParameters(),
|
||||
$this->buildInputsPart($this->inputs),
|
||||
|
|
@ -369,14 +372,14 @@ class AdvancedMedia extends AbstractMediaType
|
|||
*/
|
||||
private function buildConfiguredGlobalOptions($optionNames)
|
||||
{
|
||||
$commands = array();
|
||||
$commands = [];
|
||||
foreach ($optionNames as $optionName) {
|
||||
if (!$this->driver->getConfiguration()->has('ffmpeg.' . $optionName)) {
|
||||
if (!$this->driver->getConfiguration()->has('ffmpeg.'.$optionName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$commands[] = '-' . $optionName;
|
||||
$commands[] = $this->driver->getConfiguration()->get('ffmpeg.' . $optionName);
|
||||
$commands[] = '-'.$optionName;
|
||||
$commands[] = $this->driver->getConfiguration()->get('ffmpeg.'.$optionName);
|
||||
}
|
||||
|
||||
return $commands;
|
||||
|
|
@ -391,7 +394,7 @@ class AdvancedMedia extends AbstractMediaType
|
|||
*/
|
||||
private function buildInputsPart(array $inputs)
|
||||
{
|
||||
$commands = array();
|
||||
$commands = [];
|
||||
foreach ($inputs as $input) {
|
||||
$commands[] = '-i';
|
||||
$commands[] = $input;
|
||||
|
|
@ -403,13 +406,11 @@ class AdvancedMedia extends AbstractMediaType
|
|||
/**
|
||||
* Build "-filter_complex" part of the ffmpeg command.
|
||||
*
|
||||
* @param FiltersCollection $complexFilters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function buildComplexFilterPart(FiltersCollection $complexFilters)
|
||||
{
|
||||
$commands = array();
|
||||
$commands = [];
|
||||
/** @var ComplexFilterInterface $filter */
|
||||
foreach ($complexFilters as $filter) {
|
||||
$filterCommand = $this->applyComplexFilter($filter);
|
||||
|
|
@ -417,8 +418,9 @@ class AdvancedMedia extends AbstractMediaType
|
|||
}
|
||||
|
||||
if (empty($commands)) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
return array('-filter_complex', implode(';', $commands));
|
||||
|
||||
return ['-filter_complex', implode(';', $commands)];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue