The Secret Source, build your own YouTUBE

A how to on Installing FFMPEG on Ubuntu
So you would like to set up a site that allows users to upload videos of any format, get the server to convert the video to a Macromedia Flash format and then play it through a cool customized flash video player (Much like TouTube)? Well then this is the tutorial for you.
Setting up server side video conversion is not a secret, its just really a really complicated and painful thing to do. The main reason for this is the lack of support and documentation. However, a couple of fellow web developers and I have gone through the tedious task of figuring it all out. We have setup and implemented sites much like YouTube a number of times.

We now feel it is time to give back to the world in the form of this tutorial (And hopefully get tons of hits on NoboxMedia.com). So lets get started.

First a little background

We are going to set up a piece of software called FFMPEG. It’s a collection of software libraries that can record, convert and stream digital audio and video in numerous formats (Really cooool).

FFMPEG will allow visitors to your site to upload a video of almost any format and converts it to a video format called FLV, which is a flash video. This is what YouTUBE do (We think). The main reason for doing this, is to reduce the potential for viewing trouble in to ensure the videos which are streamed and at a reasonable file size.

If your looking for a robust scalable solution for a site which deals largely with uploading and playing videos, FFMPEG is a must have.

We are going to set it up on Ubuntu (We haven’t tried on anything else, but it might work). Any version of Ubuntu should be fine.

Step 1 - Compiling FFMPEG

A lot of the work in this tutorial is done in linux command line, so open up that console.

Ensuring that you have a reliable interent connection to your server, type out the following commands:

sudo apt-get build-dep ffmpeg
sudo apt-get install liblame-dev libfaad2-dev \
libfaac-dev libxvidcore4-dev checkinstall fakeroot
DEB_BUILD_OPTIONS=risky fakeroot apt-get source ffmpeg –compile

Install all the deb packages that are created. A little finer control could be exercised if instead of setting DEB_BUILD_OPTIONS, the debian/rules file can be edited.

Additional configuration

(Some steps may be excluded as were performed above)
First, get your dependencies:

sudo apt-get build-dep ffmpeg
sudo apt-get install liblame-dev libfaad2-dev \
libfaac-dev libxvidcore4-dev liba52-0.7.4 \
liba52-0.7.4-dev libx264-dev checkinstall \
build-essential subversion

Step 2 - Next, grab the ffmpeg source:

Type the following command in your console:

svn checkout -r 8998 svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

If you’re feeling adventurous, you can try the very latest code by omitting the -r 8998 part of that line. Revision 8998 is the latest at the time of writing, and worked for us.

Now you can configure and build ffmpeg. Use the following commands, this takes a little while:

cd ffmpeg
./configure --enable-gpl --enable-pp --enable-libvorbis \
--enable-libogg --enable-liba52 --enable-libdts \
--enable-dc1394 --enable-libgsm --disable-debug \
--enable-libmp3lame --enable-libfaad --enable-libfaac \
--enable-xvid --enable-pthreads --enable-x264
make

Finally, install it. checkinstall gives you the option to edit some parameters: I set the name to ffmpeg and the version to 3:0.svn20070511

sudo checkinstall

Step 3 - Install FFMPEG-PHP

ffmpeg-php is a very useful php extension which provides several methods to query information on the uploaded media. if you are going to do media conversion , you have to know the frame size, frame rate,ect of the input file, and ffmpeg provides those facilities. What ffmpeg-php does is, it provides an PHP interface to ffmpeg tool.

Installing ffmpeg-php is trivial. But make sure you have FFMPEG properly installed , please read the previous post for that.

Download the source code from

http://sourceforge.net/project/showfiles.php?group_id=122353&package_id=133626

Untar the file and then…

phpize

./configure --enable-ffmpeg-php --with-ffmpeg-php --enable-maintainer-zts --enable-debug --with-php-config=/usr/local/php/bin/php-config

Note that –enable-maintainer-zts –enable-debug –with-php-config=/usr/local/php/bin/php-config

A few options were required to ensure this extension complies with the PHP installation i have. so you might not need those.

make
make install

Then…

vi /usr/local/php/php.ini
cp /usr/local/php/lib/php/extensions/debug-zts-20060613/ffmpeg.so /usr/local/php/lib/php/extensions/
apache stopp
apache start
php -r 'phpinfo();' | grep ffmpeg
you should see
ffmpeg
ffmpeg support (ffmpeg-php) => enabled
ffmpeg-php version => 0.5.0
ffmpeg.allow_persistent => 0 => 0

php -f ext/ffmpeg-php-0.5.0/tests/test_ffmpeg.php

You should get a page with various info with ffmpeg and ffmpeg formats,ect. You can do further tests by using the media provided by ffmpeg-php source.

The Final step - finding a cool player

You now need a cool video player, we recomend this one:

JW FLV PLAYER 3.12

Resources (sources of above info) This is where we got it all

First do this:

http://stuphi.co.uk/wordpress/?page_id=43

Then…

http://po-ru.com/diary/bleeding-edge-ffmpeg-on-ubuntu-feisty/

Then…

http://r4vi.org/index.html/?q=node/41

Also look at…

http://stuphi.co.uk/wordpress/?p=23

http://po-ru.com/diary/fixing-ffmpeg-on-ubuntu/

Share this post: Share this post with the world.
  • Muti
  • GoGuide
  • Facebook
  • del.icio.us
  • Digg
  • Reddit
  • StumbleUpon
  • Technorati
By admin / Nov 19th, 2007 / Category: