2012-09-23 21:18:12 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Name: Handle Video
|
|
|
|
* Author: velocity37 <velocity37@gmail.com>
|
2014-04-18 06:06:12 +00:00
|
|
|
* Modified By: Shish <webmaster@shishnet.org>, jgen <jeffgenovy@gmail.com>
|
2012-09-23 21:18:12 +00:00
|
|
|
* License: GPLv2
|
|
|
|
* Description: Handle FLV, MP4, OGV and WEBM video files.
|
|
|
|
* Documentation:
|
|
|
|
* Based heavily on "Handle MP3" by Shish.<br><br>
|
|
|
|
* FLV: Flash player<br>
|
|
|
|
* MP4: HTML5 with Flash fallback<br>
|
|
|
|
* OGV, WEBM: HTML5<br>
|
|
|
|
* MP4's flash fallback is forced with a bit of Javascript as some browsers won't fallback if they can't play H.264.
|
|
|
|
* In the future, it may be necessary to change the user agent checks to reflect the current state of H.264 support.<br><br>
|
|
|
|
* Made possible by:<br>
|
|
|
|
* <a href='http://getid3.sourceforge.net/'>getID3()</a> - Gets media information with PHP (no bulky FFMPEG API required).<br>
|
|
|
|
* <a href='http://jarisflvplayer.org/'>Jaris FLV Player</a> - GPLv3 flash multimedia player.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class VideoFileHandler extends DataHandlerExtension {
|
2014-04-18 06:10:10 +00:00
|
|
|
public function onInitExt(InitExtEvent $event) {
|
|
|
|
global $config;
|
|
|
|
$config->set_default_string('video_thumb_engine', 'static');
|
|
|
|
$config->set_default_string('thumb_ffmpeg_path', '');
|
|
|
|
}
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-18 06:10:10 +00:00
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event) {
|
|
|
|
global $config;
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-18 06:10:10 +00:00
|
|
|
$thumbers = array();
|
|
|
|
$thumbers['None'] = "static";
|
|
|
|
$thumbers['ffmpeg'] = "ffmpeg";
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-18 06:10:10 +00:00
|
|
|
$sb = new SetupBlock("Video Thumbnail Options");
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-18 06:10:10 +00:00
|
|
|
$sb->add_choice_option("video_thumb_engine", $thumbers, "Engine: ");
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-26 21:09:18 +00:00
|
|
|
//if($config->get_string("video_thumb_engine") == "ffmpeg") {
|
2014-04-18 06:10:10 +00:00
|
|
|
$sb->add_label("<br>Path to ffmpeg: ");
|
|
|
|
$sb->add_text_option("thumb_ffmpeg_path");
|
2014-04-26 21:09:18 +00:00
|
|
|
//}
|
2014-04-18 06:10:10 +00:00
|
|
|
$event->panel->add_block($sb);
|
|
|
|
}
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-27 19:33:57 +00:00
|
|
|
/**
|
|
|
|
* @param string $hash
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-04-26 21:09:18 +00:00
|
|
|
protected function create_thumb($hash) {
|
2014-04-10 07:14:17 +00:00
|
|
|
global $config;
|
|
|
|
|
2014-04-18 06:10:10 +00:00
|
|
|
// this is never used...
|
2014-04-18 05:37:27 +00:00
|
|
|
//$q = $config->get_int("thumb_quality");
|
2014-04-10 07:14:17 +00:00
|
|
|
|
2014-04-27 19:33:57 +00:00
|
|
|
$ok = false;
|
|
|
|
|
2014-04-18 05:37:27 +00:00
|
|
|
switch($config->get_string("video_thumb_engine"))
|
2014-04-18 06:10:10 +00:00
|
|
|
{
|
2014-04-10 07:14:17 +00:00
|
|
|
default:
|
|
|
|
case 'static':
|
2014-04-26 21:09:18 +00:00
|
|
|
$outname = warehouse_path("thumbs", $hash);
|
2014-04-10 07:14:17 +00:00
|
|
|
copy("ext/handle_video/thumb.jpg", $outname);
|
2014-04-27 19:33:57 +00:00
|
|
|
$ok = true;
|
2014-04-10 07:14:17 +00:00
|
|
|
break;
|
|
|
|
case 'ffmpeg':
|
2014-04-26 21:09:18 +00:00
|
|
|
$ffmpeg = escapeshellarg($config->get_string("thumb_ffmpeg_path"));
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-26 21:09:18 +00:00
|
|
|
$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));
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-26 21:09:18 +00:00
|
|
|
$cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -s {$w}x{$h} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}");
|
2014-04-10 07:14:17 +00:00
|
|
|
exec($cmd, $output, $ret);
|
2014-04-18 05:37:27 +00:00
|
|
|
|
2014-04-27 19:33:57 +00:00
|
|
|
// TODO: We should really check the result of the exec to see if it really succeeded.
|
|
|
|
$ok = true;
|
|
|
|
|
2014-04-10 07:14:17 +00:00
|
|
|
log_debug('handle_video', "Generating thumbnail with command `$cmd`, returns $ret");
|
|
|
|
break;
|
|
|
|
}
|
2014-04-27 19:33:57 +00:00
|
|
|
|
|
|
|
return $ok;
|
2012-09-23 21:18:12 +00:00
|
|
|
}
|
|
|
|
|
2014-04-27 19:33:57 +00:00
|
|
|
/**
|
|
|
|
* @param string $ext
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-09-23 21:18:12 +00:00
|
|
|
protected function supported_ext($ext) {
|
|
|
|
$exts = array("flv", "mp4", "m4v", "ogv", "webm");
|
|
|
|
return in_array(strtolower($ext), $exts);
|
|
|
|
}
|
|
|
|
|
2014-04-27 19:33:57 +00:00
|
|
|
/**
|
|
|
|
* @param string $filename
|
|
|
|
* @param array $metadata
|
|
|
|
* @return Image|null
|
|
|
|
*/
|
2012-09-23 21:18:12 +00:00
|
|
|
protected function create_image_from_data($filename, $metadata) {
|
2014-04-18 05:37:27 +00:00
|
|
|
//global $config;
|
2012-09-23 21:18:12 +00:00
|
|
|
|
|
|
|
$image = new Image();
|
|
|
|
|
|
|
|
require_once('lib/getid3/getid3/getid3.php');
|
|
|
|
$getID3 = new getID3;
|
|
|
|
$ThisFileInfo = $getID3->analyze($filename);
|
|
|
|
|
|
|
|
if (isset($ThisFileInfo['video']['resolution_x']) && isset($ThisFileInfo['video']['resolution_y'])) {
|
|
|
|
$image->width = $ThisFileInfo['video']['resolution_x'];
|
|
|
|
$image->height = $ThisFileInfo['video']['resolution_y'];
|
|
|
|
} else {
|
|
|
|
$image->width = 0;
|
|
|
|
$image->height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($ThisFileInfo['mime_type']) {
|
|
|
|
case "video/webm":
|
|
|
|
$image->ext = "webm";
|
|
|
|
break;
|
|
|
|
case "video/quicktime":
|
|
|
|
$image->ext = "mp4";
|
|
|
|
break;
|
|
|
|
case "application/ogg":
|
|
|
|
$image->ext = "ogv";
|
|
|
|
break;
|
|
|
|
case "video/x-flv":
|
|
|
|
$image->ext = "flv";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$image->filesize = $metadata['size'];
|
|
|
|
$image->hash = $metadata['hash'];
|
|
|
|
$image->filename = $metadata['filename'];
|
|
|
|
$image->tag_array = Tag::explode($metadata['tags']);
|
|
|
|
$image->source = $metadata['source'];
|
|
|
|
|
|
|
|
return $image;
|
|
|
|
}
|
|
|
|
|
2014-04-27 19:33:57 +00:00
|
|
|
/**
|
|
|
|
* @param $file
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-09-23 21:18:12 +00:00
|
|
|
protected function check_contents($file) {
|
|
|
|
if (file_exists($file)) {
|
|
|
|
require_once('lib/getid3/getid3/getid3.php');
|
|
|
|
$getID3 = new getID3;
|
|
|
|
$ThisFileInfo = $getID3->analyze($file);
|
2014-04-28 04:57:49 +00:00
|
|
|
if (isset($ThisFileInfo['mime_type']) && (
|
|
|
|
$ThisFileInfo['mime_type'] == "video/webm" ||
|
|
|
|
$ThisFileInfo['mime_type'] == "video/quicktime" ||
|
|
|
|
$ThisFileInfo['mime_type'] == "application/ogg" ||
|
|
|
|
$ThisFileInfo['mime_type'] == 'video/x-flv')
|
|
|
|
) {
|
2012-09-23 21:18:12 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-04-25 02:28:53 +00:00
|
|
|
|