Uploading and Storing videos online using PHP and ffmpeg - php

I have a website that allows users to upload videos to it,
After they upload videos, I would like to be able to display them using a flash player.
One flash player i know is flowplayer, althrough if anyone knows a better one I will be happy to know.
In any case, as I understood from a brief google search, there are no players that can play .avi/.mpeg files, but they can only play .flv files.
I began searching for ways to convert my user's avi's/mpeg's and found that I can use ffmpeg to convert the video to .flv using system().
Is this the best solution for me? I feel like ffmpeg takes a lot of CPU and once I have enough users the server will crash..
Thanks!

Just an outline
(Note: i don't own nor wrote a PHP video sharing site, so treat these like tips)
Set up your web server and PHP to be capable of accepting large files via HTTP
Let users upload their videos via a web interface
Upon successful upload add uploaded video to a queue
Set up a fully server side script that handles video processing (No PHP)
Run a cron job on this queue when your server is able to crunch uploaded videos
Notify users when videos are done
Hope it helps in some way.

Related

How do i get my file-sharing script to stream uploaded videos?

Let's say i have this file-sharing website script but you see, all it
does is share files, like PutLocker.com , i want it so that if a file
with an extension like ".mp4 or .mpeg etc" is uploaded, it uses your
player to stream the file instead of just having shared...
For example:
Jim's wants to start a website, but he is weak at coding. So he gets a
file sharing script.
But the file-sharing script does just that, share files! Jim wants
people to be able to stream their video files aswell, and if happy
worm's player allows him, stream just audio too!
So a user uploads to his website a regular folder, the link is shared,
the script is working fine. But then a user uploads a .mpeg video and
Jim does not want his website to just share the file, he wants his
script to allow users to automatically stream the video file using
Happy Worm's jPlayer and give users an option to download.
I hope you're not lost, believe me i've read the documentation. Should
i just slap the player's source code in there or is there some lines
of code needed to tell it that it needs to stream using that player?
The script i am talking about is X Filesharing pro
I can link you to the php code i have if it would help better...
Thanks...
PHP runs server-side, it won't play media. (Just like physics, you simply can't.)
There are various solutions to deliver media, but the most widely used is Flash.
JWPlayer from LongTailVideo is perfect for what you need, both audio and video.
The documentation is comprehensive and the player itself has lots and lots of cool extras, such as:
buffering
a JS API (for HTML styling)
For thumbnails from video files you'll need third party tools (ffmpeg) installed on the server, some degree of technical knowledge and access to the exec() function in PHP so you can run command-line tools via PHP and output results.

How to convert a set of BitmapDatas into video?

I basically need to record a video of the flash stage, and save it as a video file on the webserver. I don't have FMS or the luxury of Java based servers like Red5 to stream to, so I am pretty much stuck with HTTP post to a php script. Now I can grab invidual snapshots (bitmapDatas) Just fine, but how can I convert them to a video file? Any help is appreciated.
PS: This is not an AIR app, so I am using flash runtime. And the video would be couple seconds long so there shouldn't be much of a performance concern at this point.
Flex provide a JPEG encoder. You can use that to compress the bitmap images and send them to the server, where you can that stitch them together using ffmpeg.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/codec/JPEGEncoder.html

Uploading video, with PHP serverside formatting & encoding

We've currently developed an ExpressionEngine site (php), and are using a paid JWPlayer to display video uploaded by the client.
At present we're running into a number of issues, as the client is:
Uploading video at the wrong size
Uploading video randomly in both flv or mp4 format
And the player is chugging along terribly with multiple pauses throughout the video - sometimes buffering the entire clip before it is played.
I know FFMPEG can be installed serverside, but I'm not sure of the way in which to go about this, and how it might interact between ExpressionEngine and JWPlayer. I'm also not sure about the formatting - the ability for this automated encoding process to also crop/resize the video to suit the player dimensions on the site.
We would really like to have the videos playable on all browsers & iOS devices.
A HQ option would also be great where applicable, but it's just a nice to have - as we're struggling with the formatting / encoding issues first and foremost.
Any help figuring out the best process, and what tools I might need would be greatly appreciated.
I'd reccomend using a service like zencoder
I've used them in the past and no matter what video format I've thrown at them it works great. (PS. I'm not affiliated with them at all)
There is a PHP API with a whole lot of resizing, quality and format options. After you've uploaded your video you can send it to zencoder and they'll send you a response some time later with success or fail.
They can put the processed video on Amazon S3 or FTP it to a server.
You'll need a HTML5 player for iOS devices though, unless JWPlayer has come a long way since I used it last.
You could get zencoder to output in mp4. and then you still only need mp4 for JWPlayer/flash and the HTML5 version for iOS, as long as your happy to use flash for all desktop browsers there's no problem.
As far as the buffering issues you are having - I have found that using a CDN version of the swf for JWPlayer (or whatever player you are using) has caused it to load the entire video file before playing. Easily fixed by hosting it yourself.
I have found many times the video conversion capabilities of different CMS to be limited, and often restricting video formats to what the developers thought was appropriate, such as FLV, which nowadays is turning obsolete for video delivery.
One of the ways you can approach it is by creating a custom script to process the videos uploaded by your client using FFmpeg, which in fact can accept almost any video format, and generate the correct output formats and dimensions, ensuring that the resulting videos will be suitable for web playback using your player.
The problem with the video buffering you are facing is because the video file is not prepared for progressive download or pseudo-streaming, so your browser needs to download the whole video before starting to play. This can be solved with programs like qt-faststart for MP4 and MOV video files, and flvtool2 for FLV files. So your script would need to also optimize the encoded videos using these tools.
Also note that if you use an HTML5 video player (browser native or recent JWPlayer), then you can enjoy from random seeking the video files without buffering them.
If starting from scratch is not an option, you can look into a commercial solution like tremendum transcoder which also uses FFmpeg and is quite simple to use, yet it does all you need in regards to dealing with different input formats and aspect ratios automatically.
I have done a few setups this way, separating the CMS part from the video processing part, and it saved me some headaches.

Upload Music files into server but restrict download?

I am developing a website for a rock band. I wanted to upload the music into the website and let the users listen to the songs. But, I want to add a functionality or some sort of code so that the users are not able to download the mp3 files that i will let the users listen. Suppose someone uses "Internet download manager", he she will be prompted to save the file on as soon as it get the music file. Is there any way to stop that.
Thanks.
There is always a way to bypass any restriction (either download the file or use an audio recorder).
The protection that iTunes and other music platforms use is to let you listen to a preview of the music (~30 seconds) so you cannot get the entire song.
Well, there is really no way to let someone listen to music without them downloading it. Even if you stream the music, they could still record it.
http://www.codewalkers.com/c/a/Miscellaneous/Using-PHP-to-Stream-MP3-Files-and-Prevent-Illegal-Downloading/
This could be of help to you, though, because it will make it much more difficult to download the music.
As mentioned by others, there is no foolproof way to keep the users from downloading the mp3s. Having said that, you could try streaming the content which will make it much more harder for most people.
You can use a streaming server like Red5 for this.
I've been working on the same, and what I did was to create two (or more) versions of each file. One file will be the listening file which in my case was a low quality MP3 file encoded with 112 kbps. The quality would be good enough for people to listen to it online, but not good enough if people wanted a decent quality when they are on the go with a portable player or the like.
Then i'd also have high quality MP3 versions (320 kbps) and WAV files which people could download only if they were logged in.
I can't say that I've found a solution which guarantees that people can't get hold of the music if that's what they are after. You could certainly use Red5 or some other streaming solution, but that requires you to spend more time and resources on configuring and maintaining that solution. Furthermore, I believe Red5/Wowza or any of the other streaming servers requires that the client use Flash to play music (because the communication is done over RTMP). That rules out iPad/iPhone/iPod users as Flash can't be used on those devices.
My conclusion was thus that with the (limited) resources I had the way to go was to offer playback over HTTP (aka "progressive http") using low quality files.

Video Uploading: recommended process?

Hey just a quick question for anyone who has done this. I want to create a video tube site. I have done file uploads before but was wondering if anyone could give me suggestions on what I am planning to do.
The way I am planning is to have a folder in my web directory and to upload videos into the folder after virus scanning and checking mime. The video will then be converted and compressed using FFMPEG into flv.
I will change the name and store the video reference id in mysql so the file name can be fetched and served.
I will serve the files using HTTP_Download to a flash player
$dl = new HTTP_Download();
$dl->setFile("$path");
$dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, "$path");
$dl->setContentType('video/flv');
$dl->send();
Anyone have any suggestions? Is it a good idea to put all videos in one directory?
You may want to consider a Java based uploader as PHP can run into timeout problems on large uploads.
Also do you FFMPEG processing as a CRON job not at upload as it takes a long time.
Look in something like Wowza Streaming Server to serve the videos. Allows streaming and everything is above the root. I name each video with a UID and send a parameter to the Flash video player to decide which one to play.
Where and how you store them will largely depend on how secure they need to be (i.e. should people be able to access the files in the directory directly? or should it be stored more securely than that?)
If direct access is fine, then putting them all in one folder is okay. If not, then you may want to obscure folder names, store them in a secure Database, or in a folder that is not accessible outside of the server.
Also, I'm hoping you're aware of the massive amounts of storage space and bandwidth such a service will consume? I hope you have a scaled solution ready to deploy if you're really serious about this..

Categories