From 02efa180deaf5ec039647b68eaae3e8dd672d99a Mon Sep 17 00:00:00 2001 From: jgen Date: Sat, 13 Dec 2014 16:54:21 -0800 Subject: [PATCH 1/6] Add a default option to ignore aspect ratio when creating a thumbnail with FFmpeg. --- ext/handle_video/main.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index 781a9220..721ae709 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -21,6 +21,7 @@ class VideoFileHandler extends DataHandlerExtension { public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_string('video_thumb_engine', 'static'); + $config->set_default_bool('video_thumb_ignore_aspect_ratio', true); $config->set_default_string('thumb_ffmpeg_path', ''); } @@ -39,6 +40,10 @@ class VideoFileHandler extends DataHandlerExtension { $sb->add_label("
Path to ffmpeg: "); $sb->add_text_option("thumb_ffmpeg_path"); //} + + // Some versions of ffmpeg have trouble with the automatic aspect ratio scaling. + $sb->add_bool_option("video_thumb_ignore_aspect_ratio", "Ignore aspect ratio when creating thumbnails: "); + $event->panel->add_block($sb); } @@ -70,7 +75,11 @@ class VideoFileHandler extends DataHandlerExtension { $inname = escapeshellarg(warehouse_path("images", $hash)); $outname = escapeshellarg(warehouse_path("thumbs", $hash)); - $cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -vf scale='if(gt(a,{$w}/{$h}),{$w},-1)':'if(gt(a,{$w}/{$h}),-1,{$h})' -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"); + if ($config->get_bool("video_thumb_ignore_aspect_ratio", true) == true) { + $cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"); + } else { + $cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -vf scale='if(gt(a,{$w}/{$h}),{$w},-1)':'if(gt(a,{$w}/{$h}),-1,{$h})' -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"); + } exec($cmd, $output, $ret); From 2ff036d250374d0f3f28d92158af6939844d3c7e Mon Sep 17 00:00:00 2001 From: jgen Date: Sun, 14 Dec 2014 15:19:59 -0800 Subject: [PATCH 2/6] Remove unused variables. --- ext/handle_video/main.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index 721ae709..46e3cf1f 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -26,8 +26,8 @@ class VideoFileHandler extends DataHandlerExtension { } public function onSetupBuilding(SetupBuildingEvent $event) { - global $config; - + //global $config; + $thumbers = array(); $thumbers['None'] = "static"; $thumbers['ffmpeg'] = "ffmpeg"; @@ -108,7 +108,6 @@ class VideoFileHandler extends DataHandlerExtension { * @return Image|null */ protected function create_image_from_data($filename, $metadata) { - //global $config; $image = new Image(); From 5012b15ce9faaabd6e3397ef52f097528651cbf3 Mon Sep 17 00:00:00 2001 From: jgen Date: Sun, 14 Dec 2014 15:20:47 -0800 Subject: [PATCH 3/6] Comment as to why the default is to ignore the aspect ratio. --- ext/handle_video/main.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index 46e3cf1f..6b679278 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -21,8 +21,14 @@ class VideoFileHandler extends DataHandlerExtension { public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_string('video_thumb_engine', 'static'); - $config->set_default_bool('video_thumb_ignore_aspect_ratio', true); $config->set_default_string('thumb_ffmpeg_path', ''); + + // By default we generate thumbnails ignoring the aspect ratio of the video file. + // + // Why? - This allows Shimmie to work with older versions of FFmpeg by default, + // rather than completely failing out of the box. If people complain that their + // thumbnails are distorted, then they can turn this feature on manually later. + $config->set_default_bool('video_thumb_ignore_aspect_ratio', true); } public function onSetupBuilding(SetupBuildingEvent $event) { From 433d67453cd841bb729d25a85e79f488c1f5d69d Mon Sep 17 00:00:00 2001 From: jgen Date: Sun, 14 Dec 2014 15:22:44 -0800 Subject: [PATCH 4/6] This fixes issue #466. You can now optionally generate thumbnails for videos with the newer versions of FFmpeg that take into account the aspect ratio. --- ext/handle_video/main.php | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index 6b679278..4a253d5b 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -47,22 +47,23 @@ class VideoFileHandler extends DataHandlerExtension { $sb->add_text_option("thumb_ffmpeg_path"); //} - // Some versions of ffmpeg have trouble with the automatic aspect ratio scaling. + // Some older versions of ffmpeg have trouble with the automatic aspect ratio scaling. + // This adds an option in the Board Config to disable the aspect ratio scaling. + $sb->add_label("
"); $sb->add_bool_option("video_thumb_ignore_aspect_ratio", "Ignore aspect ratio when creating thumbnails: "); $event->panel->add_block($sb); } /** + * Generate the Thumbnail image for particular file. + * * @param string $hash - * @return bool + * @return bool Returns true on successful thumbnail creation. */ protected function create_thumb($hash) { global $config; - // this is never used... - //$q = $config->get_int("thumb_quality"); - $ok = false; switch($config->get_string("video_thumb_engine")) @@ -73,26 +74,33 @@ class VideoFileHandler extends DataHandlerExtension { copy("ext/handle_video/thumb.jpg", $outname); $ok = true; break; + case 'ffmpeg': - $ffmpeg = escapeshellarg($config->get_string("thumb_ffmpeg_path")); + $ffmpeg = escapeshellcmd($config->get_string("thumb_ffmpeg_path")); $w = (int)$config->get_int("thumb_width"); $h = (int)$config->get_int("thumb_height"); $inname = escapeshellarg(warehouse_path("images", $hash)); $outname = escapeshellarg(warehouse_path("thumbs", $hash)); - - if ($config->get_bool("video_thumb_ignore_aspect_ratio", true) == true) { + + if ($config->get_bool("video_thumb_ignore_aspect_ratio") == true) + { $cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"); - } else { - $cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -vf scale='if(gt(a,{$w}/{$h}),{$w},-1)':'if(gt(a,{$w}/{$h}),-1,{$h})' -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"); + } + else + { + $scale = 'scale="' . escapeshellarg("if(gt(a,{$w}/{$h}),{$w},-1)") . ':' . escapeshellarg("if(gt(a,{$w}/{$h}),-1,{$h})") . '"'; + $cmd = "{$ffmpeg} -i {$inname} -vf {$scale} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"; } - exec($cmd, $output, $ret); + exec($cmd, $output, $returnValue); - // TODO: We should really check the result of the exec to see if it really succeeded. - $ok = true; + if ((int)$returnValue == (int)1) + { + $ok = true; + } - log_debug('handle_video', "Generating thumbnail with command `$cmd`, returns $ret"); + log_debug('handle_video', "Generating thumbnail with command `$cmd`, returns $returnValue"); break; } From 95b94bd115701a5f4dc22d667b0f6d0c71743e5c Mon Sep 17 00:00:00 2001 From: jgen Date: Sun, 14 Dec 2014 16:06:31 -0800 Subject: [PATCH 5/6] Some minor linting. --- core/user.class.php | 1 + ext/favorites/main.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/user.class.php b/core/user.class.php index 40f8b07b..a6eafc38 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -46,6 +46,7 @@ class User { * would be to use User::by_id, User::by_session, etc. * * @param mixed $row + * @throws SCoreException */ public function __construct($row) { global $_user_classes; diff --git a/ext/favorites/main.php b/ext/favorites/main.php index bdfa7f2e..94a58bc4 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -27,7 +27,7 @@ class FavoriteSetEvent extends Event { * @param bool $do_set */ public function __construct(/*int*/ $image_id, User $user, /*boolean*/ $do_set) { - assert(is_numeric($image_id)); + assert(is_int($image_id)); assert(is_bool($do_set)); $this->image_id = $image_id; From d878526487588ef12194e750466d9bde491fe0eb Mon Sep 17 00:00:00 2001 From: jgen Date: Sun, 14 Dec 2014 16:07:00 -0800 Subject: [PATCH 6/6] Button should say "Regenerate Thumbnail" for clarity. --- ext/regen_thumb/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/regen_thumb/theme.php b/ext/regen_thumb/theme.php index ad2d852d..e7de3afb 100644 --- a/ext/regen_thumb/theme.php +++ b/ext/regen_thumb/theme.php @@ -11,7 +11,7 @@ class RegenThumbTheme extends Themelet { return " ".make_form(make_link("regen_thumb"))." - + "; }