91
Mods & Plugins (Requests & Discussions) / Re: Using ffmpeg to generate uploaded video thumbnails
« on: February 25, 2007, 09:07:52 AM »Wow... this sounds crazy hard. I'm a little overwhelmed with all of the updates & corrections.
Can we get a step by step for n00bs in one post?
OK guys... let's try again to put all code modifications in one place:
You should have mplayer.exe installed in "C:/mplayer/mplayer.exe" . You can download this application from here: http://www.mplayerhq.hu/design7/dload.html
Step 1.
In image_utils.php find and modify as follows:
Code: [Select]
function create_thumbnail($src, $dest, $quality, $dimension, $resize_type) {
global $convert_options;
if (file_exists($dest)) {
@unlink($dest);
}
$image_info = (defined("IN_CP")) ? getimagesize($src) : @getimagesize($src);
if (!$image_info) {
return false;
}
$width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);
$resize_handle = "resize_image_".$convert_options['convert_tool'];
if ($resize_handle($src, $dest, $quality, $width_height['width'], $width_height['height'], $image_info)) {
@chmod($dest, CHMOD_FILES);
return true;
}
//****added from here****
if (in_array(get_file_extension($new_name), array("mpg", "mpeg", "avi", "wmv")) && Generate_VideoThumb($src, $dest.".jpg")) {
$new_thumb_name = $new_name.".jpg";
}
//****added to here****
else {
return false;
}
}
//****added from here****
/**************************************************************************
* WeZ - Get Vid Info Code *
*************************************************************************/
function movie_get_length_in_seconds($src)
{
$cmd = "C:\\mplayer\\mplayer.exe -identify -vo null -ao null -frames 1 \"".$src."\" 2>&1 | grep ID_LENGTH";
$output = exec($cmd);
list(,$length) = explode("=", $output);
$length = ceil($length/2);
return $length;
}
/**************************************************************************
* WeZ - Get Thumb Code *
*************************************************************************/
function Generate_VideoThumb($src, $dest) {
global $convert_options;
$length = movie_get_length_in_seconds($src);
$command = "C:\\mplayer\\mplayer.exe \"".$src."\" -ss ".$length." -nosound -vo jpeg:smooth=75 -vop scale=120:80 -frames 1 > imagegenoutput.txt";
system($command);
unlink("imagegenoutput.txt");
rename("00000001.jpg",$dest);
movie_get_length_in_seconds($src);
return (file_exists($dest)) ? 1 : 0;
}
//****added to here****
Step2:
in member.php modify as follows:
Code: [Select]
// Upload thumb file
$new_thumb_name = "";
if (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$uploaderror) {
$new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $upload_cat, basename($new_name));
if (!$new_thumb_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['thumb_upload_error'].": ".$new_thumb_name."</b><br />".$site_upload->get_upload_errors();
@unlink(MEDIA_TEMP_PATH."/".$new_name);
$uploaderror = 1;
}
}
elseif (check_remote_thumb($remote_thumb_file)) {
$new_thumb_name = $remote_thumb_file;
}
elseif ($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file'.$fileext]['tmp_name']) && $HTTP_POST_FILES['media_file'.$fileext]['tmp_name'] != "none" && !$uploaderror) {
if ($direct_upload) {
$src = MEDIA_PATH."/".$cat_id."/".$new_name;
$dest = THUMB_PATH."/".$cat_id."/".$new_name;
}
else {
$src = MEDIA_TEMP_PATH."/".$new_name;
$dest = THUMB_TEMP_PATH."/".$new_name;
}
$do_create = 0;
if ($image_info = @getimagesize($src)) {
if ($image_info[2] == 1 || $image_info[2] == 2 || $image_info[2] == 3) {
$do_create = 1;
}
}
require_once(ROOT_PATH.'includes/image_utils.php');
$convert_options = init_convert_options();
if ($do_create) {
if (!$convert_options['convert_error']) {
$dimension = (intval($config['auto_thumbnail_dimension'])) ? intval($config['auto_thumbnail_dimension']) : 100;
$resize_type = (intval($config['auto_thumbnail_resize_type'])) ? intval($config['auto_thumbnail_resize_type']) : 1;
$quality = (intval($config['auto_thumbnail_quality']) && intval($config['auto_thumbnail_quality']) <= 100) ? intval($config['auto_thumbnail_quality']) : 100;
if (create_thumbnail($src, $dest, $quality, $dimension, $resize_type)) {
$new_thumb_name = $new_name;
}
}
}
else {
if (in_array(get_file_extension($new_name), array("mpg", "mpeg", "avi", "wmv")) && Generate_VideoThumb($src, $dest.".jpg")) {
$new_thumb_name = $new_name.".jpg";
}
}
}
And the final advise: If you want to try it then BACKUP YOUR ORIGINALS so you can always roll back the changes. Hope I helped some of you guys! Good luck!