diff --git a/app/config/collections.php b/app/config/collections.php index 709ab7aa34..63cb5cd8a9 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -3804,8 +3804,8 @@ $collections = [ 'indexes' => [ [ '$id' => '_key_video_type', - 'type' => Database::INDEX_KEY, - 'attributes' => ['videoId', 'type'], + 'type' => Database::INDEX_UNIQUE, + 'attributes' => ['videoId', 'type', 'name'], 'lengths' => [], 'orders' => [], ], diff --git a/app/controllers/api/videos.php b/app/controllers/api/videos.php index 7d09e18d1a..f86ed50e94 100644 --- a/app/controllers/api/videos.php +++ b/app/controllers/api/videos.php @@ -354,7 +354,8 @@ App::post('/v1/videos/:videoId/preview') } validateFilePermissions($dbForProject, $video['bucketId'], $video['fileId'], $mode); - + var_dump($second); + var_dump($video['duration']); $range = new Range(1, ($video['duration'] / 1000), Validator::TYPE_INTEGER); if (!$range->isValid($second)) { throw new Exception(Exception::VIDEO_SECOND_OUT_OF_RANGE); diff --git a/app/workers/videos.php b/app/workers/videos.php index 542028c451..fe28a2297e 100644 --- a/app/workers/videos.php +++ b/app/workers/videos.php @@ -1,10 +1,12 @@ filters() - ->resize(new \FFMpeg\Coordinate\Dimension(640, 480)) + ->resize(new \FFMpeg\Coordinate\Dimension($this->video->getAttribute('width'), $this->video->getAttribute('height'))) ->synchronize(); $media ->frame(\FFMpeg\Coordinate\TimeCode::fromSeconds($this->args['second'])) ->save($this->outDir . $name); - /** Upload preview**/ + /** + * Upload preview + */ console::info('Uploading ' . $name); $this->getVideoDevice($this->project->getId())->write( @@ -199,15 +191,25 @@ class VideosV1 extends Worker (new Local('/'))->read($this->outDir . $name) ); - $preview = $this->database->createDocument('videos_previews', new Document([ - 'videoId' => $this->video->getId(), - 'type' => 'preview', - 'name' => $name, - 'path' => $path, - ])); + try { + $preview = $this->database->createDocument('videos_previews', new Document([ + 'videoId' => $this->video->getId(), + 'type' => 'preview', + 'name' => $name, + 'path' => $path, + ])); + } catch (Duplicate $th) { + ; + } $this->video->setAttribute('previewId', $preview->getId()); + (new Delete()) + ->setType(DELETE_TYPE_CACHE_BY_RESOURCE) + ->setResource('preview/' . $preview->getId()) + ->trigger(); + + $this->database->updateDocument( 'videos', $this->video->getId(), @@ -220,6 +222,17 @@ class VideosV1 extends Worker } if ($this->action === 'timeline') { + /* + * Title: PlayerJS Thumbnails & WebVTT Creator + * URI: https://playerjs.com/docs/q=thumbnailsphpwebvtt + * Version: 1.0 + * Author: Playerjs.com + * Author URI: https://playerjs.com + * License: GPL-2.0+ + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt + * Text Domain: playerjs + */ + $interval = 2; $ranges = [ ['from' => 120, 'to' => 600, 'interval' => 5], @@ -282,14 +295,19 @@ class VideosV1 extends Worker } if ($counter > 0) { - /** Upload vtt**/ + /** + * Upload vtt + */ $this->getVideoDevice($this->project->getId())->write( $this->getVideoDevice($this->project->getId())->getPath($this->video->getId() . '/timeline/timeline.vtt'), $data ); + console::info('Uploading timeline vtt'); - /** Upload sprites**/ + /** + * Upload sprites* + */ $dir = new DirectoryIterator($this->outDir); foreach ($dir as $fileinfo) { if (!$fileinfo->isDot()) {