Merge pull request #468 from jgen/develop

Allow Shimmie to work with older versions of FFmpeg
This commit is contained in:
Shish 2014-12-17 13:44:25 +00:00
commit caa2691bb9
4 changed files with 39 additions and 16 deletions

View file

@ -46,6 +46,7 @@ class User {
* would be to use User::by_id, User::by_session, etc. * would be to use User::by_id, User::by_session, etc.
* *
* @param mixed $row * @param mixed $row
* @throws SCoreException
*/ */
public function __construct($row) { public function __construct($row) {
global $_user_classes; global $_user_classes;

View file

@ -27,7 +27,7 @@ class FavoriteSetEvent extends Event {
* @param bool $do_set * @param bool $do_set
*/ */
public function __construct(/*int*/ $image_id, User $user, /*boolean*/ $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)); assert(is_bool($do_set));
$this->image_id = $image_id; $this->image_id = $image_id;

View file

@ -22,11 +22,18 @@ class VideoFileHandler extends DataHandlerExtension {
global $config; global $config;
$config->set_default_string('video_thumb_engine', 'static'); $config->set_default_string('video_thumb_engine', 'static');
$config->set_default_string('thumb_ffmpeg_path', ''); $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) { public function onSetupBuilding(SetupBuildingEvent $event) {
global $config; //global $config;
$thumbers = array(); $thumbers = array();
$thumbers['None'] = "static"; $thumbers['None'] = "static";
$thumbers['ffmpeg'] = "ffmpeg"; $thumbers['ffmpeg'] = "ffmpeg";
@ -39,19 +46,24 @@ class VideoFileHandler extends DataHandlerExtension {
$sb->add_label("<br>Path to ffmpeg: "); $sb->add_label("<br>Path to ffmpeg: ");
$sb->add_text_option("thumb_ffmpeg_path"); $sb->add_text_option("thumb_ffmpeg_path");
//} //}
// 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: ");
$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"))
@ -62,22 +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)
{
$cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -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}";
}
$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, $returnValue);
exec($cmd, $output, $ret); if ((int)$returnValue == (int)1)
{
$ok = true;
}
// TODO: We should really check the result of the exec to see if it really succeeded. log_debug('handle_video', "Generating thumbnail with command `$cmd`, returns $returnValue");
$ok = true;
log_debug('handle_video', "Generating thumbnail with command `$cmd`, returns $ret");
break; break;
} }
@ -99,7 +122,6 @@ class VideoFileHandler extends DataHandlerExtension {
* @return Image|null * @return Image|null
*/ */
protected function create_image_from_data($filename, $metadata) { protected function create_image_from_data($filename, $metadata) {
//global $config;
$image = new Image(); $image = new Image();

View file

@ -11,7 +11,7 @@ class RegenThumbTheme extends Themelet {
return " return "
".make_form(make_link("regen_thumb"))." ".make_form(make_link("regen_thumb"))."
<input type='hidden' name='image_id' value='$image_id'> <input type='hidden' name='image_id' value='$image_id'>
<input type='submit' value='Regenerate'> <input type='submit' value='Regenerate Thumbnail'>
</form> </form>
"; ";
} }