Merge pull request #749 from sanmadjack/video_transcode

Video transcoding
This commit is contained in:
Shish
2020-09-16 13:46:18 +01:00
committed by GitHub
13 changed files with 536 additions and 6 deletions

65
core/command_builder.php Normal file
View File

@ -0,0 +1,65 @@
<?php declare(strict_types=1);
// Provides mechanisms for cleanly executing command-line applications
// Was created to try to centralize a solution for whatever caused this:
// quotes are only needed if the path to convert contains a space; some other times, quotes break things, see github bug #27
class CommandBuilder
{
private $executable;
private $args = [];
public $output;
function __construct(String $executable) {
if(empty($executable)) {
throw new InvalidArgumentException("executable cannot be empty");
}
$this->executable = $executable;
}
public function add_flag(string $value): void
{
$this->args[] = $value;
}
public function add_escaped_arg(string $value): void
{
$this->args[] = escapeshellarg($value);
}
public function generate(): string
{
$command = escapeshellarg($this->executable);
if(!empty($this->args)) {
$command .= " ";
$command .= join(" ", $this->args);
}
return escapeshellcmd($command)." 2>&1";
}
public function combineOutput(string $empty_output = ""): string
{
if(empty($this->output)) {
return $empty_output;
} else {
return implode("\r\n", $this->output);
}
}
public function execute(bool $fail_on_non_zero_return = false): int
{
$cmd = $this->generate();
exec($cmd, $this->output, $ret);
$output = $this->combineOutput("nothing");
log_debug('command_builder', "Command `$cmd` returned $ret and outputted $output");
if($fail_on_non_zero_return&&(int)$ret!==(int)0) {
throw new SCoreException("Command `$cmd` failed, returning $ret and outputting $output");
}
return $ret;
}
}

View File

@ -63,6 +63,9 @@ class Image
/** @var boolean */
public $video = null;
/** @var string */
public $video_codec = null;
/** @var boolean */
public $image = null;
@ -439,7 +442,7 @@ class Image
$database->execute(
"UPDATE images SET ".
"lossless = :lossless, ".
"video = :video, audio = :audio,image = :image, ".
"video = :video, video_codec = :video_codec, audio = :audio,image = :image, ".
"height = :height, width = :width, ".
"length = :length WHERE id = :id",
[
@ -448,6 +451,7 @@ class Image
"height" => $this->height ?? 0,
"lossless" => $database->scoresql_value_prepare($this->lossless),
"video" => $database->scoresql_value_prepare($this->video),
"video_codec" => $database->scoresql_value_prepare($this->video_codec),
"image" => $database->scoresql_value_prepare($this->image),
"audio" => $database->scoresql_value_prepare($this->audio),
"length" => $this->length