?
Solved

Uploading video using PHP

Posted on 2009-05-18
1
Medium Priority
?
448 Views
Last Modified: 2012-05-07
Dear all,

i manage to upload my videos using the following script but unable to convert it to flv nor display the thumbnails. I have followed the ffmpeg installation from this site http://www.myownserver.info/index.php/step-4-additonal-settings/11-installffmpeg.html

i'm using windows running on xampp apache on localhost.

may i know why and is thr any other alternative for me? thanks!
++++++++ uploadvideo.html++++++++++++++++++++++
 
<form name="frm" action="uploadvideopro.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>
 
 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 
+++++uploadvideopro.php+++++++++++++++++++++++++++++++++++++++++++++++++
 
<?php
 
/***************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");
 
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
?>
 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Open in new window

0
Comment
Question by:bosscat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
biztiger earned 1500 total points
ID: 24543677
For converting the video, always give the full path name of ffmpeg.exe on the exec function.

That means if you are converting wmv file, try this:-

if( $fileExtension == "wmv" ) {
 
exec("C:\ffmpeg -i ".$dynamic_path."/".$moviepath."".$fileName."
-sameq -acodec mp3 -ar 22050 -ab 32 -f flv -s 320x240 ".$dynamic_path."/".$flvpath."myflv.flv");
 
}

It assumes that ffmpeg is installed on c:\ (that means the path to ffmpeg.exe is c:\ffmpeg.exe)

Also your codesnippet will work if you add ffmpeg as a Environment Variable and put the path of the ffmpeg.exe as the value of environment variable.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question