DTHBAH2006 Posted December 25, 2007 Share Posted December 25, 2007 PHPMotion Script Latest Version. Downloaded 12-22-2007 The problem is the AVI files are not converting to FLV files. When the AVI files are uploaded they do not appear at all. When FLV files are uploaded they seem to work flawlessly. What is needed to fix the converter.php file so that it will convert AVI files into FLV files as it was designed? converter.php code below. ??? <?php /////////////////////////////////////////////////////////////////////////////////////// // PHPmotion http://www.phpmotion.com // /////////////////////////////////////////////////////////////////////////////////////// // License: You are not to sell or distribute this software without permission // // Version: PHPmotion V1.0 beta // // This file last modified: 30 June 2007 // // Main Author: Brian Shawa - bshawa@gmail.com // // Help and support please visit http://www.phpmotion.com // // Copyright reserved // /////////////////////////////////////////////////////////////////////////////////////// //this script runs as a background process. //CHECK POINT 1\\ //mail("you@yourdomain.com", "PHPmotion - Check Point 1", "Loaded OK", "From: Server <name@email.com>"); include_once ("classes/config.php"); @error_reporting(0); //LOG THAT THIS PAGE WAS LOADED (debugging for CLI) if ($log_encoder == "yes") { //check if file exists $file_contents = "\n\n\n\n" . 'PHPmotion Convertor.php debug' . "\n" . 'CLI for convertor OK' . "\n" . $config["date_format"] . "\n" . '================================================================================' . "\n"; $log_file = "logs/logfile.rtf"; if (@file_exists($log_file)) {//append to log file $fo = @fopen($log_file, 'a'); @fwrite($fo, $file_contents); @fclose($fo); } else { $fo = @fopen($log_file, 'w');//else create new log @fwrite($fo, $file_contents); @fclose($fo); } } ///////////////////////////// //get all file paths for file ///////////////////////////// $ffmpeg_debug = $_GET['debug'];//incase we are loading this as a url dor debugging $base_path = installation_paths(); ////////////////////////////// //PROCESS OR VIDEOS ONE BY ONE ////////////////////////////// $sql = "SELECT * FROM videos where approved ='pending_conversion'"; $query = @mysql_query($sql); while ($result = @mysql_fetch_array($query)) { $raw_video = $result['video_id']; //set current video to "converting" $sql1 = "UPDATE videos SET approved = 'converting' WHERE video_id = '$raw_video'"; @mysql_query($sql1); $raw_video_path = $base_path . '/uploads/avi/' . $raw_video;//full path of raw video file list($file_name_no_extension, $extension) = @split('\.', $raw_video);//spliting the raw video file name to get just the unique name $avi_file = $base_path . '/uploads/avi/' . $file_name_no_extension . '.avi'; $new_flv = $base_path . "/uploads/" . $file_name_no_extension . ".flv"; ///////////////////////////////////////////////////////////// // STEP 1 // // encode video to flv // ///////////////////////////////////////////////////////////// if ($extension != 'flv'){ //the following can be changed (vbitrate, vop scale, SRATE) $path_to_mencoder = $config["path_to_mencoder"]; $mencoder_cmd = "$path_to_mencoder $raw_video_path -o $new_flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=450:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -ofps 13 -vf scale=450:400 -srate 22050"; @exec("$mencoder_cmd 2>&1", $output); //If no flv was created. Attempt to convert with -vop swicth and not -vf if(!file_exists($new_flv)){ $mencoder_cmd = "$path_to_mencoder $raw_video_path -o $new_flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=450:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -ofps 13 -vop scale=450:400 -srate 22050"; @exec("$mencoder_cmd 2>&1", $output); } //debugging $debug_1 = $mencoder_cmd . "\n";//file line of debug foreach ($output as $outputline) { $debug_1 = $debug_1 . $outputline . "\n"; if ($debugmodex == 1) {//no debug mode echo ("$outputline<br>"); } } //LOG THAT STEP 1 was ok if ($log_encoder == "yes") { //check if file exists $file_contents = 'PHPmotion debug' . "\n" . $mencoder_cmd . "\n" . 'Command was executed.See rest of log for output details' . "\n" . '================================================================================' . "\n"; $log_file = "logs/logfile.rtf"; if (@file_exists($log_file)) {//append to log file $fo = @fopen($log_file, 'a'); @fwrite($fo, $file_contents); @fclose($fo); } else { $fo = @fopen($log_file, 'w');//else create new log @fwrite($fo, $file_contents); @fclose($fo); } } }else{ //just move the flv file @copy($raw_video_path, $new_flv); } //CHECK POINT 2\\ //mail("you@yourdomain.com", "PHPmotion - Check Point 2", "Video - Flash : $mencoder_cmd", "From: Server <name@email.com>"); ///////////////////////////////////////////////////////////// // STEP 2 // // FLVTOOL2 INJECTION // ///////////////////////////////////////////////////////////// $path_to_flv = $config["path_to_flvtool2"]; $flv_cmd = "$path_to_flv -U $new_flv"; @exec("$flv_cmd 2>&1", $output); //debugging $debug_2 = $flv_cmd . "\n";//file line of debug foreach ($output as $outputline) { $debug_2 = $debug_2 . $outputline . "\n"; if ($debugmodex == 1) {//no debug mode echo ("$outputline<br>"); } } //LOG THAT STEP 2 was ok if ($log_encoder == "yes") { //check if file exists $file_contents = 'PHPmotion debug' . "\n" . $flv_cmd . "\n" . 'Command was executed.See rest of log for output details' . "\n" . '================================================================================' . "\n"; $log_file = "logs/logfile.rtf"; if (@file_exists($log_file)) {//append to log file $fo = @fopen($log_file, 'a'); @fwrite($fo, $file_contents); @fclose($fo); } else { $fo = @fopen($log_file, 'w');//else create new log @fwrite($fo, $file_contents); @fclose($fo); } } //CHECK POINT 3\\ //mail("you@yourdomain.com", "PHPmotion - Check Point 3", "FLVTOOL2 : $flv_cmd", "From: Server <name@email.com>"); ///////////////////////////////////////////////////////////// // STEP 3 // // ffmpeg-php get video duration // ///////////////////////////////////////////////////////////// //Original FFMPEG-PHP option for getting video length /////////////////////////////////////////////////////////////////// /* $video_info = @new ffmpeg_movie($new_flv);//duration of new flv file. $sec = @$video_info->getDuration();// Gets the duration in secs. */ //-------------------------------------------------------------------------------end of original ffmpeg-php //Alternative to flvtool2 if getting errors or if no flvtool exists (comment out if failing or to use ffpmeg-php) /////////////////////////////////////////////////////////////////// $video_info = new ffmpeg_movie("$new_flv"); $sec = $video_info->getDuration(); $duration = sec2hms($sec); //Alternative to flvtool2 if getting errors or if no flvtool exists (comment out if failing or to use ffpmeg-php) /////////////////////////////////////////////////////////////////// /* $shell_output = $debug_1 . $debug_2;//get as much sheel out put as possible to run search for duration if (@preg_match('/Video stream:.*bytes..(.*?).sec/', $shell_output, $regs)) { $sec = $regs[1]; } else { $sec = ""; }*/ //----------------------------------------------------------------------------------end of alternative to ffmpeg-php //continue with rest of process if ($sec == "" || !is_numeric($sec)) { $sec = 2; } //$duration = sec2hms($sec);//covert to 00:00:00 i.e. hrs:min:sec //get the middle of the movie (time; 00:00:00 format) for thumbnail $sec2 = $sec / 2; $sec2 = @round($sec2); $thumb_position = sec2hms($sec2); //LOG THAT STEP 3 was ok if ($log_encoder == "yes") { //check if file exists $file_contents = 'PHPmotion debug' . "\n" . 'FFMPEG-PHP - check - Video Duration = ' . $duration . "\n" . '================================================================================' . "\n"; $log_file = "logs/logfile.rtf"; if (@file_exists($log_file)) {//append to log file $fo = @fopen($log_file, 'a'); @fwrite($fo, $file_contents); @fclose($fo); } else { $fo = @fopen($log_file, 'w');//else create new log @fwrite($fo, $file_contents); @fclose($fo); } } //CHECK POINT 4\\ //mail("you@yourdomain.com", "PHPmotion - Check Point 4", "FFMPEG-PHP : $duration", "From: Server <name@email.com>"); ///////////////////////////////////////////////////////////// // STEP 4 // // Create thumnail image // ///////////////////////////////////////////////////////////// $output_file = $base_path . '/uploads/thumbs/' . $file_name_no_extension . '.jpg'; //IMPORTANT: if your thumbs ar enot being created, try change "mjpeg" below to "image2" $ffmpeg_cmd2 = "$config[path_to_ffmpeg] -i $new_flv -ss $thumb_position -t 00:00:01 -s 120x90 -r 1 -f mjpeg $output_file"; //execute and record output to variable @exec("$ffmpeg_cmd2 2>&1", $output); //debugging $debug_3 = $ffmpeg_cmd2 . "\n";//file line of debug foreach ($output as $outputline) { $debug_3 = $debug_3 . $outputline . "\n"; if ($debugmodex == 1) {//no debug mode echo ("$outputline<br>"); } } //LOG THAT STEP 4 was ok if ($log_encoder == "yes") { //check if file exists $file_contents = 'PHPmotion debug' . "\n" . $ffmpeg_cmd2 . "\n" . 'Command was executed.See rest of log for output details' . "\n" . '================================================================================' . "\n\n\n"; $log_file = "logs/logfile.rtf"; if (@file_exists($log_file)) {//append to log file $fo = @fopen($log_file, 'a'); @fwrite($fo, $file_contents); @fclose($fo); } else { $fo = @fopen($log_file, 'w');//else create new log @fwrite($fo, $file_contents); @fclose($fo); } } ////////////////////////////////////////////////////////////// //check if image thumb has been made //This tries to create thumb using different format "image2" ////////////////////////////////////////////////////////////// if (@!file_exists($output_file)) { $ffmpeg_cmd2 = "$config[path_to_ffmpeg] -i $new_flv -ss $thumb_position -t 00:00:01 -s 120x90 -r 1 -f image2 $output_file"; //execute and record output to variable @exec("$ffmpeg_cmd2 2>&1", $output); //debugging $debug_3 = $ffmpeg_cmd2 . "\n";//file line of debug foreach ($output as $outputline) { $debug_3 = $debug_3 . $outputline . "\n"; if ($debugmodex == 1) {//no debug mode echo ("$outputline<br>"); } } //LOG THAT STEP 4 was ok if ($log_encoder == "yes") { //check if file exists $file_contents = 'PHPmotion debug - Image type 2' . "\n" . $ffmpeg_cmd2 . "\n" . 'Command was executed.See rest of log for output details' . "\n" . '================================================================================' . "\n\n\n"; $log_file = "logs/logfile.rtf"; if (@file_exists($log_file)) {//append to log file $fo = @fopen($log_file, 'a'); @fwrite($fo, $file_contents); @fclose($fo); } else { $fo = @fopen($log_file, 'w');//else create new log @fwrite($fo, $file_contents); @fclose($fo); } } } //CHECK POINT 5\\ //mail("you@yourdomain.com", "PHPmotion - Check Point 5", "THUMBNAIL : $ffmpeg_cmd2", "From: Server <name@email.com>"); ///////////////////////////////////////////////////////////// // STEP 6 // // UDATE DATABASE DETAILS // ///////////////////////////////////////////////////////////// //RESET THE VIDEO FROM "pending_conversion" to just "pending" (for admin approval etc) $sql = "UPDATE videos SET approved='pending' WHERE video_id = '$raw_video'"; @mysql_query($sql); //RESET THE VIDEO ID TO REMOVE file extenstion $sql = "UPDATE videos SET video_id='$file_name_no_extension' WHERE video_id = '$raw_video'"; @mysql_query($sql); //Update dabase with new duration information ///////////////////////////////////////////// $file_name_no_extension = $file_name_no_extension; $sql = "UPDATE videos SET video_length='$duration' WHERE video_id = '$file_name_no_extension'"; @mysql_query($sql); //Check if video need pre approval by admin, if not update from pending to "yes" //////////////////////////////////////////////////////////////////////////////// if ($config["auto_approve_videos"] == "yes") { $sql = "UPDATE videos SET approved='yes' WHERE video_id = '$file_name_no_extension'"; @mysql_query($sql); } //@mysql_close(); ////////////////////////////////////////////////////////////////// //WRITE OUTPUT TO LOGFILE - HELP WITH DEBUGGING (logs/logfile.rtf) ////////////////////////////////////////////////////////////////// if ($log_encoder == "yes") { $file_contents = 'Date: ' . $config["date_format"] . "\n" . 'STEP 1 - OUTPUT' . "\n" . $debug_1 . "\n" . 'STEP 2 - OUTPUT' . "\n" . $debug_2 . "\n" . 'STEP 4 - OUTPUT' . "\n" . $debug_3;//adding all output //check if file exists $log_file = "logs/logfile.rtf"; if (@file_exists($log_file)) {//append to log file $fo = @fopen($log_file, 'a'); @fwrite($fo, $file_contents); @fclose($fo); } else { $fo = @fopen($log_file, 'w');//else create new log @fwrite($fo, $file_contents); @fclose($fo); } } //delete original file and converted temp avi file /////////////////////////////////////////////////// $original_file = $raw_video_path; if ($config["delete_original"] == 'yes') { if (@file_exists("$new_flv") && @file_exists("$raw_video_path")) { if ($new_flv != $raw_video_path) { @unlink($raw_video_path); } } } if ($config["delete_avi"] == 'yes') { if (@file_exists("$new_flv") && @file_exists("$avi_file")) { @unlink($avi_file); } } //CHECK POINT 6\\ //mail("you@yourdomain.com", "PHPmotion - Check Point 6", "SCRIPT LOADED TO THE END", "From: Server <name@email.com>"); @mysql_close(); }//end while ?> Quote Link to comment https://forums.phpfreaks.com/topic/83099-avi-files-not-converting/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.