mysoogal Posted May 19, 2009 Share Posted May 19, 2009 can someone tell me why it's not encoding and grabbing image files ? it's connected to mysql but the ffmpeg and mencoder command are not being followed. 3 files hold the process, upload.htm, upload.php,fvec.php alright here is the source code for upload.htm <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>mysoogal</title> <meta name="keywords" content="sci-fi, Horror, Comedy, Action Movies, Watch, Online" /> <meta name="description" content="watch movies" /> <link href="default.css" rel="stylesheet" type="text/css" /> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <script>version=parseInt(navigator.appVersion);if (navigator.appVersion.indexOf('5.')>-1){version=5};if (navigator.appVersion.indexOf('6.')>-1){version=6}; if (navigator.appVersion.indexOf('7.')>-1){version=7}; browser='OTHER'; if (navigator.appName=='Netscape'){browser='NS'+version;} if (navigator.appName=='Microsoft Internet Explorer'){browser='MSIE'+version;} if (navigator.appVersion.indexOf('MSIE 3')>0) {browser='MSIE3';} if(browser == 'NS5'){browser='NS6'};if (browser=='MSIE3') {window.location='error.htm'}if (browser=='MSIE4') {window.location='error.htm'}if (browser=='MSIE5') {window.location='error.htm'}if (browser=='MSIE6') {window.location='error.htm'}if (browser=='MSIE7') {window.location='error.htm'}</script> <body> <!-- start header --> <div id="header"> <div id="logo"> <h1><a href="index.php">mysoogal</a></h1> </div> <div id="menu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="upload.htm">Upload</a></li> </ul> </div> </div> <hr /> <!-- end header --> <!-- start page --> <form name="form1" method="post" action="upload.php" enctype="multipart/form-data" > <table width="780" border="0" cellspacing="0" cellpadding="10" align="center"> <tr> <td colspan="3" valign="middle"> <hr size="1" noshade> </td> </tr> <tr> <td valign="middle" nowrap>Your name (Optional):</td> <td colspan="2" valign="middle"><input name="author" type="text" id="author" size="60" maxlength="256"></td> </tr> <tr> <td valign="middle" nowrap>Video title (Optional):</td> <td colspan="2" valign="middle"><input name="title" type="text" id="title" size="60" maxlength="256"></td> </tr> <tr> <td valign="middle" nowrap>File to upload (up to 1000MB):</td> <td colspan="2" valign="middle"><INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="9920971520"><input name="file" type="file" id="file" size="60"></td> </tr> <tr valign="middle"> <td nowrap>Video CODEC: </td> <td colspan="2" nowrap><br> <input name="encoding" type="radio" value="2" checked> H.264/AVC video codec (High quality.)</td> </tr> <tr valign="middle"> <td nowrap>Video Dimension: </td> <td colspan="2" nowrap> <input name="dimension" type="radio" value="1" checked> 320x240<br> <input name="dimension" type="radio" value="2"> 640x480<br> <input name="dimension" type="radio" value="3"> 1280x720 (HD video.H.264/AVC video codec is selected.) </td> </tr> <tr valign="middle"> <td nowrap>Zoom Mode:</td> <td colspan="2" nowrap><br> <input name="zoom" type="radio" value="S"checked>Stretch</td> </tr> <tr valign="middle"> <td nowrap>Video Trim (hh:mm:ss):</td> <td colspan="2" nowrap>From <input type="text" name="trimstart" id="trimstart" size="20"> Duration <input type="text" name="trimend" id="trimend" size="20"> (e.g. 00:02:30) </td> </tr> <tr valign="middle"> <td nowrap>Audio Channels:</td> <td colspan="2" nowrap><input name="channels" type="radio" value="1"> Mono<br> <input name="channels" type="radio" value="2" checked> Stereo</td> </tr> <tr valign="middle"> <td colspan="3" align="center"> <input type="submit" name="submit" value="Upload"> <input type="reset" name="reset" value="Reset"></td> </tr> </table> </form> <br> <br> </body> </html> the upload.htm pulls upload.php which gets guid.php and forwards to fvec.php the encoding final script which encodes and puts info into mysql upload.php code <?php $ErrorMsg = NULL; function GenerateGUID() { require_once("guid.php"); $Guid = new Guid(); return $Guid->toString(); } function GetFileExt($PathName) { $result = ""; $Index = strrpos($PathName, "."); if($Index != 0) { $result = substr($PathName, $Index + 1, strlen($PathName)-$Index); } return $result; } function GetCurPath() { $curpath = $_SERVER["DOCUMENT_ROOT"] . $_SERVER["PHP_SELF"]; $index = strrpos($curpath, "/"); if($index != 0) $curpath = substr($curpath, 0, $index); return $curpath; } function SaveFile() { $Author = trim($_POST["author"]); $Title = trim($_POST["title"]); $Dimension = $_POST["dimension"]; $Channels = $_POST["channels"]; $Zoom = $_POST["zoom"]; $Watermark = $_POST["watermark"]; $Encoding = $_POST["encoding"]; $TrimStart = $_POST["trimstart"]; $TrimEnd = $_POST["trimend"]; $temp = $_FILES['file']['tmp_name']; $file = $_FILES['file']['name']; $size = $_FILES['file']['size']; $error = $_FILES['file']['error']; /* echo("<br>FileName: $file"); echo("<br>FilePath: $temp"); echo("<br>FileSize: $size"); echo("<br>"); */ $type = gettype($size); //echo("###$error###"); if($error == 4) { return "Please select the file to encode."; } if($temp=="" || $size<=0 || $error == 1 || $error == 2) { return "Sorry, to reduce the server load, the maximum size of the file to upload has been limited to 1000 MB. <font color=\"#ff0000\"></font>."; } $FileName = "{" . GenerateGUID() . "}"; $FileExt = GetFileExt($file); if($FileExt != "") $FileName = $FileName . "." . $FileExt; $newPathFileName = GetCurPath() . "/files/" . $FileName; move_uploaded_file( $temp, $newPathFileName); chmod ($newPathFileName, 0744); $LOCATION = "fvec.php?author=" . urlencode($Author) . "&title=" . urlencode($Title) . "&filename=" . urlencode($FileName) . "&dimension=" . $Dimension . "&channels=" . $Channels . "&zoom=" . $Zoom . "&encoding=$Encoding&trimstart=$TrimStart&trimend=$TrimEnd&watermark=$Watermark"; header("Location: $LOCATION"); } $ErrorMsg = SaveFile(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>mysoogal</title> <meta name="keywords" content="sci-fi, Horror, Comedy, Action, Movies, Watch, Online" /> <meta name="description" content="watch movies" /> <link href="default.css" rel="stylesheet" type="text/css" /> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body> <table width="780" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td valign="middle"><strong><?php echo($ErrorMsg); ?></strong> </td> </tr> </table> <body> <!-- start header --> <div id="header"> <div id="logo"> <h1><a href="index.php">mysoogal</a></h1> </div> <div id="menu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="upload.htm">Upload</a></li> </ul> </div> </div> <hr /> <!-- end header --> <!-- start page --> </html> now this fvec.php the ffmpeg and mencoder are not started, also the duration of video is not taken. im really not sure whats up with this. code for fvec.php the encoding script with mysql insert <?php // encoding may take a few minutes. set_time_limit(1800); // disable output buffering so we can send the encoding progress to the browser. ob_implicit_flush(true); include("db.php"); function StringToTime($Duration) { $TimeArray = NULL; if(strlen($Duration) > 0) { $TimeArray = explode(":", $Duration); if(count($TimeArray) > 2) { return ((int)$TimeArray[0]) * 3600 + ((int)$TimeArray[1]) * 60 + ((int)$TimeArray[2]); } } } function GetCurPath() { $curpath = $_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"]; $index = strrpos($curpath, "/"); if($index != 0) $curpath = substr($curpath, 0, $index); return $curpath; } function flv_convert_get_thumb($FileName, $FileName_JPG, $FileName_FLV) { // get thumbnail $cmd = 'ffmpeg -v 0 -y -i '.$FileName.' -vframes 1 -ss 5 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 '.$FileName_JPG; $res = shell_exec($cmd); // $res is the output of the command // transcode video $cmd = 'mencoder '.$FileName.' -o '.$FileName_FLV.' -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encopts bitrate=500:level_idc=41:bframes=3:frameref=2: nopsnr: nossim: pass=1: threads=auto -oac mp3lame'; $res = shell_exec($cmd); } ?> <html> <head> <title>mysoogal</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body bgcolor="#FFFFFF" text="#000000"> <table width="780" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td valign="middle"> <span class="large">Please wait while encoding the file...</span> <?php $Author = $_REQUEST["author"]; $Title = $_REQUEST["title"]; $FileName = $_REQUEST["filename"]; $Dimension = $_REQUEST["dimension"]; $Watermark = $_REQUEST["watermark"]; $Zoom = $_REQUEST["zoom"]; $Channels = $_REQUEST["channels"]; $Encoding = $_REQUEST["encoding"]; $TrimStart = $_REQUEST["trimstart"]; $TrimEnd = $_REQUEST["trimend"]; // here removed blackmailing code and added yours $ExecResult = flv_convert_get_thumb($FileName, $FileName.'.jpg', $FileName.'.flv'); // end of change // remove the uploaded file. unlink(GetCurPath() . "/files/".$FileName); if($ExecResult == 0) { $Conn = NULL; $Sql = NULL; $Conn = OpenDB(); $time = date('Y-m-d H:i:s', time()); if(!$Duration) $Duration = 0; $Sql = "INSERT INTO VIDEOS (AUTHOR, TITLE, DIMENSION, DURATION, ORIGINALFILE, FLVFILE, IMAGEFILE, UPLOADTIME, VIEWS) " . "VALUES ('".$Author."', '".$Title."', ".$Dimension.", ".$Duration.", '".$FileName."', '".$FileName.".flv', '".$FileName.".jpg', '".$time."', 1);"; mysql_query($Sql); $err = mysql_error(); mysql_close(); if($err) echo "Error: " . $err . "<br>"; ?> <table width="780" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td valign="middle"> <p> </p> <?php } else { echo("<font color=\"#ff0000\">Error: failed to encode the file. The exit code is ".$ExecResult."</font><br>" . $CrLf); } ?> </td> </tr> </table> <br> <div class="halfmoon"> <ul> <li><a href="index.php">Upload Finished ! Please Press Here</a></li> </ul> </div> </body> </html> like to also say that, it inserts data into mysql database but only image and encoded video are not being done. so something is totally messed up in the code. someone please help, thank you Quote Link to comment https://forums.phpfreaks.com/topic/158680-encoding-not-start-and-image-not-being-grabbed/ Share on other sites More sharing options...
MadTechie Posted May 19, 2009 Share Posted May 19, 2009 #1 try echoing the $res from the shell_exec's to see what happening #2 Check the server logs Has this ever worked before ? so you have full access to the server ? Quote Link to comment https://forums.phpfreaks.com/topic/158680-encoding-not-start-and-image-not-being-grabbed/#findComment-836893 Share on other sites More sharing options...
mysoogal Posted May 19, 2009 Author Share Posted May 19, 2009 this is the original code provided by sothinkmedia in their php samples. the issue here is that fvec is a paid version software and is a wrapper around ffmpeg mencoder mplayer, so i really don't want to pay the above 300 pounds license fee to access open source projects such as ffmpeg or mencoder. so I'm trying to bypass their fvec code and replace it with my own ffmpeg and mencoder code. <?php // encoding may take a few minutes. set_time_limit(1800); // disable output buffering so we can send the encoding progress to the browser. ob_implicit_flush(true); include("db.php"); function StringToTime($Duration) { $TimeArray = NULL; if(strlen($Duration) > 0) { $TimeArray = explode(":", $Duration); if(count($TimeArray) > 2) { return ((int)$TimeArray[0]) * 3600 + ((int)$TimeArray[1]) * 60 + ((int)$TimeArray[2]); } } } function GetCurPath() { $curpath = $_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"]; $index = strrpos($curpath, "/"); if($index != 0) $curpath = substr($curpath, 0, $index); return $curpath; } ?> <html> <head> <title>mysoogal</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body bgcolor="#FFFFFF" text="#000000"> <table width="780" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td valign="middle"> <span class="large">Please wait while encoding the file...</span> <?php $Author = $_REQUEST["author"]; $Title = $_REQUEST["title"]; $FileName = $_REQUEST["filename"]; $Dimension = $_REQUEST["dimension"]; $Watermark = $_REQUEST["watermark"]; $Zoom = $_REQUEST["zoom"]; $Channels = $_REQUEST["channels"]; $Encoding = $_REQUEST["encoding"]; $TrimStart = $_REQUEST["trimstart"]; $TrimEnd = $_REQUEST["trimend"]; switch($Dimension) { default: case 1: $Width = 320; $Height = 240; $SWFWidth = $Width + 2; $SWFHeight = $Height + 44; break; case 2: $Width = 640; $Height = 480; $SWFWidth = $Width + 2; $SWFHeight = $Height + 44; break; case 3: $Width = 1280; $Height = 720; $SWFWidth = 736 + 2; $SWFHeight = 414 + 44; break; } // vb parameter can be omitted and let the program choosing a proper video bitrate $vb = $Width * $Height * ($Encoding==2?1.2:1.4) / 256; // please modify the path of fvec.exe if you did not use the default installation path $Command = "\"" . "/usr/bin/fvec/fvec\" " . "\"" . GetCurPath() . "/files/$FileName\" " . "\"" . GetCurPath() . "/files/$FileName.flv\"" . " -vw " . $Width . " -vh " . $Height . ($Encoding==2?" -h264":""). " -vz " . $Zoom . " -ac " . $Channels . " -tn " . "\"" . GetCurPath() . "/files/$FileName.jpg\" " . " -tw 160". " -th 120". " -vb $vb". ($TrimStart==""?"":" -ss $TrimStart"). ($TrimEnd==""?"":" -endpos $TrimEnd"); if($Watermark != 0) { $Command = "$Command -wn " . "\"" . GetCurPath() . "/watermark.png" . "\"" . " -ws 3,5"; if($Watermark == 1) { $Command = "$Command -wp 5,5"; } else { $xpos = $Width - 53; $Command = "$Command -wp $xpos,5"; } } // Use Windows path style so fvec.exe can handle it correctly. $Command = str_replace("\\", "/", $Command); echo("<p>Executing command: <br>$Command</p>"); echo("<br>"); // We do not use exec() because we want to get the Stdout line by line. //$StdOut = exec("\"$Command\"", $Lines, $ExecResult); $GotOutput = false; $ExecResult = -1; $CrLf = "\n"; $FirstLine = true; $RegExPattern = "([0-9]+)"; $descriptorspec = array( 0 => array('pipe', 'r'), // stdin is a pipe that the child will read from (we do not use it). 1 => array('pipe', 'w'), // stdout is a pipe that the child will write to and we will read from. 2 => array('pipe', 'w') // stderr is a file to write to (we do not use it). ); $process = proc_open("$Command", $descriptorspec, $pipes); //$process = proc_open("\"$Command\"", $descriptorspec, $pipes); if (is_resource($process)) { while(!feof($pipes[1])) { $InputLine = fgets($pipes[1], 1024); if (strlen($InputLine) == 0) break; $GotOutput = true; if(strcmp(substr($InputLine, 0, 6), "Error:") == 0) { echo("<font color=\"#ff0000\">" . $InputLine . "</font><br>" . $CrLf); break; } if(strcmp(substr($InputLine, 0, 9), "Percent: ") == 0) { if($FirstLine) { $FirstLine = false; echo("<p><table width=\"404\" bgcolor=\"#000000\" border=\"0\" cellspacing=\"0\" cellpadding\"1\"><tr><td>" . $CrLf); echo("<table width=\"100%\" bgcolor=\"#ffffff\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\"><tr><td><img id=\"bar\" src=\"bar.gif\" width=\"0\" height=\"10\" alt=\"Progress\"></td></tr></table>" . $CrLf); echo("</td></tr></table></p></td></tr></table>" . $CrLf); //echo(str_repeat(' ', 256)); ob_flush(); flush(); } $Matches = NULL; ereg($RegExPattern, $InputLine, $Matches); if(count($Matches) > 1) { // display the current encoding progress $Percent = $Matches[0]; echo("<script language=\"javascript\">document.all(\"bar\").width = " . ((int)$Percent * 4). "</script>" . $CrLf); ob_flush(); flush(); } } else { if(strcmp(substr($InputLine, 0, 9), "Duration:") == 0) { // get the duration of the input video. $Duration = StringToTime(trim(substr($InputLine, 10))); } //echo($InputLine . "<br>" . $CrLf); } } // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); // get the exit code of fvec.exe. $ExecResult = proc_close($process); } // remove the uploaded file. unlink(GetCurPath() . "/files/$FileName"); if($ExecResult == 0) { $Conn = NULL; $Sql = NULL; $Conn = OpenDB(); $time = date('Y-m-d H:i:s', time()); if(!$Duration) $Duration = 0; $Sql = "INSERT INTO VIDEOS (AUTHOR, TITLE, DIMENSION, DURATION, ORIGINALFILE, FLVFILE, IMAGEFILE, UPLOADTIME, VIEWS) " . "VALUES ('$Author', '$Title', $Dimension, $Duration, '$FileName', '$FileName.flv', '$FileName.jpg', '$time', 1);"; mysql_query($Sql); $err = mysql_error(); mysql_close(); if($err) echo "Error: " . $err . "<br>"; ?> <table width="780" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td valign="middle"> <p> </p> <?php } else { echo("<font color=\"#ff0000\">Error: failed to encode the file. The exit code is $ExecResult</font><br>" . $CrLf); } ?> </td> </tr> </table> <br> <div class="halfmoon"> <ul> <li><a href="index.php">Upload Finished ! Please Press Here</a></li> </ul> </div> </body> </html> new friend of mine from phpsnaps helped me modified the fvec for ffmpeg and mencoder, this is what he had to say about this, but im not sure how i should use this information to correct things. since im very new to php heir code uses the $ExecResult to check for encoding error, you should set the output of your encoding code to go there, so that the existing flow of the code remains the same. The errors you get have to do with the way the variables are presented in a string. The correct way is to concetate string with the dot, not like this: 'a big string with a $variable'; After you see the code below, you should check what is the output of the convert function ($ExecResult). Because: if($ExecResult == 0) that means the conversion was successful (well, at least with the old code). Which means, if the function flv_convert_get_thumb() runs with success but it doesn't return 0, the script will give you error, even if the conversion happened! Quote Link to comment https://forums.phpfreaks.com/topic/158680-encoding-not-start-and-image-not-being-grabbed/#findComment-836921 Share on other sites More sharing options...
MadTechie Posted May 19, 2009 Share Posted May 19, 2009 #1 try echoing the $res from the shell_exec's to see what happening #2 Check the server logs Has this ever worked before ? so you have full access to the server ? okay so no it hasn't worked before.. Have you checked the logs and echoed the $res ? EDIT: also is this on your own PC or a shared server? Quote Link to comment https://forums.phpfreaks.com/topic/158680-encoding-not-start-and-image-not-being-grabbed/#findComment-837488 Share on other sites More sharing options...
mysoogal Posted May 19, 2009 Author Share Posted May 19, 2009 yes its on my development machine, ubuntu 8.10 with everything installed it works on the original code but with the replaced code, it doesn't seem to start the ffmpeg to get image and encoding not starting also. the res i believe i used 1 to show encoding error. but still same doesn't give exactly the error since the output error is for the fvec. ??? Quote Link to comment https://forums.phpfreaks.com/topic/158680-encoding-not-start-and-image-not-being-grabbed/#findComment-837752 Share on other sites More sharing options...
MadTechie Posted May 20, 2009 Share Posted May 20, 2009 Okay this was my first post in this topic #1 try echoing the $res from the shell_exec's to see what happening #2 Check the server logs Has this ever worked before ? so you have full access to the server ? So far i know this #1 try echoing the $res from the shell_exec's to see what happening -- unknown #2 Check the server logs -- unknown Has this ever worked before ? - no so you have full access to the server ? - yes and from the start you said it inserts data into mysql database but only image and encoded video are not being done and this is from your own code // get thumbnail $cmd = 'ffmpeg -v 0 -y -i '.$FileName.' -vframes 1 -ss 5 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 '.$FileName_JPG; $res = shell_exec($cmd); // $res is the output of the command So // $res is the output of the command Now I know if you make a call to a problem and that program isn't found you get an error, this error is found in the server logs and in the output of the command.. however these are the two things you have yet to tell me! With all that in-mind i am going to guess and say you need to add the path to ffmpeg and mencoder into the code. Quote Link to comment https://forums.phpfreaks.com/topic/158680-encoding-not-start-and-image-not-being-grabbed/#findComment-837761 Share on other sites More sharing options...
mysoogal Posted May 20, 2009 Author Share Posted May 20, 2009 so just below, i should add my ffmpeg and mencoder code ? but isn't this already used by this cmd line above. here is the whole project. mysoogals.zip - 1017.7 Kb if you want to check out for your self. and few other files like vlc player. i will try to add the mencoder code below hope it works. $res = shell_exec($cmd); // $res is the output of the command if you want to test it out, fully please let me know. i believe maybe the theme not show up in index.php Quote Link to comment https://forums.phpfreaks.com/topic/158680-encoding-not-start-and-image-not-being-grabbed/#findComment-837817 Share on other sites More sharing options...
MadTechie Posted May 20, 2009 Share Posted May 20, 2009 Okay.. i am not testing the whole code, YOU need to debug it.. as my setup will be different from yours! when you choose to supplie some useful/requested information i will continue to help! Quote Link to comment https://forums.phpfreaks.com/topic/158680-encoding-not-start-and-image-not-being-grabbed/#findComment-838007 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.