From 8d496d66d19546da0f00f44f79f30d92d7061175 Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 2 Mar 2023 15:05:15 +0200 Subject: [PATCH] metadata extraction ffmpeg -> mediainfo --- app/config/collections.php | 52 ++++++++++++++++++-- app/workers/transcoding.php | 44 +++++++---------- src/Appwrite/Utopia/Response/Model/Video.php | 41 ++++++++++----- 3 files changed, 97 insertions(+), 40 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 50fb06f90b..81aca3dab5 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -3586,6 +3586,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => 'format', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => 'duration', 'type' => Database::VAR_STRING, @@ -3620,7 +3631,29 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'videoCodec', + '$id' => 'aspectRatio', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'videoFormat', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'videoFormatProfile', 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -3642,7 +3675,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'videoFramerate', + '$id' => 'videoFrameRateMode', 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -3653,7 +3686,18 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'audioCodec', + '$id' => 'videoFrameRate', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'audioFormat', 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -3675,7 +3719,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'audioSamplerate', + '$id' => 'audioSampleRate', 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, diff --git a/app/workers/transcoding.php b/app/workers/transcoding.php index 69310b38d2..8a1aabe74b 100644 --- a/app/workers/transcoding.php +++ b/app/workers/transcoding.php @@ -120,43 +120,37 @@ class TranscodingV1 extends Worker $mediaInfo = new MediaInfo(); $mediaInfoContainer = $mediaInfo->getInfo($inPath); $general = $mediaInfoContainer->getGeneral(); - $this->video-> - setAttribute('duration', strval($general->get('duration')->getMilliseconds())); + $this->video + ->setAttribute('duration', strval($general->get('duration')->getMilliseconds())) + ->setAttribute('format', $general->get('format')->getShortName()); - var_dump($general->get('duration')->getMilliseconds()); - var_dump($general->get('overall_bit_rate')->getShortName()); - - $videos = $mediaInfoContainer->getVideos(); - foreach ($videos as $video) { + foreach ($mediaInfoContainer->getVideos() ?? [] as $video) { $this->video ->setAttribute('height', $video->get('height')->getAbsoluteValue()) ->setAttribute('width', $video->get('width')->getAbsoluteValue()) - ->setAttribute('videoCodec', strval($video->get('format')->getShortName())) - ->setAttribute('videoFramerate', strval($video->get('frame_rate')->getAbsoluteValue())) + ->setAttribute('aspectRatio', $video->get('display_aspect_ratio')->getTextValue()) + ->setAttribute('videoFormat', $video->get('format')->getShortName()) + ->setAttribute('videoFormatProfile', $video->get('video_format_profile')) + ->setAttribute('videoFrameRate', strval($video->get('frame_rate')->getAbsoluteValue())) + ->setAttribute('videoFrameRateMode', $video->get('frame_rate_mode')->getFullName()) ->setAttribute('videoBitrate', strval($video->get('bit_rate')->getAbsoluteValue())); - - var_dump($video->get('format_profile')); - var_dump($video->get('frame_rate_mode')->getFullName()); - var_dump($video->get('display_aspect_ratio')->getTextValue()); } - $audios = $mediaInfoContainer->getAudios(); - - foreach ($audios as $audio) { + foreach ($mediaInfoContainer->getAudios() ?? [] as $audio) { $this->video - ->setAttribute('audioCodec', strval($audio->get('format')->getShortName())) - ->setAttribute('audioSamplerate', strval($audio->get('frame_rate')->getAbsoluteValue())) + ->setAttribute('audioFormat', strval($audio->get('format')->getShortName())) + ->setAttribute('audioSampleRate', strval($audio->get('sampling_rate')->getAbsoluteValue())) ->setAttribute('audioBitrate', strval($audio->get('bit_rate')->getAbsoluteValue())); } - console::info('Input video id:' . $this->video->getId() . PHP_EOL . + console::info('Input video id: ' . $this->video->getId() . PHP_EOL . 'Input name: ' . $this->file->getAttribute('name') . PHP_EOL . - 'Input width: ' . $this->video->getAttribute('width') . PHP_EOL . - 'Input height: ' . $this->video->getAttribute('height') . PHP_EOL . - 'Input duration: ' . $this->video->getAttribute('duration') . PHP_EOL . - 'Input size: ' . $this->video['size'] . PHP_EOL . - 'Input videoBitrate: ' . $this->video->getAttribute('videoBitrate') . PHP_EOL . - 'Input audioBitrate: ' . $this->video->getAttribute('audioBitrate') . PHP_EOL); + 'Input width: ' . $this->video->getAttribute('width') . ' px' . PHP_EOL . + 'Input height: ' . $this->video->getAttribute('height') . ' px' . PHP_EOL . + 'Input duration: ' . ($this->video->getAttribute('duration') / 1000) . ' sec' . PHP_EOL . + 'Input size: ' . ($this->video->getAttribute('size') / 1024 / 1024) . ' MiB' . PHP_EOL . + 'Input videoBitrate: ' . ($this->video->getAttribute('videoBitrate') / 1000) . ' b/s' . PHP_EOL . + 'Input audioBitrate: ' . ($this->video->getAttribute('audioBitrate') / 1000) . ' b/s'); $this->database->updateDocument('videos', $this->video->getId(), $this->video); $media = $this->ffmpeg->open($inPath); diff --git a/src/Appwrite/Utopia/Response/Model/Video.php b/src/Appwrite/Utopia/Response/Model/Video.php index 4c39c3cf0e..ec65abc08f 100644 --- a/src/Appwrite/Utopia/Response/Model/Video.php +++ b/src/Appwrite/Utopia/Response/Model/Video.php @@ -31,9 +31,21 @@ class Video extends Model ->addRule('size', [ 'type' => self::TYPE_INTEGER, 'description' => 'File size.', - 'default' => '', + 'default' => 0, 'example' => 23647142, ]) + ->addRule('format', [ + 'type' => self::TYPE_STRING, + 'description' => 'Format.', + 'default' => '', + 'example' => 'MPEG-4', + ]) + ->addRule('aspectRatio', [ + 'type' => self::TYPE_STRING, + 'description' => 'Aspect ratio .', + 'default' => '', + 'example' => '16:9', + ]) ->addRule('duration', [ 'type' => self::TYPE_STRING, 'require' => false, @@ -55,16 +67,23 @@ class Video extends Model 'default' => 0, 'example' => 544, ]) - ->addRule('videoCodec', [ + ->addRule('videoFormat', [ 'type' => self::TYPE_STRING, 'require' => false, - 'description' => 'Video codec.', - 'default' => null, - 'example' => 'h264,avc1', + 'description' => 'Video format.', + 'default' => '', + 'example' => 'AVC', + ]) + ->addRule('videoFormatProfile', [ + 'type' => self::TYPE_STRING, + 'require' => false, + 'description' => 'Video format profile.', + 'default' => '', + 'example' => 'Baseline@L3.1', ]) ->addRule('videoBitrate', [ 'type' => self::TYPE_INTEGER, - 'require' => false, + 'require' => false, 'description' => 'Video bitrate.', 'default' => 0, 'example' => 564790, @@ -76,12 +95,12 @@ class Video extends Model 'default' => 0, 'example' => '231947377/4638947', ]) - ->addRule('audioCodec', [ + ->addRule('audioFormat', [ 'type' => self::TYPE_STRING, 'require' => false, - 'description' => 'Audio codec.', - 'default' => null, - 'example' => 'aac,mp4a', + 'description' => 'Audio format.', + 'default' => '', + 'example' => 'AAC', ]) ->addRule('audioBitrate', [ 'type' => self::TYPE_INTEGER, @@ -90,7 +109,7 @@ class Video extends Model 'default' => 0, 'example' => 127999, ]) - ->addRule('audioSamplerate', [ + ->addRule('audioSampleRate', [ 'type' => self::TYPE_INTEGER, 'require' => false, 'description' => 'Audio sample rate.',