function extract_video_thumbs($video_path, $video_id) { global $config; $duration = get_video_duration($video_path, $video_id); if ($duration > 180) { $ss = 60; $step = 5; } elseif ($duration > 120) { $ss = 15; $step = 5; } elseif ($duration > 60) { $ss = 10; $step = 2; } else { $ss = 1; $step = 1; } $i = 0; mkdir($config['TMP_DIR'] . '/thumbs/' . $video_id); mkdir($config['TMB_DIR'] . '/' . $video_id); while ($i <= 20) { $width = $config['img_max_width']; $height = $config['img_max_height']; if ($i == 0) { $width = 320; $height = 240; } if ($config['thumbs_tool'] == 'ffmpeg') { $cmd = $config['ffmpeg'] . ' -i ' . $video_path . ' -f image2 -ss ' . $ss . ' -s ' . $width . 'x' . $height . ' -vframes 2 -y ' . $config['TMP_DIR'] . '/thumbs/' . $video_id . '/%08d.jpg'; } else { $cmd = $config['mplayer'] . ' ' . $video_path . ' -ss ' . $ss . ' -nosound -vop scale=' . $width . ':' . $height . ' -vo jpeg:outdir=' . $config['TMP_DIR'] . '/thumbs/' . $video_id . ' -frames 2'; } log_conversion($config['LOG_DIR'] . '/' . $video_id . '.log', $cmd); exec($cmd . ' 2>&1', $output); log_conversion($config['LOG_DIR'] . '/' . $video_id . '.log', implode("\n", $output)); if (file_exists($config['TMP_DIR'] . '/thumbs/' . $video_id . '/00000002.jpg')) { $src = $config['TMP_DIR'] . '/thumbs/' . $video_id . '/00000002.jpg'; } else { $src = $config['TMP_DIR'] . '/thumbs/' . $video_id . '/00000001.jpg'; } $dst = $i == 0 ? $config['TMB_DIR'] . '/' . $video_id . '/default.jpg' : $config['TMB_DIR'] . '/' . $video_id . '/' . $i . '.jpg'; log_conversion($config['LOG_DIR'] . '/' . $video_id . '.log', $src . "\n" . $dst); copy($src, $dst); $ss = $ss + $step; if ($ss > $duration) { $ss = $ss - $step; } ++$i; } @unlink($config['TMP_DIR'] . '/thumbs/' . $video_id); }
if ($config['vresize'] != 1 && $ext == 'flv') { copy($video_path, $config['FLVDO_DIR'] . '/' . $vid . 'x.flv'); } else { exec($cmd . ' 2>&1', $output); } log_conversion($config['LOG_DIR'] . '/' . $vid . '.log', implode("\n", $output)); // update flv meta tags if ($config['meta_tool'] == 'flvtool2') { $cmd = $config['metainject'] . ' -Uv ' . $config['FLVDO_DIR'] . '/' . $vid . 'x.flv ' . $config['FLVDO_DIR'] . '/' . $vid . '.flv'; } elseif ($config['meta_tool'] == 'yamdi') { $cmd = $config['yamdi'] . ' -i ' . $config['FLVDO_DIR'] . '/' . $vid . 'x.flv -o ' . $config['FLVDO_DIR'] . '/' . $vid . '.flv'; } else { log_conversion($config['LOG_DIR'] . '/' . $vid . '.log', 'Invalid meta tool..must be yamdi or flvtool2'); } exec($cmd, $output); log_conversion($config['LOG_DIR'] . '/' . $vid . '.log', implode("\n", $output)); //change permissions to 666 for lighty @chmod($config['FLVDO_DIR'] . '/' . $vid . '.flv', 0666); // delete temporary flv file @unlink($config['FLVDO_DIR'] . '/' . $vid . 'x.flv'); //extract video thumbs extract_video_thumbs($video_path, $vid); //activate video if (file_exists($config['FLVDO_DIR'] . '/' . $vid . '.flv') && filesize($config['FLVDO_DIR'] . '/' . $vid . '.flv') > 10) { $add = NULL; if ($config['multi_server'] == '1') { require $config['BASE_DIR'] . '/include/function_server.php'; $server = get_server(); update_server_used($server); upload_video($config['FLVDO_DIR'] . '/' . $vid . '.flv', $server['server_ip'], $server['ftp_username'], $server['ftp_password'], $server['ftp_root']); update_server($server);
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; }
$lx = explode("=", $v); $vidinfo[$lx[0]] = $lx[1]; } } $vdoname = $vid . '.flv'; $flvdoname = $vid . '.flv'; $video_id = $vid; $duration = $vidinfo['ID_LENGTH']; $height = $vidinfo['ID_VIDEO_HEIGHT']; $width = $vidinfo['ID_VIDEO_WIDTH']; $fps = $vidinfo['ID_VIDEO_FPS']; $id_video_format = $vidinfo['ID_VIDEO_FORMAT']; $cgi = strpos(php_sapi_name(), 'cgi') ? 'env -i ' : NULL; // Proc $cmd = $cgi . $config['phppath'] . " " . $config['BASE_DIR'] . "/scripts/convert_videos.php" . " " . $vdoname . " " . $video_id . " " . $vdo_path . ""; log_conversion($config['LOG_DIR'] . '/' . $video_id . '.log', $cmd); $lg = $config['LOG_DIR'] . '/' . $video_id . '.log2'; run_in_background($cmd . ' > ' . $lg); $add = NULL; if ($config['multi_server'] == '1') { require $config['BASE_DIR'] . '/include/function_server.php'; $server = get_server(); update_server_used($server); upload_video($config['FLVDO_DIR'] . '/' . $vid . '.flv', $server['server_ip'], $server['ftp_username'], $server['ftp_password'], $server['ftp_root']); update_server($server); $add = ", server = '" . mysql_real_escape_string($server['url']) . "'"; } $size = filesize($vdo_path); } } if (!$errors) {