Initial Video Thumbnail Support
This commit is contained in:
parent
d8afc46626
commit
a5e8106b7a
2 changed files with 16 additions and 2 deletions
|
@ -8,7 +8,7 @@ DISCLAIMER: This was just quickly hacked together, it might not be up to any qua
|
||||||
|
|
||||||
Copy conf/config.sample.php to config.php and edit accordingly.
|
Copy conf/config.sample.php to config.php and edit accordingly.
|
||||||
|
|
||||||
A webserver with PHP (tested with 7.4 and 8.0) support and the php-gd and php-exif extensions (for thumbnails) is required. An example config for nginx with php-fpm might look something like this:
|
A webserver with PHP (tested with 7.4 and 8.0) support and the php-gd and php-exif extensions (for image thumbnails) and installed ffmpeg (for video thumbnails) is required. An example config for nginx with php-fpm might look something like this:
|
||||||
|
|
||||||
worker_processes 4;
|
worker_processes 4;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ class thumb {
|
||||||
protected int $w = 200;
|
protected int $w = 200;
|
||||||
protected int $h = 200;
|
protected int $h = 200;
|
||||||
|
|
||||||
|
protected string $ffmpeg_cmd = '/usr/bin/ffmpeg'
|
||||||
|
protected string $ffprobe_cmd = '/usr/bin/ffprobe';
|
||||||
|
|
||||||
const IMAGE_HANDLERS = [
|
const IMAGE_HANDLERS = [
|
||||||
IMAGETYPE_JPEG => [
|
IMAGETYPE_JPEG => [
|
||||||
'load' => 'imagecreatefromjpeg',
|
'load' => 'imagecreatefromjpeg',
|
||||||
|
@ -39,7 +42,18 @@ class thumb {
|
||||||
if (!file_exists($dstpath)) {
|
if (!file_exists($dstpath)) {
|
||||||
|
|
||||||
if(str_starts_with(mime_content_type($src), 'video/')) {
|
if(str_starts_with(mime_content_type($src), 'video/')) {
|
||||||
|
$cmd = $this->ffprobe_cmd.' -i "'.$src.'" -show_entries format=duration -v quiet -of csv="p=0"';
|
||||||
|
exec($cmd, $output, $retval);
|
||||||
|
$seconds = ($output[0]*10) / 100;
|
||||||
|
|
||||||
|
$cmd = $this->ffmpeg_cmd.' -i "'.$src.'" -an -ss '.$seconds.' -t 00:00:01 -vf scale=w='.$this->w.':h='.$this->h.':force_original_aspect_ratio=decrease -r 1 -y -vcodec mjpeg -f mjpeg '.$dstpath.' 2>&1';
|
||||||
|
exec($cmd, $output, $retval);
|
||||||
|
|
||||||
|
if ($retval) {
|
||||||
return "img/video.png";
|
return "img/video.png";
|
||||||
|
} else {
|
||||||
|
return $this->thumburl.$dstname.'.jpg';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = exif_imagetype($src);
|
$type = exif_imagetype($src);
|
||||||
|
|
Loading…
Reference in a new issue