September 12th, 2011

FFmpeg is a collection of multimedia tools and codecs that can be used for transcoding and displaying of various multimedia formats. Portions of FFmpeg can be found in well-known projects such as Google Chrome and VLC Player.
FFmpeg libraries are very useful if you plan to use your server a video hub, and some hosting providers advertise FFmpeg support right on the spec list. Say a user uploads video.mov (QuickTime format), and you need to convert it to video.flv (Flash video format). FFmpeg can do this for you:
ffmpeg -i video.mov -b 600k -r 24 -ar 22050 -ab 96k video.flv
FFmpeg is very command-line driven. In my personal experience, the best results is simply playing with command-line parameters until you get a result that looks good. Generally, if you aren't sure what input parameter to use, try leaving it off. FFmpeg will take a best guess, and their guess is pretty decent.
How you might use this on a server within a PHP script could be,
system("ffmpeg -i ".escapeshellcmd($uploadedFile)." -b 600k -r 24 -ar 22050 -ab 96k ".escapeshellcmd($uploadedFile).".flv");When the script finishes, you can present the user the converted file. Conversion could take a really long time, so you may want to use exec() instead and tell the user to check back later. Even better, set up a database table to queue uploaded files to be processed one at a time.
No exaggeration. If you do not plan this correctly, transcoding will grind your sever to a halt. An Intel i3 processor with 2 GBs of RAM can transcode an MPEG stream to H.264 in real time at decent quality. However, that will be all the meaningful work it can do.
Installing FFmpeg can be painful. There are so many libraries to hunt and juggle to get everything to work. Fortunately, various distros have done a lot of the heavy lifting for you, such as Ubuntu. Here are some commands to get you going:
sudo apt-get updatesudo apt-get install build-essential checkinstall git libfaac-dev \ libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev \ libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev \ libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html \ yasm zlib1g-devgit clone git://git.videolan.org/ffmpegcd ffmpeg./configure --enable-gpl --enable-libfaac --enable-libmp3lame \ --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora \ --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree \ --enable-postproc --enable-version3 --enable-x11grabmake
A couple pointers about this configure command. One is that mp3 and x264 are very popular and proprietary formats. This is why the "enable-nonfree" is being passed. You must check and make sure you are allowed to use them before enabling them.
CentOS can also fetch much of FFmpeg from a repository:
yum install ffmpeg ffmpeg-devel
If you are running Windows, there are some installers around, but I have personally never found one to work reliably. I recommend getting a Linux virtual machine running using VMware or VirtualBox and installing Ubuntu or CentOS on it.
If you are running a Mac, then installing FFmpeg is really easy if you use Mac Ports:
sudo port install ffmpeg +gpl +lame +x264 +xvid
Kick-off that command and come back later with everything installed.
You will want to do all your FFmpeg development locally before trying these things on the server because installing FFmpeg and getting the command line calls correct is simply not a simple task. You could take down your whole site. You'd much rather take down a local machine or virtual machine.
If you decided that you do want to offer FFmpeg or use it as a back-end to anything-to-anything transcoding service on your web server, you should not offer this on shared plans. This is something that should be VPS or dedicated only (and you should be pushing dedicated). That way, the customer is only burning CPU cycles that are allocated just to him/her.
Posted in Articles | No Comments
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment