I assuming it is unefficent to upload and stream a video with php.
So this is a 2 part question (1. using php to upload the contents, 2. using php? flash? etc? to convert and play the video file).

1. How would I upload a video file? - Like a normal file?
2. Now If I converted to a fla format, I would do this before or after the video file is uploaded?
3. How do I stream a live video?
4. How much bandwidth am I looking at consuming?

In short im looking for video tutorials that can be used to upload and play your own videos (something similar to youtube - on a very small scale). What is the best way to do this?

Thankyou, Regards X

PS: The same concept for the video would be used for a powerpoint presentation?

I assuming it is unefficent to upload and stream a video with php.
So this is a 2 part question (1. using php to upload the contents, 2. using php? flash? etc? to convert and play the video file).

1. How would I upload a video file? - Like a normal file?
2. Now If I converted to a fla format, I would do this before or after the video file is uploaded?
3. How do I stream a live video?
4. How much bandwidth am I looking at consuming?

In short im looking for video tutorials that can be used to upload and play your own videos (something similar to youtube - on a very small scale). What is the best way to do this?

Thankyou, Regards X

PS: The same concept for the video would be used for a powerpoint presentation?

Hi,

Acco'd to my knowledge uploading of any file can be done by PHP. And videos are converted on the fly to flv format from any format using FFMPEG. Basically to start a site like youtube or any thing which streams videos requires FFMPEG modules installed. And secondly the bandwidth issue is it depends on the file size. Say the video is of 1mb, you upload it, and is viewed 10 times. So the bandwidth used is 1+1*10=11mb used. I hope you understood.

Ya I gather most of that and I have uploaded files to a server before, details to a database, etc just never video.

When a person uploads a video the 'FFMPEG ' would convert it to fla and store it on the server and then would be avaliable to all to see? How would I code that? Would I need to make sure my server supports x, y and z?

I was thinking when you upload it FFMPEG converts it to fla and stores it and then you could easily make a webpage with basic html to play the file?

Let me know your ideas, more importantly example code but ideally some sort of website with a tutorial (I have searched and nothing but youtube this and youtube that tutorials).

Thanks, Regards X

<?php ob_start("ob_gzhandler"); ?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"><meta name="distribution" content="global">
<meta http-equiv="content-Script-Type" content="text/javascript"><meta name="author" content="Rob Dockrey 2004">
<style type='text/css'>
<!--
.logo { 
 background-color: #eeeeee; 
 color: #000000;
 text-align: right; 
 font-family: verdana, geneva, arial, serif;
 font-size: 8pt;
 top: expression(document.body.scrollTop + 
 document.body.clientHeight - 
 offsetHeight );
 left: expression(document.body.scrollLeft + 
 document.body.clientWidth - 
 offsetWidth - 1 );
 position: absolute;
}
-->
</style>
<script type="text/javascript">
<!--//
function shrink(){
 document.getElementById("MediaPlayer1").style.width=384;
 document.getElementById("MediaPlayer1").style.height=300;
}
function enLarge(){
 document.getElementById("MediaPlayer1").style.width=480;
 document.getElementById("MediaPlayer1").style.height=402;
}
 //-->
</script>
<title>video - Entertainment - Dockrey Apartments</title>
</head><body><a name='top'></a>
<p class='logo'>
<button onclick="enLarge()">large</button>
<button onclick="shrink()">small</button>
<a class='button' href='..'>Main Menu</a>
<A href="http://www.microsoft.com/windows/windowsmedia/player/download/"><IMG ALT="Get Windows Media Player" SRC="http://www.microsoft.com/windows/windowsmedia/images/logos/getwm/mp11_88x31_static.gif" WIDTH="88" HEIGHT="31" BORDER="0"></A><br>
<OBJECT ID="MediaPlayer1" width=384 height=300 classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">
<PARAM NAME="fileName" VALUE="">
<PARAM NAME="showControls" VALUE="true">
<PARAM NAME="PlayCount" VALUE="0">
<PARAM NAME="animationatStart" VALUE="true">
<PARAM NAME="transparentatStart" VALUE="true">
<PARAM NAME="autoStart" VALUE="true">
<EMBED type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="" name="MediaPlayer1" width=360 height=260 AutoStart=true></EMBED></object></p>
<p>Videos<div style='float:left; text-align:left;'>
<?php $p = split('/', $_SERVER['SCRIPT_FILENAME']);
	$script_name = $p[count($p)-1];
	$path = str_replace($script_name, '', $_SERVER['SCRIPT_FILENAME']);
	$dir_handle = @opendir($path) or die("Unable to open $path");
	Function get_Extension($m_FileName){
 	$path_parts = pathinfo($m_FileName);
 	if ($path_parts["extension"]) {
 		$m_Extension = strtolower($path_parts["extension"]);
 		return(strtoupper($m_Extension));
 		}
 	else { return "unbekannt"; }
 }
 function check_image($filename){
 $temp=strtoupper(get_Extension($filename));
 if(($temp=="WMV")||($temp=="ASF"))
 return (true);
 else
 return (false);
 }
 Function get_Files($path) {
 	if ($handle = opendir($path)) {	
 		while (false !== ($file = readdir($handle))) { 
 		if(!is_dir($file) && substr($file,O,1) != "."){				
				$m_Files[]=$file;
 			}
 		}
 closedir($handle); 
 	}
 if(sizeof($m_Files)>1)
 asort($m_Files);
 return $m_Files;
 }
 $files=get_Files($path); 
 $filter_files=array_filter($files,"check_image");
 $maxnr=sizeof($filter_files)-1;
 sort($filter_files);
for ($i=0;$i<sizeof($filter_files);$i++){
	echo "<a class='button' onclick=\"MediaPlayer1.SRC='$filter_files[$i]';MediaPlayer1.fileName='$filter_files[$i]';\">";
	echo substr($filter_files[$i], 0, strlen($filter_files[$i])-4);
	echo "</a><br>";
 }
closedir($dir_handle); ?>
</p>
</body></html>
<?php ob_flush(); ?>

serves wmv asf files, without flash overhead

The code looks good but when I tried to run it, there was only an out of area media player available, no upload, no movie and also required active x.

Is there something more like you tube script available or something?

Thanks

google, utube clone script
upload and serve scripts are always separate
often in the same package, but separate

almostbob - Will do so now, thanks.

I have been doing some research with php and video and the "FFMPEG" has come up several times, which will allow me to covnert and play my videos like youtube does but I havent found anything accurate yet.

So pretty much looking for a php video script that will lead to a mini website of youtube.

Thanks, Regards X

Here is a bit on uploading files in PHP:
http://www.php.net/manual/en/features.file-upload.post-method.php

You can convert the file to flv after uploading using FFMPEG and FLVTool2 for the metadata.
FFMPEG-PHP can help with this: http://ffmpeg-php.sourceforge.net/

It's probably easier to use FFMPEG and FLVTool2 in the command line first and when you're successful, try doing it from PHP with exec().

The tutorial given previously explains this well.

You'll need root access to install FFMPEG and FLVTool2. If you don't have this, you could probably get away with uploading the video file to a site such as google video or youtube, and then downloading the converted FLV through their API.

Basically there are 2 ways of streaming the FLV to the flash player.

1) using HTTP
2) using a streaming protocols such as RTMP (Real Time Messaging Protocol)

http://en.wikipedia.org/wiki/Flash_Video#Delivery_options

Using RTMP requires a streaming server, such as Red5 (open source).

If you won't want to use a special server, just using your HTTP server would allow you to progressively download the FLV without any special setup. Just giving your choice of flash player (eg: http://www.longtailvideo.com/players/jw-flv-player/) the URL of the flv and it should "stream". The only thing it won't be able to do is seek (seek to a position not yet downloaded).

You can stream the FLV, and allow seeking using HTTP by having PHP control the HTTP stream:
http://www.flashcomguru.com/index.cfm/2005/11/2/Streaming-flv-video-via-PHP-take-two

Here is a PHP class based on this:
http://xmoov.com/xmoov-php/

There is a server implementation in Lighty based on the same:
http://blog.lighttpd.net/articles/2006/03/09/flv-streaming-with-lighttpd
http://jan.kneschke.de/projects/flv-streaming/

This is better then using PHP, since PHP has a greater overhead, but it isn't a problem with just a few simultaneous downloads.

commented: Very useful and informative post, Thankyou! +3

Great Information digital-ether, Thankyou!!!

I have read your post and had a brief look at your links.
So with the links you have given me it looks like I will be able to:
- Upload a file (PHP).
- Convert it (FFMPEG).
- Store it on the server (HTTP).
- Then play it (HTTP).

Few things I noticed are:
- Should I convert then upload? or upload then convert?
- FFMPEG can be installed onto my server's site, if I have access to the root? meaning www folder?
- Get the idea of the streaming and requests just gotta check that out in more detail for more information and ill get back to ya.

Thanks for the useful and informative information!!

Regards, X

Reading the sites now in detail, to start anything I think I need to know how to :
- How do I install FFMPEG onto my localhost? I have a basic apache, php, mysql setup

Great Information digital-ether, Thankyou!!!

I have read your post and had a brief look at your links.
So with the links you have given me it looks like I will be able to:
- Upload a file (PHP).
- Convert it (FFMPEG).
- Store it on the server (HTTP).
- Then play it (HTTP).

Few things I noticed are:
- Should I convert then upload? or upload then convert?
- FFMPEG can be installed onto my server's site, if I have access to the root? meaning www folder?
- Get the idea of the streaming and requests just gotta check that out in more detail for more information and ill get back to ya.

Thanks for the useful and informative information!!

Regards, X

- Should I convert then upload? or upload then convert?

It depends on whether you want the process automated, or want to do it yourself. If you can install FFMPEG and FLVTool2 on your server and write the PHP code to do the automated conversions, then you might as well do it and save the manual conversions.

- FFMPEG can be installed onto my server's site, if I have access to the root? meaning www folder?

Root access means that you can log into the system as the root user, and/or gain root privileges in order to install programs and do other tasks.

This is usually given when you have a dedicated server, or a VPS server.

With shared servers, you do not have root access, however, you can ask your host to install the needed programs for you.

It depends on whether you want the process automated, or want to do it yourself. If you can install FFMPEG and FLVTool2 on your server and write the PHP code to do the automated conversions, then you might as well do it and save the manual conversions.

So how do I install FFMPEG and FLVTool2 onto my localhost and my server?

Reading the sites now in details:
Questions:
- How do I install FFMPEG onto my localhost?
- I have a basic apache, php, mysql setup

If you localhost running windows?

If so download a windows binary:

eg: http://ffmpeg.arrozcru.org/builds/

Then put that into your system path (if you want).

Here is the docs on using ffmpeg command:

http://ffmpeg.org/ffmpeg-doc.html

It depends on whether you want the process automated, or want to do it yourself. If you can install FFMPEG and FLVTool2 on your server and write the PHP code to do the automated conversions, then you might as well do it and save the manual conversions.

So how do I install FFMPEG and FLVTool2 onto my localhost and my server?

What are you running on your web server? You can either build FFMPEG or install it using the package manager for your particular linux distribution.

Im pretty sure my hosting is LINUX but I run WINDOWS. But I use windows to access both not linux. So I think I would need to know how to install it on windows first and then contact me web host about installing it on the server? or if i just need to install it on the root I can do that myself as I have access. But that still leaves how to install on windows as it only has linux instructions.

Thanks

Im pretty sure my hosting is LINUX but I run WINDOWS. But I use windows to access both not linux. So I think I would need to know how to install it on windows first and then contact me web host about installing it on the server? or if i just need to install it on the root I can do that myself as I have access. But that still leaves how to install on windows as it only has linux instructions.

Thanks

I presumme you are on a shared server?

As far as I know there isn't a shared server host that supports FFMPEG.

It causes allot of strain on the servers so they tend not to allow it.

If the server doesn't already have FFMPEG installed then you will need Shell Root Access, this is like command prompt for winodws.

I would advise you (if you are serious about this) to falk out some extra money on either a dedicated server or a VPS server.

You should be able to install FFMPEG on either but I would presume you would need a heafty VPS server to handle FFMPEG as allot only allow you 500MB burstable RAM.

Have you thought of building a quad core system and paying a local computer store to give it unsupported hosting (means you have to do everything yourself, it's your computer). Although you would have to falk out £640 for a copy of windows server 2003 (the cheapest) because I doubt you would be able to run a server using SSH.

Im pretty sure my hosting is LINUX but I run WINDOWS. But I use windows to access both not linux. So I think I would need to know how to install it on windows first and then contact me web host about installing it on the server? or if i just need to install it on the root I can do that myself as I have access. But that still leaves how to install on windows as it only has linux instructions.

Thanks

On windows you just have to download one of the windows binaries. Here is the link again to an unofficial windows builds:

http://ffmpeg.arrozcru.org/builds/

For example, the latest build they have right now is:

http://ffmpeg.arrozcru.org/builds/bin/ffmpeg-latest.tar.bz2

Download that. Then uncompress it on your computer. This will give you an .exe file. Basicaly you're done.

To use it, you just need to open the command prompt:
Start -> All programs -> accessories -> command prompt

In the command prompt type in the full path to the ffmpeg.exe file you extracted.

eg: c:\downloads\ffmpeg.exe

This should give you some info on ffmpeg if you did it right.

For convenience, you want to put the path to that exec file in your windows system path. This is a list of folders that windows will look for commands.

Just search "edit windows system path" and you should have lots of tutorials on how to do that.

Once in the path, you can call ffmpeg in the command line by its name, and not its path.

On my windows system I copied ffmpeg.exe to c:\mybin\ffmpeg.exe for convenience. I have c:\mybin\ in the system path, so what ever *.exe I put in there becomes a command automatically.

commented: Thanks for the instructions! +3

I presumme you are on a shared server?

As far as I know there isn't a shared server host that supports FFMPEG.

It causes allot of strain on the servers so they tend not to allow it.

If the server doesn't already have FFMPEG installed then you will need Shell Root Access, this is like command prompt for winodws.

I would advise you (if you are serious about this) to falk out some extra money on either a dedicated server or a VPS server.

You should be able to install FFMPEG on either but I would presume you would need a heafty VPS server to handle FFMPEG as allot only allow you 500MB burstable RAM.

Have you thought of building a quad core system and paying a local computer store to give it unsupported hosting (means you have to do everything yourself, it's your computer). Although you would have to falk out £640 for a copy of windows server 2003 (the cheapest) because I doubt you would be able to run a server using SSH.

Shared hosting dreamhost.com has FFMPEG and flvtools2 on the machine I'm on. I haven't used it much, but it worked when I tested it just now. Transcoding a 400MB wmv to FLV with FFMPEG took about 10 minutes. I have no idea if thats considered fast or slow.

Thanks for the instructions!

Now I will just run ffmpeg in command prompt and learn it and see if it works.

Now if it does how do I translate this to run it off php to while uploading and converting?

I have to do some programming like system(C:\ffmpeg\etc)?
Followed by the parameters -a -b -c in php something like that?

Shared hosting dreamhost.com has FFMPEG and flvtools2 on the machine I'm on. I haven't used it much, but it worked when I tested it just now. Transcoding a 400MB wmv to FLV with FFMPEG took about 10 minutes. I have no idea if thats considered fast or slow.

I suppose thats actually kinda quick as you'll find most shared servers are terribly over filled so to speak.

Thanks for the instructions!

Now I will just run ffmpeg in command prompt and learn it and see if it works.

Now if it does how do I translate this to run it off php to while uploading and converting?

I have to do some programming like system(C:\ffmpeg\etc)?
Followed by the parameters -a -b -c in php something like that?

google PHP execute, this should work, it basicly allows you to execute a batch programm so would be pretty much like typing in the command window.

I have had some trouble with exec because if the command prompt doesn't close within 60 seconds you get a script timeout error. I suppose the command prompt stays open though :P.

Take a look at using cron jobs after the file is uploaded.

Basicly upload the file and upon completion give them a message saying, we are currently checking the file or whatnot we will email you when it's done.

Then update the mysql database and when the cron job next runs it will convert the file stated in the mysql database from the current file extension to flv for instance. When this cron job finishes you could say change a field from 1 (needs converting) to 2 (needs the user to be notified) , this means you can have another cron job checking for user notifications, and when it finds one it sends the email then changes the field to 3 (done).

You could also add another cron job that could generate a page or something but you could just do that from the MySql database.

I havent had anytime to construct some demo code but hopefully soon I will.

Josh - Thanks for the instructions, sounds feasable.

Now on the assumption everyone works. Will I use "flvtools2" to play that newly converted flv file on the webpage?

Thanks, X

Note: Im reading "php execute" as we speak well see how we go with that to.

I have had some trouble with exec because if the command prompt doesn't close within 60 seconds you get a script timeout error. I suppose the command prompt stays open though

You can set the max_execution_time with either set_time_limit(0) or ini_set('max_execution_time', 0) to allow the script to execute indefinitely. (If you aren't in safe mode).

Now if it does how do I translate this to run it off php to while uploading and converting?

I have to do some programming like system(C:\ffmpeg\etc)?
Followed by the parameters -a -b -c in php something like that?

You don't want to transcode the file right after upload since you'd have the user waiting for a few minutes with no indication of whats happening on the other end.

So the cron job would definitely be a better option.

Basicly upload the file and upon completion give them a message saying, we are currently checking the file or whatnot we will email you when it's done.

Then update the mysql database and when the cron job next runs it will convert the file stated in the mysql database from the current file extension to flv for instance. When this cron job finishes you could say change a field from 1 (needs converting) to 2 (needs the user to be notified) , this means you can have another cron job checking for user notifications, and when it finds one it sends the email then changes the field to 3 (done).

You could also start a background process to do the transcoding using & in the command on linux.

eg:

exec("/path/to/ffmpeg -i inputfile.mpeg outputfile.flv &");

The & switch makes the exec() return immediately, and the command is run as a new process.

The problem with this is that you have no indication of when the trancoding has completed since PHP has no interprocess communication with the forked ffmpeg process.

What you could do instead if write a PHP script that does the transcoding and then fork to that script when you need transcoding.

eg:

exec("/usr/bin/php /path/to/phpfile -i inputfile.mpeg outputfile.flv &");

The PHP file would just take what it received as arguments and proxy it to ffmpeg:

<?php

// write starting trancode to database

$arg_str = implode(" ", $argv);
exec("/path/to/ffmpeg ".$arg_str); 

// update transcoding completed to database

?>

Basically what you did was start a PHP process/script through the command line with exec(). This makes PHP preserve the arguments parsed to $argv just like $_GET and $_POST when PHP is called from the server API (from the web).

You then pass the same arguments to ffmpeg in the PHP script. You don't pass & this time so PHP will know when the process terminates.
You then update the database or other storage you have with the result, and so the user can know its done.

This bypasses that hassle with using cron.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.