aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/functions_upload.inc.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2016-01-14 11:21:04 +0100
committerplegall <plg@piwigo.org>2016-01-14 11:21:04 +0100
commitc44a5e289021c68fdf882e83835e34fccdc49c50 (patch)
treef3cf6908035e0823585bcf5524298584ac1c03b3 /admin/include/functions_upload.inc.php
parent8ba7a1587a1a3acfbbf45cdcf26c286aa42afad3 (diff)
feature #293, also process videos
... as in Piwigo 2.7, to keep the same level of features. Plugin VideoJS may provide a better algorithm.
Diffstat (limited to '')
-rw-r--r--admin/include/functions_upload.inc.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php
index 0608f59e1..b97c4762f 100644
--- a/admin/include/functions_upload.inc.php
+++ b/admin/include/functions_upload.inc.php
@@ -521,6 +521,54 @@ function upload_file_tiff($representative_ext, $file_path)
return get_extension($representative_file_abspath);
}
+add_event_handler('upload_file', 'upload_file_video');
+function upload_file_video($representative_ext, $file_path)
+{
+ global $logger, $conf;
+
+ $logger->info(__FUNCTION__.', $file_path = '.$file_path.', $representative_ext = '.$representative_ext);
+
+ if (isset($representative_ext))
+ {
+ return $representative_ext;
+ }
+
+ $ffmpeg_video_exts = array( // extensions tested with FFmpeg
+ 'wmv','mov','mkv','mp4','mpg','flv','asf','xvid','divx','mpeg',
+ 'avi','rm',
+ );
+
+ if (!in_array(strtolower(get_extension($file_path)), $ffmpeg_video_exts))
+ {
+ return $representative_ext;
+ }
+
+ $representative_file_path = dirname($file_path).'/pwg_representative/';
+ $representative_file_path.= get_filename_wo_extension(basename($file_path)).'.';
+
+ $representative_ext = 'jpg';
+ $representative_file_path.= $representative_ext;
+
+ prepare_directory(dirname($representative_file_path));
+
+ $second = 1;
+
+ $ffmpeg = $conf['ffmpeg_dir'].'ffmpeg';
+ $ffmpeg.= ' -i "'.$file_path.'"';
+ $ffmpeg.= ' -an -ss '.$second;
+ $ffmpeg.= ' -t 1 -r 1 -y -vcodec mjpeg -f mjpeg';
+ $ffmpeg.= ' "'.$representative_file_path.'"';
+
+ @exec($ffmpeg);
+
+ if (!file_exists($representative_file_path))
+ {
+ return null;
+ }
+
+ return $representative_ext;
+}
+
function prepare_directory($directory)
{
if (!is_dir($directory)) {