Added understanding of video codecs, primarily to allow us to determine whether a file is a webm or not, but also to support my forthcoming video transcoding extension

This commit is contained in:
Matthew Barbour 2020-08-17 17:05:51 -05:00
parent 988bc831b2
commit 65aca09203
4 changed files with 22 additions and 1 deletions

View file

@ -439,7 +439,7 @@ class Image
$database->execute( $database->execute(
"UPDATE images SET ". "UPDATE images SET ".
"lossless = :lossless, ". "lossless = :lossless, ".
"video = :video, audio = :audio,image = :image, ". "video = :video, video_codec = :video_codec, audio = :audio,image = :image, ".
"height = :height, width = :width, ". "height = :height, width = :width, ".
"length = :length WHERE id = :id", "length = :length WHERE id = :id",
[ [
@ -448,6 +448,7 @@ class Image
"height" => $this->height ?? 0, "height" => $this->height ?? 0,
"lossless" => $database->scoresql_value_prepare($this->lossless), "lossless" => $database->scoresql_value_prepare($this->lossless),
"video" => $database->scoresql_value_prepare($this->video), "video" => $database->scoresql_value_prepare($this->video),
"video_codec" => $database->scoresql_value_prepare($this->video_codec),
"image" => $database->scoresql_value_prepare($this->image), "image" => $database->scoresql_value_prepare($this->image),
"audio" => $database->scoresql_value_prepare($this->audio), "audio" => $database->scoresql_value_prepare($this->audio),
"length" => $this->length "length" => $this->length

View file

@ -67,6 +67,7 @@ class VideoFileHandler extends DataHandlerExtension
if (array_key_exists("streams", $data)) { if (array_key_exists("streams", $data)) {
$video = false; $video = false;
$audio = true; $audio = true;
$video_codec = null;
$streams = $data["streams"]; $streams = $data["streams"];
if (is_array($streams)) { if (is_array($streams)) {
foreach ($streams as $stream) { foreach ($streams as $stream) {
@ -79,6 +80,7 @@ class VideoFileHandler extends DataHandlerExtension
break; break;
case "video": case "video":
$video = true; $video = true;
$video_codec = $stream["codec_name"];
break; break;
} }
} }
@ -93,7 +95,15 @@ class VideoFileHandler extends DataHandlerExtension
} }
} }
$event->image->video = $video; $event->image->video = $video;
$event->image->video_codec = $video_codec;
$event->image->audio = $audio; $event->image->audio = $audio;
if($event->image->get_mime()==MimeType::MKV &&
($event->image->video_codec == "vp9" ||
$event->image->video_codec == "vp8")) {
// WEBMs are MKVs with the VP9 or VP8 codec
// For browser-friendliness, we'll just change the mime type
$event->image->set_mime(MimeType::WEBM);
}
} }
} }
if (array_key_exists("format", $data)&& is_array($data["format"])) { if (array_key_exists("format", $data)&& is_array($data["format"])) {

View file

@ -931,6 +931,13 @@ class Media extends Extension
$database->begin_transaction(); $database->begin_transaction();
} }
if ($this->get_version(MediaConfig::VERSION) < 3) {
$database->execute($database->scoreql_to_sql(
"ALTER TABLE images ADD COLUMN video_codec varchar(512) NULL"
));
$this->set_version(MediaConfig::VERSION, 3);
}
} }
public static function hex_color_allocate($im, $hex) public static function hex_color_allocate($im, $hex)

View file

@ -34,6 +34,9 @@ class CustomViewImageTheme extends ViewImageTheme
<br>Filesize: $h_filesize <br>Filesize: $h_filesize
<br>Type: ".$h_type." <br>Type: ".$h_type."
"; ";
if($image->video_codec!=null) {
$html .= "<br/>Video Codec: $image->video_codec";
}
if ($image->length!=null) { if ($image->length!=null) {
$h_length = format_milliseconds($image->length); $h_length = format_milliseconds($image->length);
$html .= "<br/>Length: $h_length"; $html .= "<br/>Length: $h_length";