Support resize and watermark in ordering. (#343)
* Support multiple -vf commands Marge Filters into one command * Ordering Scale Using -vf to scale instead of -s to have ordering * Correct the ResizeFilterTest * Remove useless comments * Fixed filter bug Add checking on filters if only one process. * Fixed typo error
This commit is contained in:
parent
30d5250376
commit
4cfcabd7b5
3 changed files with 76 additions and 24 deletions
|
|
@ -98,8 +98,10 @@ class ResizeFilter implements VideoFilterInterface
|
||||||
if (null !== $dimensions) {
|
if (null !== $dimensions) {
|
||||||
$dimensions = $this->getComputedDimensions($dimensions, $format->getModulus());
|
$dimensions = $this->getComputedDimensions($dimensions, $format->getModulus());
|
||||||
|
|
||||||
$commands[] = '-s';
|
// Using Filter to have ordering
|
||||||
$commands[] = $dimensions->getWidth() . 'x' . $dimensions->getHeight();
|
$commands[] = '-vf';
|
||||||
|
$commands[] = '[in]scale=' . $dimensions->getWidth() . ':' . $dimensions->getHeight() . ' [out]';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $commands;
|
return $commands;
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,56 @@ class Video extends Audio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge Filters into one command
|
||||||
|
$videoFilterVars = $videoFilterProcesses = [];
|
||||||
|
for($i=0;$i<count($commands);$i++) {
|
||||||
|
$command = $commands[$i];
|
||||||
|
if ( $command == '-vf' ) {
|
||||||
|
$commandSplits = explode(";", $commands[$i + 1]);
|
||||||
|
if ( count($commandSplits) == 1 ) {
|
||||||
|
$commandSplit = $commandSplits[0];
|
||||||
|
$command = trim($commandSplit);
|
||||||
|
if ( preg_match("/^\[in\](.*?)\[out\]$/is", $command, $match) ) {
|
||||||
|
$videoFilterProcesses[] = $match[1];
|
||||||
|
} else {
|
||||||
|
$videoFilterProcesses[] = $command;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach($commandSplits as $commandSplit) {
|
||||||
|
$command = trim($commandSplit);
|
||||||
|
if ( preg_match("/^\[[^\]]+\](.*?)\[[^\]]+\]$/is", $command, $match) ) {
|
||||||
|
$videoFilterProcesses[] = $match[1];
|
||||||
|
} else {
|
||||||
|
$videoFilterVars[] = $command;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($commands[$i]);
|
||||||
|
unset($commands[$i + 1]);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$videoFilterCommands = $videoFilterVars;
|
||||||
|
$lastInput = 'in';
|
||||||
|
foreach($videoFilterProcesses as $i => $process) {
|
||||||
|
$command = '[' . $lastInput .']';
|
||||||
|
$command .= $process;
|
||||||
|
$lastInput = 'p' . $i;
|
||||||
|
if ( $i == count($videoFilterProcesses) - 1 ) {
|
||||||
|
$command .= '[out]';
|
||||||
|
} else {
|
||||||
|
$command .= '[' . $lastInput . ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
$videoFilterCommands[] = $command;
|
||||||
|
}
|
||||||
|
$videoFilterCommand = implode(";", $videoFilterCommands);
|
||||||
|
|
||||||
|
if ( $videoFilterCommand ) {
|
||||||
|
$commands[] = '-vf';
|
||||||
|
$commands[] = $videoFilterCommand;
|
||||||
|
}
|
||||||
|
|
||||||
$fs = FsManager::create();
|
$fs = FsManager::create();
|
||||||
$fsId = uniqid('ffmpeg-passes');
|
$fsId = uniqid('ffmpeg-passes');
|
||||||
$passPrefix = $fs->createTemporaryDirectory(0777, 50, $fsId) . '/' . uniqid('pass-');
|
$passPrefix = $fs->createTemporaryDirectory(0777, 50, $fsId) . '/' . uniqid('pass-');
|
||||||
|
|
|
||||||
|
|
@ -42,34 +42,34 @@ class ResizeFilterTest extends TestCase
|
||||||
public function provideDimensions()
|
public function provideDimensions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(new Dimension(320, 240), ResizeFilter::RESIZEMODE_FIT, 640, 480, 2, array('-s', '320x240')),
|
array(new Dimension(320, 240), ResizeFilter::RESIZEMODE_FIT, 640, 480, 2, array('-vf', '[in]scale=320:240 [out]')),
|
||||||
array(new Dimension(320, 240), ResizeFilter::RESIZEMODE_INSET, 640, 480, 2, array('-s', '320x240')),
|
array(new Dimension(320, 240), ResizeFilter::RESIZEMODE_INSET, 640, 480, 2, array('-vf', '[in]scale=320:240 [out]')),
|
||||||
array(new Dimension(320, 240), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 640, 480, 2, array('-s', '320x240')),
|
array(new Dimension(320, 240), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 640, 480, 2, array('-vf', '[in]scale=320:240 [out]')),
|
||||||
array(new Dimension(320, 240), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 640, 480, 2, array('-s', '320x240')),
|
array(new Dimension(320, 240), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 640, 480, 2, array('-vf', '[in]scale=320:240 [out]')),
|
||||||
|
|
||||||
array(new Dimension(640, 480), ResizeFilter::RESIZEMODE_FIT, 320, 240, 2, array('-s', '640x480')),
|
array(new Dimension(640, 480), ResizeFilter::RESIZEMODE_FIT, 320, 240, 2, array('-vf', '[in]scale=640:480 [out]')),
|
||||||
array(new Dimension(640, 480), ResizeFilter::RESIZEMODE_INSET, 320, 240, 2, array('-s', '640x480')),
|
array(new Dimension(640, 480), ResizeFilter::RESIZEMODE_INSET, 320, 240, 2, array('-vf', '[in]scale=640:480 [out]')),
|
||||||
array(new Dimension(640, 480), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 320, 240, 2, array('-s', '640x480')),
|
array(new Dimension(640, 480), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 320, 240, 2, array('-vf', '[in]scale=640:480 [out]')),
|
||||||
array(new Dimension(640, 480), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 320, 240, 2, array('-s', '640x480')),
|
array(new Dimension(640, 480), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 320, 240, 2, array('-vf', '[in]scale=640:480 [out]')),
|
||||||
|
|
||||||
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_FIT, 1280, 720, 2, array('-s', '640x360')),
|
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_FIT, 1280, 720, 2, array('-vf', '[in]scale=640:360 [out]')),
|
||||||
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_INSET, 1280, 720, 2, array('-s', '640x360')),
|
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_INSET, 1280, 720, 2, array('-vf', '[in]scale=640:360 [out]')),
|
||||||
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 1280, 720, 2, array('-s', '640x360')),
|
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 1280, 720, 2, array('-vf', '[in]scale=640:360 [out]')),
|
||||||
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 1280, 720, 2, array('-s', '640x360')),
|
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 1280, 720, 2, array('-vf', '[in]scale=640:360 [out]')),
|
||||||
|
|
||||||
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_FIT, 1280, 720, 2, array('-s', '640x360')),
|
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_FIT, 1280, 720, 2, array('-vf', '[in]scale=640:360 [out]')),
|
||||||
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_INSET, 1280, 720, 2, array('-s', '640x360')),
|
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_INSET, 1280, 720, 2, array('-vf', '[in]scale=640:360 [out]')),
|
||||||
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 1280, 720, 2, array('-s', '640x360')),
|
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 1280, 720, 2, array('-vf', '[in]scale=640:360 [out]')),
|
||||||
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 1280, 720, 2, array('-s', '640x360')),
|
array(new Dimension(640, 360), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 1280, 720, 2, array('-vf', '[in]scale=640:360 [out]')),
|
||||||
|
|
||||||
// test non standard dimension
|
// test non standard dimension
|
||||||
array(new Dimension(700, 150), ResizeFilter::RESIZEMODE_INSET, 123, 456, 2, array('-s', '62x150'), true),
|
array(new Dimension(700, 150), ResizeFilter::RESIZEMODE_INSET, 123, 456, 2, array('-vf', '[in]scale=62:150 [out]'), true),
|
||||||
array(new Dimension(700, 150), ResizeFilter::RESIZEMODE_INSET, 123, 456, 2, array('-s', '40x150'), false),
|
array(new Dimension(700, 150), ResizeFilter::RESIZEMODE_INSET, 123, 456, 2, array('-vf', '[in]scale=40:150 [out]'), false),
|
||||||
|
|
||||||
array(new Dimension(320, 320), ResizeFilter::RESIZEMODE_FIT, 640, 480, 2, array('-s', '320x320')),
|
array(new Dimension(320, 320), ResizeFilter::RESIZEMODE_FIT, 640, 480, 2, array('-vf', '[in]scale=320:320 [out]')),
|
||||||
array(new Dimension(320, 320), ResizeFilter::RESIZEMODE_INSET, 640, 480, 2, array('-s', '320x240')),
|
array(new Dimension(320, 320), ResizeFilter::RESIZEMODE_INSET, 640, 480, 2, array('-vf', '[in]scale=320:240 [out]')),
|
||||||
array(new Dimension(320, 320), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 640, 480, 2, array('-s', '320x240')),
|
array(new Dimension(320, 320), ResizeFilter::RESIZEMODE_SCALE_HEIGHT, 640, 480, 2, array('-vf', '[in]scale=320:240 [out]')),
|
||||||
array(new Dimension(320, 320), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 640, 480, 2, array('-s', '426x320')),
|
array(new Dimension(320, 320), ResizeFilter::RESIZEMODE_SCALE_WIDTH, 640, 480, 2, array('-vf', '[in]scale=426:320 [out]')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue