Merge pull request #406 from jgen/video_thumb

Video thumbnails
This commit is contained in:
Shish 2014-04-20 11:25:24 +01:00
commit 44d0e56c97
2 changed files with 41 additions and 8 deletions

View file

@ -2,6 +2,7 @@
/*
* Name: Handle Video
* Author: velocity37 <velocity37@gmail.com>
* Modified By: Shish <webmaster@shishnet.org>, jgen <jeffgenovy@gmail.com>
* License: GPLv2
* Description: Handle FLV, MP4, OGV and WEBM video files.
* Documentation:
@ -17,25 +18,56 @@
*/
class VideoFileHandler extends DataHandlerExtension {
protected function create_thumb($hash) {
public function onInitExt(InitExtEvent $event) {
global $config;
$config->set_default_string('video_thumb_engine', 'static');
$config->set_default_string('thumb_ffmpeg_path', '');
}
public function onSetupBuilding(SetupBuildingEvent $event) {
global $config;
$w = $config->get_int("thumb_width");
$h = $config->get_int("thumb_height");
$q = $config->get_int("thumb_quality");
$thumbers = array();
$thumbers['None'] = "static";
$thumbers['ffmpeg'] = "ffmpeg";
$sb = new SetupBlock("Video Thumbnail Options");
$sb->add_choice_option("video_thumb_engine", $thumbers, "Engine: ");
if($config->get_string("video_thumb_engine") == "ffmpeg") {
$sb->add_label("<br>Path to ffmpeg: ");
$sb->add_text_option("thumb_ffmpeg_path");
}
$event->panel->add_block($sb);
}
protected function create_thumb($hash) {
global $config;
$w = (int)$config->get_int("thumb_width");
$h = (int)$config->get_int("thumb_height");
// this is never used...
//$q = $config->get_int("thumb_quality");
$inname = warehouse_path("images", $hash);
$outname = warehouse_path("thumbs", $hash);
switch($config->get_string("video_thumb_engine")) {
switch($config->get_string("video_thumb_engine"))
{
default:
case 'static':
copy("ext/handle_video/thumb.jpg", $outname);
break;
case 'ffmpeg':
$ffmpeg = $config->get_string("thumb_ffmpeg_path");
$cmd = "$ffmpeg -i $inname -s {$w}x{$h} -ss 00:00:00.0 -f image2 -vframes 1 $outname"
$inname = escapeshellarg($inname);
$outname = escapeshellarg($outname);
$cmd = "{$ffmpeg} -i {$inname} -s {$w}x{$h} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}";
exec($cmd, $output, $ret);
log_debug('handle_video', "Generating thumbnail with command `$cmd`, returns $ret");
break;
}
@ -47,7 +79,7 @@ class VideoFileHandler extends DataHandlerExtension {
}
protected function create_image_from_data($filename, $metadata) {
global $config;
//global $config;
$image = new Image();

View file

@ -27,7 +27,8 @@ else {
<source src='" . make_link("/image/" . $image->id) . "' type='video/ogg' />
</video>";
} elseif ($ext == "webm") {
$html = "Video not playing? <a href='" . $image->parse_link_template(make_link('image/$id/$id%20-%20$tags.$ext')) . "'>Click here</a> to download the file.<br><video controls='controls' autoplay='autoplay'>
$ie_only = "<!--[if IE]><p>To view webm files with IE, please <a href='http://tools.google.com/dlpage/webmmf/' target='_blank'>download this plugin</a>.</p><![endif]-->";
$html = $ie_only ."Video not playing? <a href='" . $image->parse_link_template(make_link('image/$id/$id%20-%20$tags.$ext')) . "'>Click here</a> to download the file.<br><video controls='controls' autoplay='autoplay'>
<source src='" . make_link("/image/" . $image->id) . "' type='video/webm' />
</video>";
}