FFMPEG painful. Anyone know how to upload/convert videos?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

FFMPEG painful. Anyone know how to upload/convert videos?

Post by scarface222 »

Hi guys,

I have been messing with ffmpeg for a while now and I have no idea how to use it. I downloaded ffmpeg 0.5 from the site and put it in my site folder. I am using someone's script for uploading and converting videos to flash and I just get the error
Warning: dl() [function.dl]: Not supported in multithreaded Web servers - use extension=ffmpeg.dll in your php.ini in C:\Web Files\wamp\www\k\includes\videoupload.php on line 26
Can't load extension C:\php5/ffmpeg.dll
First of all, do I need the FFMPEG stored in my site directory or will it be installed on the host server (if I find one that supports it) and if so where can I get the ffmpeg.dll to install it. I am testing the site in a local environment. If anyone has any pointers, I would greatly appreciate it. I have searched for solutions for a while now.

Thanks in advance

Code: Select all

<html>
<head>
<title>Untitled Document</title>
</head>
 
<body>
<?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");
 
}
?>
</body>
</html>
Last edited by Benjamin on Fri Apr 24, 2009 7:31 pm, edited 2 times in total.
Reason: Changed code type from text to php.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: FFMPEG painful. Anyone experienced to upload/convert videos?

Post by scarface222 »

Any pro developers out there who know how to upload/convert videos? At this point any advice will do just to help me into the right direction haha. I've never done something like this before and don't know where to start.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by Benjamin »

dl() is a function that loads PHP extensions at runtime. dl() will not work on your server due to the error specified above.

You'll need to edit your php.ini file to load the ffmpeg.dll in your php.ini file. If you are in a shared hosting environment, you will want to contact your hosting provider to see if they can enable it for you.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by scarface222 »

What about in a local environment? Where can I find a php_ffmpeg.dll file and do I need to have the FFMPEG folder in my site folder or is that something I need to look for the server to have installed? Have you ever needed this functionality before?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by Benjamin »

In windows there are several places you can place the file, including the system folder, the php extensions folder, and the same directory that the php binary is in. I would recommend searching google for information on where to get and how to install the extension. That's what I would do ;)
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by scarface222 »

lol yeah I've been searching for some days now. There is very limited information on this subject of uploading and converting to FLV. I thought maybe there was someone who had done this before in this forum who could break the process down for me. I know where I can place the file but the whole thing is confusing for me because it seems that the process is different in a local environment from a remote server provider environment so if I figure it out on my local testing environment it might not even work when I upload my site. Also, the materials I find talk about installing FFMPEG etc but I do not know if this means installing on your own server space or if it means installing on the server itself if you were a provider. The whole thing is just new to me is all. Thanks for trying anyway man.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by Benjamin »

Here's a start:

exec()
man ffmpeg
ffmpeg website
ffmpeg download - includes windows binaries

You also may want to search hotscripts.com for a script that has this functionality. You could then learn how it works and modify the existing code.

Another thing, you may want to consider setting up a linux programming environment on your computer. You can create a separate partition for it and dual boot linux & windows. Ubuntu is a good place to start.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by scarface222 »

I am currently using something called WAMP server, why would I need a linux environment and how would it help?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by John Cartwright »

It probably won't help in your case if your new to linux, but linux much easier to manage once you get the hang of things.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by scarface222 »

Appreciate your help. By the way have you ever used FFMPEG man? I still really want to find someone who has experience in this before I have to spend days trying learn what would take an expert 2 minutes to explain the basics of how FFMPEG is used. PS thanks astions, your resources will be useful for me.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by John Cartwright »

I think we used FFMPEG to capture a screenshot of uploaded videos way back when. Reguardless, what exactly are you having trouble with? The links provided are excellent resources for installing in both Windows and Linux environments. For your particular task it it should be rather simple as far as running the command (once you get everything configured correctly).

Converting an AVI to FLV would be a matter of (according to)

Code: Select all

ffmpeg -y -i /path/to/avi/12.avi -acodec mp3 -ar 22050 -f flv /path/to/flv/14.flv
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: FFMPEG painful. Anyone know how to upload/convert videos?

Post by scarface222 »

I just am unsure of the whole process. I am trying to achieve a video conversion and upload that is triggered via a form. I downloaded the latest version of FFMPEG, now what do I do with it? I understand the php and html code needed to execute the process but where does FFMPEG play in it? Do I need to install it on my computer to test it, and will I need to install it on the server once I upload my site or can I just drag the program into the site folder and find the dll for php to make it work on my local computer and then when it comes time to upload my site, I can just find a server that has FFMPEG readiness and forget about installing it? I'm sorry if I sound like an idiot but this whole process is just highly confusing to me. Thanks for bearing with me man.
Post Reply