From 16688fae3c20ea60ff8f8ca71831c562f14027b4 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 22 Dec 2018 17:18:03 +0100 Subject: [PATCH] added mp4 preview image generation --- README.md | 3 ++- controllers/video/video.controller.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59491dc..b894e92 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ PictShare is a selfhostable, open source image, video and text hosting as well a - [x] Write permission detection ### Image hosting -- [x] Upload of images - [ ] Resizing - [ ] Filters - [ ] Gif to mp4 conversion +- [x] Upload of images ### Text file hosting - [x] Upload of text files @@ -36,6 +36,7 @@ PictShare is a selfhostable, open source image, video and text hosting as well a ### MP4 hosting - [ ] Resizing +- [x] Preview image generation - [x] Upload of videos - [x] Automatic conversion if not mobile friendly or wrong encoder used - [x] Render template for videos \ No newline at end of file diff --git a/controllers/video/video.controller.php b/controllers/video/video.controller.php index f0c6877..8451d96 100644 --- a/controllers/video/video.controller.php +++ b/controllers/video/video.controller.php @@ -14,6 +14,18 @@ class VideoController if(in_array('raw',$url)) $this->serveMP4($path,$hash); + else if(in_array('preview',$url)) + { + $preview = ROOT.DS.'data'.DS.$hash.DS.'preview.jpg'; + if(!file_exists($preview)) + { + $this->saveFirstFrameOfMP4($path,$preview); + } + + header ("Content-type: image/jpeg"); + readfile($preview); + + } else if(in_array('download',$url)) { if (file_exists($path)) { @@ -174,4 +186,13 @@ class VideoController unlink(ROOT.DS.'tmp'.DS.$hash.'.txt'); return false; } + + function saveFirstFrameOfMP4($path,$target) + { + $bin = escapeshellcmd(FFMPEG_BINARY); + $file = escapeshellarg($path); + $cmd = "$bin -y -i $file -vframes 1 -f image2 $target"; + + system($cmd); + } } \ No newline at end of file