summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshadlaws <shad@shadlaws.com>2012-12-18 15:58:13 +0100
committershadlaws <shad@shadlaws.com>2012-12-18 15:58:13 +0100
commitce68177ba0dc27010435e55b79cbea453751f8ee (patch)
tree90abf82dfadf5bf4c79233798efca1aaafb51963
parentf2a32526be0a307005052105ed09bc337e29d333 (diff)
[#1928 - Make thumbnail generation more flexible for movies (graphics and movie helpers)]
- graphics helper: add movie_extract_frame event to generate function (allows modules to add to the options sent to movie::extract_frame or to generate the thumbnail on their own without movie::extract_frame) - movie helper: add extra optional argument to movie::extract_frame (can add ffmpeg arguments and/or change the frame extract time) - gallery_installer: add movie_extract_time module variable, update to v53 - module.info: update to v53 - install.sql: update to v53
-rw-r--r--installer/install.sql5
-rw-r--r--modules/gallery/helpers/gallery_installer.php10
-rw-r--r--modules/gallery/helpers/graphics.php26
-rw-r--r--modules/gallery/helpers/movie.php34
-rw-r--r--modules/gallery/module.info2
5 files changed, 59 insertions, 18 deletions
diff --git a/installer/install.sql b/installer/install.sql
index 44ed1bf4..b01c5a7c 100644
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -244,7 +244,7 @@ CREATE TABLE {modules} (
KEY `weight` (`weight`)
) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
-INSERT INTO {modules} VALUES (1,1,'gallery',52,1);
+INSERT INTO {modules} VALUES (1,1,'gallery',53,1);
INSERT INTO {modules} VALUES (2,1,'user',4,2);
INSERT INTO {modules} VALUES (3,1,'comment',7,3);
INSERT INTO {modules} VALUES (4,1,'organize',4,4);
@@ -382,7 +382,7 @@ CREATE TABLE {vars} (
`value` text,
PRIMARY KEY (`id`),
UNIQUE KEY `module_name` (`module_name`,`name`)
-) AUTO_INCREMENT=45 DEFAULT CHARSET=utf8;
+) AUTO_INCREMENT=46 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO {vars} VALUES (NULL,'gallery','active_site_theme','wind');
INSERT INTO {vars} VALUES (NULL,'gallery','active_admin_theme','admin_wind');
@@ -415,6 +415,7 @@ INSERT INTO {vars} VALUES (NULL,'gallery','show_user_profiles_to','registered_us
INSERT INTO {vars} VALUES (NULL,'gallery','extra_binary_paths','/usr/local/bin:/opt/local/bin:/opt/bin');
INSERT INTO {vars} VALUES (NULL,'gallery','timezone',NULL);
INSERT INTO {vars} VALUES (NULL,'gallery','lock_timeout','1');
+INSERT INTO {vars} VALUES (NULL,'gallery','movie_extract_frame_time','3');
INSERT INTO {vars} VALUES (NULL,'gallery','blocks_site_sidebar','a:4:{i:10;a:2:{i:0;s:7:\"gallery\";i:1;s:8:\"language\";}i:11;a:2:{i:0;s:4:\"info\";i:1;s:8:\"metadata\";}i:12;a:2:{i:0;s:3:\"rss\";i:1;s:9:\"rss_feeds\";}i:13;a:2:{i:0;s:3:\"tag\";i:1;s:3:\"tag\";}}');
INSERT INTO {vars} VALUES (NULL,'gallery','identity_provider','user');
INSERT INTO {vars} VALUES (NULL,'user','minimum_password_length','5');
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 1f190800..597771f3 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -313,8 +313,9 @@ class gallery_installer {
module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin");
module::set_var("gallery", "timezone", null);
module::set_var("gallery", "lock_timeout", 1);
+ module::set_var("gallery", "movie_extract_frame_time", 3);
- module::set_version("gallery", 52);
+ module::set_version("gallery", 53);
}
static function upgrade($version) {
@@ -735,6 +736,13 @@ class gallery_installer {
->execute();
module::set_version("gallery", $version = 52);
}
+
+ if ($version == 52) {
+ // In v53, we added the ability to change the default time used when extracting frames from
+ // movies. Previously we hard-coded this at 3 seconds, so we use that as the default.
+ module::set_var("gallery", "movie_extract_frame_time", 3);
+ module::set_version("gallery", $version = 53);
+ }
}
static function uninstall() {
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index c19fbe6d..c7f87403 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -155,13 +155,27 @@ class graphics_Core {
try {
foreach ($ops as $target => $output_file) {
if ($input_item->is_movie()) {
- // Convert the movie to a JPG first
+ // Convert the movie filename to a JPG first, delete anything that might already be there
$output_file = legal_file::change_extension($output_file, "jpg");
- try {
- movie::extract_frame($input_file, $output_file);
- } catch (Exception $e) {
- // Assuming this is MISSING_FFMPEG for now
- copy(MODPATH . "gallery/images/missing_movie.jpg", $output_file);
+ unlink($output_file);
+ // Run movie_extract_frame events, which can either:
+ // - generate an output file, bypassing the ffmpeg-based movie::extract_frame
+ // - add to the options sent to movie::extract_frame (e.g. change frame extract time,
+ // add de-interlacing arguments to ffmpeg... see movie helper for more info)
+ // Note that the args are similar to those of the events in gallery_graphics
+ $movie_options_wrapper = new stdClass();
+ $movie_options_wrapper->movie_options = array();
+ module::event("movie_extract_frame", $input_file, $output_file,
+ $movie_options_wrapper, $input_item);
+ // If no output_file generated by events, run movie::extract_frame with movie_options
+ clearstatcache();
+ if (@filesize($output_file) == 0) {
+ try {
+ movie::extract_frame($input_file, $output_file, $movie_options_wrapper->movie_options);
+ } catch (Exception $e) {
+ // Didn't work, likely because of MISSING_FFMPEG - copy missing_movie instead
+ copy(MODPATH . "gallery/images/missing_movie.jpg", $output_file);
+ }
}
$working_file = $output_file;
} else {
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index ddc513ea..6d70ab2d 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -57,7 +57,16 @@ class movie_Core {
return $form;
}
- static function extract_frame($input_file, $output_file) {
+ /**
+ * Extract a frame from a movie file. Valid movie_options are start_time (in seconds),
+ * input_args (extra ffmpeg input args) and output_args (extra ffmpeg output args). Extra args
+ * are added at the end of the list, so they can override any prior args.
+ *
+ * @param string $input_file
+ * @param string $output_file
+ * @param array $movie_options (optional)
+ */
+ static function extract_frame($input_file, $output_file, $movie_options=NULL) {
$ffmpeg = movie::find_ffmpeg();
if (empty($ffmpeg)) {
throw new Exception("@todo MISSING_FFMPEG");
@@ -65,23 +74,32 @@ class movie_Core {
list($width, $height, $mime_type, $extension, $duration) = movie::get_file_metadata($input_file);
- // extract frame at 0:03, unless movie is shorter than 4 sec.
- $start_time_arg = ($duration > 4) ? " -ss 00:00:03" : "";
-
- $cmd = escapeshellcmd($ffmpeg) . " -i " . escapeshellarg($input_file) .
+ if (is_numeric($movie_options["start_time"])) {
+ $start_time = max(0, $movie_options["start_time"]); // ensure it's non-negative
+ } else {
+ $start_time = module::get_var("gallery", "movie_extract_frame_time", 3); // use default
+ }
+ // extract frame at start_time, unless movie is too short
+ $start_time_arg = ($duration >= $start_time + 0.1) ?
+ "-ss " . date("H:i:s", mktime(0,0,$start_time,0,0,0,0)) : "";
+
+ $input_args = $movie_options["input_args"] ? $movie_options["input_args"] : "";
+ $output_args = $movie_options["output_args"] ? $movie_options["output_args"] : "";
+
+ $cmd = escapeshellcmd($ffmpeg) . " $input_args -i " . escapeshellarg($input_file) .
" -an $start_time_arg -an -r 1 -vframes 1" .
" -s {$width}x{$height}" .
- " -y -f mjpeg " . escapeshellarg($output_file) . " 2>&1";
+ " -y -f mjpeg $output_args " . escapeshellarg($output_file) . " 2>&1";
exec($cmd, $exec_output, $exec_return);
clearstatcache(); // use $filename parameter when PHP_version is 5.3+
if (filesize($output_file) == 0 || $exec_return) {
// Maybe the movie needs the "-threads 1" argument added
// (see http://sourceforge.net/apps/trac/gallery/ticket/1924)
- $cmd = escapeshellcmd($ffmpeg) . " -threads 1 -i " . escapeshellarg($input_file) .
+ $cmd = escapeshellcmd($ffmpeg) . " -threads 1 $input_args -i " . escapeshellarg($input_file) .
" -an $start_time_arg -an -r 1 -vframes 1" .
" -s {$width}x{$height}" .
- " -y -f mjpeg " . escapeshellarg($output_file) . " 2>&1";
+ " -y -f mjpeg $output_args " . escapeshellarg($output_file) . " 2>&1";
exec($cmd, $exec_output, $exec_return);
clearstatcache();
diff --git a/modules/gallery/module.info b/modules/gallery/module.info
index faefd663..64cad0a7 100644
--- a/modules/gallery/module.info
+++ b/modules/gallery/module.info
@@ -1,6 +1,6 @@
name = "Gallery 3"
description = "Gallery core application"
-version = 52
+version = 53
author_name = "Gallery Team"
author_url = "http://codex.gallery2.org/Gallery:Team"
info_url = "http://codex.gallery2.org/Gallery3:Modules:gallery"