function insert_video_thumbs($options) { global $config; $vid = intval($options['VID']); $vkey = $options['vkey']; $thumb = $options['thumb']; $output = array(); for ($i = 1; $i <= 20; $i++) { $tmb = get_thumb_dir($vid) . '/' . $i . '.jpg'; if (file_exists($tmb) && is_file($tmb)) { $class = $thumb == $i ? 'tmb_active' : 'tmb'; $output[] = '<img src="' . get_thumb_url($vid) . '/' . $i . '.jpg" width="72" id="change_tmb_' . $vkey . '_' . $i . '" class="' . $class . '">'; } } return implode("\n", $output); }
function deleteVideo($vid) { global $config, $conn; $vid = intval($vid); $sql = "SELECT vdoname, channel FROM video WHERE VID = " . $vid . " LIMIT 1"; $rs = $conn->execute($sql); $vdoname = $rs->fields['vdoname']; $chid = $rs->fields['channel']; if ($config['multi_server'] == '1') { delete_video_ftp($vid); } // Define All Video Formats Possible $vdo = $config['VDO_DIR'] . '/' . $vdoname; $flv = $config['FLVDO_DIR'] . '/' . $vid . '.flv'; $iphone = $config['IPHONE_DIR'] . '/' . $vid . '.mp4'; $mp4 = $config['HD_DIR'] . '/' . $vid . '.mp4'; if (file_exists($flv)) { @chmod($flv, 0777); @unlink($flv); } if (file_exists($vdo)) { @chmod($vdo, 0777); @unlink($vdo); } if (file_exists($mp4)) { @chmod($mp4, 0777); @unlink($mp4); } if (file_exists($iphone)) { @chmod($iphone, 0777); @unlink($iphone); } // AVS thumbs format delete_directory(get_thumb_dir($vid)); // Update Channel Video Totals $sql = "UPDATE channel SET total_videos = total_videos - 1 WHERE CHID = " . $chid; $conn->execute($sql); $tables = array('video_comments', 'favourite', 'playlist', 'video'); foreach ($tables as $table) { $sql = "DELETE FROM " . $table . " WHERE VID = " . $vid; $conn->execute($sql); } }
function extract_video_thumbs($video_path, $video_id) { global $config, $conn; // Logfile $logfile = $config['LOG_DIR'] . '/' . $video_id . '.thumbs.log'; @chmod($logfile, 0777); @unlink($logfile); // Default Thumbs Width & Height $thumb_width = $config['img_max_width']; $thumb_height = $config['img_max_height']; // Get Duration of Video from Database $duration = get_video_duration($video_path, $video_id); // Only continue if source video exists if (file_exists($video_path)) { // Temp & Final Thumbnails Directories $temp_thumbs_folder = $config['TMP_DIR'] . '/thumbs/' . $video_id; $final_thumbs_folder = get_thumb_dir($video_id); // Create Thumbs Directories @mkdir($temp_thumbs_folder, 0777); @mkdir($final_thumbs_folder, 0777); // Duration - set se = start/end if ($duration > 5) { $seconds = $duration - 4; $se = 2; } elseif ($duration > 3) { $seconds = $duration - 2; $se = 1; } elseif ($duration > 2) { $seconds = $duration - 1; $se = 0.5; } else { $seconds = $duration; $se = 0; } // Divided by 20 thumbs $timeseg = $seconds / 20; // Loop for 20 thumbs for ($i = 0; $i <= 20; $i++) { if ($i == 0) { // Thumbnail Size $mplayer_scale = "scale=640:360"; $ffmpeg_scale = "640x360"; // Destination $final_thumbnail = $final_thumbs_folder . '/default.jpg'; // Get Seek Time $ss = 5 * $timeseg + $se; } else { // Thumbnail Size $mplayer_scale = "scale=" . $thumb_width . ":" . $thumb_height . ""; $ffmpeg_scale = $thumb_width . "x" . $thumb_height; // Destination $final_thumbnail = $final_thumbs_folder . '/' . $i . '.jpg'; // Get Seek Time $ss = $i * $timeseg + $se; } // Work out seconds to hh:mm:ss format $hms = ""; $hours = intval($ss / 3600); $hms .= str_pad($hours, 2, "0", STR_PAD_LEFT) . ':'; $minutes = intval($ss / 60 % 60); $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT) . ':'; $secs = intval($ss % 60); $hms .= str_pad($secs, 2, "0", STR_PAD_LEFT); $seek = $hms; // Temporary filename convention. used by ffmpeg only. $temp_thumbs = $temp_thumbs_folder . '/%08d.jpg'; // Temporary Thumbnail File $temp_thumb_file = $temp_thumbs_folder . '/00000001.jpg'; // Set Permission and Delete Temporary Thumbnail File @chmod($temp_thumb_file, 0777); @unlink($temp_thumb_file); // Thumbnails extraction commands if ($config['thumbs_tool'] == 'ffmpeg') { // FFMPEG Command $cmd = $config['ffmpeg'] . " -ss " . $seek . " -i '" . $video_path . "' -r 1 -s " . $ffmpeg_scale . " -vframes 1 -an -vcodec mjpeg -y " . $temp_thumbs; } else { // Mplayer Command $cmd = $config['mplayer'] . " -zoom " . $video_path . " -ss " . $seek . " -nosound -frames 1 -vf " . $mplayer_scale . " -vo jpeg:outdir=" . $temp_thumbs_folder; } // Send data to logfile log_conversion($logfile, $cmd); // Execute Command exec($cmd, $output); // Send data to logfile log_conversion($logfile, implode("\n", $output)); // Check if file exists if (file_exists($temp_thumb_file)) { copy($temp_thumb_file, $final_thumbnail); // Set permission @chmod($temp_thumb_file, 0777); } } // Delete Temporary Thumbnail delete_directory($temp_thumbs_folder); // Figure out which was last thumb $i = 20; // Update Thumbs count in database $sql = "UPDATE video SET thumb = '1', thumbs = '" . $i . "' WHERE VID = '" . $video_id . "' LIMIT 1"; $conn->execute($sql); } return; }
$thumb = TRUE; } } } } } if (!$thumb) { $errors[] = 'Please upload at least one video thumb!'; } if (!$errors) { $sql = "INSERT INTO video\n\t\t SET UID = " . $uid . ",\n\t\t\t\t\t\t title = '" . mysql_real_escape_string($title) . "',\n\t\t\t\t\t\t\tkeyword = '" . mysql_real_escape_string($tags) . "',\n\t\t\t\t\t\t\tchannel = '" . $category . "',\n\t\t\t\t\t\t\ttype = '" . $video['type'] . "',\n\t\t\t\t\t\t\tembed_code = '" . mysql_real_escape_string($embed_code) . "',\n\t\t\t\t\t\t\tduration = " . duration_to_seconds($duration) . ",\n\t\t\t\t\t\t\tvkey = '" . mt_rand() . "',\n\t\t\t\t\t\t\taddtime = " . time() . ",\n\t\t\t\t\t\t\tadddate = '" . date('Y-m-d') . "',\n\t\t\t\t\t\t\tactive = '0'"; $conn->execute($sql); $vid = mysql_insert_id(); require $config['BASE_DIR'] . '/classes/image.class.php'; $image = new VImageConv(); $tmb_dir = get_thumb_dir($vid); $tmp_dir = $config['BASE_DIR'] . '/tmp/thumbs/' . $vid; @mkdir($tmb_dir); @mkdir($tmp_dir); $width = (int) $config['img_max_width']; $height = (int) $config['img_max_height']; $i = 1; foreach ($_FILES as $file) { $tmb = $i . '.jpg'; if (move_uploaded_file($file['tmp_name'], $tmp_dir . '/' . $tmb)) { $src = $tmp_dir . '/' . $tmb; $dst = $tmb_dir . '/' . $tmb; $dst_tmp = $tmp_dir . '/' . $tmb . '.tmp.jpg'; $image->process($src, $dst_tmp, 'MAX_WIDTH', $width, 0); $image->resize(true, true); $image->process($dst_tmp, $dst, 'EXACT', $width, $height);