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.

This commit is contained in:
jgen 2014-12-14 15:22:44 -08:00
parent 5012b15ce9
commit 433d67453c

View File

@ -47,22 +47,23 @@ class VideoFileHandler extends DataHandlerExtension {
$sb->add_text_option("thumb_ffmpeg_path"); $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("<br>");
$sb->add_bool_option("video_thumb_ignore_aspect_ratio", "Ignore aspect ratio when creating thumbnails: "); $sb->add_bool_option("video_thumb_ignore_aspect_ratio", "Ignore aspect ratio when creating thumbnails: ");
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
/** /**
* Generate the Thumbnail image for particular file.
*
* @param string $hash * @param string $hash
* @return bool * @return bool Returns true on successful thumbnail creation.
*/ */
protected function create_thumb($hash) { protected function create_thumb($hash) {
global $config; global $config;
// this is never used...
//$q = $config->get_int("thumb_quality");
$ok = false; $ok = false;
switch($config->get_string("video_thumb_engine")) switch($config->get_string("video_thumb_engine"))
@ -73,26 +74,33 @@ class VideoFileHandler extends DataHandlerExtension {
copy("ext/handle_video/thumb.jpg", $outname); copy("ext/handle_video/thumb.jpg", $outname);
$ok = true; $ok = true;
break; break;
case 'ffmpeg': 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"); $w = (int)$config->get_int("thumb_width");
$h = (int)$config->get_int("thumb_height"); $h = (int)$config->get_int("thumb_height");
$inname = escapeshellarg(warehouse_path("images", $hash)); $inname = escapeshellarg(warehouse_path("images", $hash));
$outname = escapeshellarg(warehouse_path("thumbs", $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}"); $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. if ((int)$returnValue == (int)1)
$ok = true; {
$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; break;
} }