Monday 1 April 2013

Filled Under:

PHP- Upload and convert avi, wmv, mov and mpg videos to FLV


You can Upload and convert video file like avi, wmv, mov and mpg videos to FLV using PHP language. And also can create image using php.


1.First you have to created a page from where the user will upload a video file.
call it uploadvideofile.php.
 


 <form name=”frm” action=”uploadvideo.php” method   
 =”post” enctype="multipart/form-data" >  
 <input name="x_URL" type="file" class="form1"   
 size="26">  
 <input type="submit" name="submit" value="upload" >  
 </form>  
 2.Secondly on the process page i.e. uploadvideo.php . follow the following   
 code..  
 /***************Load FFMPEG *********************************/  
 $extension = "ffmpeg";  
 $extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;  
 $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;  
 // load extension  
 if (!extension_loaded($extension)) {  
 dl($extension_soname) or die("Can't load extension $extension_fullname\n");  
 }  
 /***********************************************************/  
 /*****************Get the path to Extention ****************/  
 $array_path = explode("/",$_SERVER['SCRIPT_FILENAME']);  
 $dynamic_path = "";  
 for ($i=0;$i<sizeof($array_path)-1;$i++)  
 if($array_path[$i]!="")  
 $dynamic_path =$dynamic_path."/".$array_path[$i];  
 /**********************************************************/  
 /******************set folders*****************************/  
 $flvpath = "flvfiles/";  
 $moviepath = "movies/" ;  
 chmod($moviepath,0777);  
 chmod($flvpath,0777);  
 /*********************************************************/  
 /******************Upload and convert video *****************************/  
 if(isset($_FILES["x_URL"]))  
 {  
 $fileName = $_FILES["x_URL"]["name"];  
 $fileNameParts = explode( ".", $fileName );  
 $fileExtension = end( $fileNameParts );  
 $fileExtension = strtolower( $fileExtension );  
 if($fileExtension=="avi" || $fileExtension=="wmv" || $fileExtension=="mpeg"   
 || $fileExtension=="mpg" || $fileExtension=="mov" )  
 {  
 if ( move_uploaded_file($_FILES["x_URL"]["tmp_name"],$ moviepath.$_FILES["x_URL"]["name"])   
 )  
 {  
 if( $fileExtension == "wmv" ) {  
 exec("ffmpeg -i ".$dynamic_path."/".$ moviepath."".$fileName."   
 -sameq -acodec mp3 -ar 22050 -ab 32 -f flv -s 320x240 ".$dynamic_path."/".$flvpath."myflv.flv");  
 }  
 if( $fileExtension == "avi" || $fileExtension=="mpg" ||   
 $fileExtension=="mpeg" || $fileExtension=="mov" ) {  
 exec("ffmpeg -i ".$dynamic_path."/".$ moviepath."".$fileName."   
 -sameq -acodec mp3 -ar 22050 -ab 32 -f flv -s 320x240 ".$dynamic_path."/".$flvpath."myflv.flv");  
 }  
 /******************create thumbnail***************/  
 exec("ffmpeg -y -i ".$dynamic_path."/".$moviepath."".$fileName."   
 -vframes 1 -ss 00:00:03 -an -vcodec png -f rawvideo -s 110x90 ".$dynamic_path."/".$flvpath."myflv.png");  
 }  
 else  
 {  
 die("The file was not uploaded");  
 }  
 }  
 else  
 {  
 die("Please upload file only with avi, wmv, mov or mpg extension!");  
 }  
 }  
 else  
 {  
 die("File not found");  
 }  




3 comments:

  1. I have tried to implement this but have no luck i get an error stating

    Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/trallwn/public_html/CHS/uploadvideopro.php on line 90

    i have copied and pasted the code so know i havent copied anything down in correct but havent installed ffmpeg. where do i need to put what ffmpeg files if any atall?

    ReplyDelete
    Replies
    1. Hi James Jones,

      first enable ffmpeg on your server and than download complate working example from this link,

      http://dudhalavillage.com/demo/download/ffmpeg_example.rar

      and take care your work....

      Delete