110 lines
2.8 KiB
PHP
110 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace VfxApply;
|
|
|
|
class Application
|
|
{
|
|
|
|
protected $plugins = [];
|
|
|
|
protected $presets = [];
|
|
|
|
public function readPlugins()
|
|
{
|
|
$iter = new \DirectoryIterator(
|
|
__DIR__."/../plugins"
|
|
);
|
|
foreach ($iter as $dir) {
|
|
if (!$dir->isDir())
|
|
continue;
|
|
if (!file_exists($dir->getPathname()."/plugin.php"))
|
|
continue;
|
|
$this->loadPlugin($dir->getPathname());
|
|
}
|
|
}
|
|
|
|
public function readPresets()
|
|
{
|
|
$iter = new \RecursiveIteratorIterator(
|
|
new \RecursiveDirectoryIterator(
|
|
__DIR__."/../presets"
|
|
));
|
|
foreach ($iter as $file) {
|
|
if ($file->isDir() || ($file->getExtension()!='yml'))
|
|
continue;
|
|
$this->loadPreset($file->getPathname());
|
|
}
|
|
}
|
|
|
|
private function loadPlugin($path)
|
|
{
|
|
$plugin = require_once $path."/plugin.php";
|
|
$this->plugins[$plugin->getName()] = $plugin;
|
|
}
|
|
|
|
private function loadPreset($file)
|
|
{
|
|
$preset = Preset::createFromFile($file);
|
|
$id = basename($file,".yml");
|
|
$this->presets[$id] = $preset;
|
|
}
|
|
|
|
private function selectPreset()
|
|
{
|
|
$cmdl = "zenity --list --column=Group --column=Preset --column=Description ".
|
|
"--title=\"Apply VFX\" ".
|
|
"--width=400 --height=400 ".
|
|
"--text=\"Select the preset to apply\" ".
|
|
"--mid-search --print-column=2 ";
|
|
foreach ($this->presets as $id=>$preset) {
|
|
$cmdl.=sprintf(
|
|
"%s %s %s ",
|
|
escapeshellarg($preset->getGroup()),
|
|
escapeshellarg($id),
|
|
escapeshellarg($preset->getName())
|
|
);
|
|
}
|
|
|
|
exec($cmdl." 2>/dev/null", $output, $retval);
|
|
if ($retval == 0) {
|
|
$name = trim($output[0]);
|
|
return $this->presets[$name];
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function run()
|
|
{
|
|
$this->readPlugins();
|
|
$this->readPresets();
|
|
|
|
$opts = getopt("i:o:");
|
|
|
|
$input = new Input();
|
|
if (!empty($opts['i'])) {
|
|
$input->setFilename($opts['i']);
|
|
} else {
|
|
if (!$input->selectFile()) {
|
|
return 1;
|
|
}
|
|
}
|
|
$input->analyze();
|
|
|
|
$dur = $input->getVideoDuration();
|
|
printf("Input: %s %.2fs (%d frames)\n", $input->getFilename(), $dur->seconds, $dur->frames);
|
|
|
|
if (!($preset = $this->selectPreset())) {
|
|
return 1;
|
|
}
|
|
$plugin_name = $preset->getPlugin();
|
|
$plugin = $this->plugins[$plugin_name];
|
|
|
|
$output = new Output();
|
|
$output->setFilename("/tmp/out.mp4");
|
|
|
|
$plugin->applyPreset($preset, $input, $output);
|
|
|
|
}
|
|
|
|
} |