namespace Fluidbook\Tools\Links;
+use Cubist\Util\Files\Files;
use Cubist\Util\Url;
+use Illuminate\Support\Facades\Cache;
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;