]> _ Git - fluidbook_tools.git/commitdiff
wip #5184 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 29 Mar 2022 12:30:39 +0000 (14:30 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 29 Mar 2022 12:30:39 +0000 (14:30 +0200)
src/Links/VideoLink.php

index 5fa315624b10e03563c16158fcf0b4f04b26c916..ba457c69dd122d8b450626173663490ed85b50dd 100644 (file)
@@ -2,7 +2,9 @@
 
 namespace Fluidbook\Tools\Links;
 
+use Cubist\Util\Files\Files;
 use Cubist\Util\Url;
+use Illuminate\Support\Facades\Cache;
 
 class VideoLink extends Link
 {
@@ -80,16 +82,19 @@ class VideoLink extends Link
             $attr['width'] = $w;
             $attr['height'] = $h;
         } else if (!is_null($compiler) && Url::isLocal($data->to)) {
-            // Get video dimensions from thumbnail if possible (locally uploaded files)
             $path = file_exists($data->to) ? $data->to : $compiler->wdir . '/' . $data->to;
-            $e = explode(',', `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 $path`);
-            if (count($e) > 1) {
-                $attr['width'] = $e[0];
-                $attr['height'] = $e[1];
-            } else {
-                $attr['width'] = 1920;
-                $attr['height'] = 1080;
-            }
+
+            $dim = Cache::get('videosize_' . Files::hashFileAttributes($path), function () use ($path) {
+                $e = explode(',', `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 $path`);
+                $res = ['width' => 1920, 'height' => 1080];
+                if (count($e) > 1) {
+                    $res['width'] = $e[0];
+                    $res['height'] = $e[1];
+                }
+                return $res;
+            });
+            // Get video dimensions from thumbnail if possible (locally uploaded files)
+            $attr = array_merge($attr, $dim);
         }
 
         return $attr;