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/

By admin / Nov 19th, 2007 / Category:

16 Responses

  1. Hello webmaster…Man i just love your blog, keep the cool posts comin..holy Monday

  2. Nice tut man, keep up the good work.

  3. Y but Google pay for the bandwidth on youTube & that suits me fine ;) Besides - you can access the flv’s with a little trickery !


  4. Great point!

    This type of setup is only relevant to specialized startups and established sites trying to take their online assets one step further. For small or even medium sized sites this would be a little overkill.

    Either way, it’s a great thing to have on your CV ;-)

  5. This is Morten Ryum, over at Simplex Media. I just wanted to thank you for leaving a comment. My first impression of your site was: “elite blogger”. Great skin, great posts, keep up the great work!


  6. Thanks a mill Morten!

  7. Thanks Admin you are great

  8. Great blog. However is it possible for the user to record an audio through a microphone and upload to the server? Any help would be appreciated.

  9. Can we expect a follow up to this? With actual PHP code that will do the conversions?


  10. Hi Sunil

    There are two options,

    Option A – The easy and most obvious one

    Recommend a good free audio capturing program (There are quite a few on the web) and then guide the user to a simple upload form, where the use a file select box to upload the file. This is the most commonly used method of getting audio on-line. You can use FFMpeg to change the format and quality of the audio.

    Option B – This is what you are looking for

    WAV Recording Applet SDK

    Click here - http://www.vimas.com/wav.php

    The WAV audio recording applet SDK is designed to create the web audio recorder on the web site. It allows to record the audio in WAV PCM/16bits/mono, WAV Mu-Law/ 8bits/mono, WAV A-Law/8bits/mono formats from the web site and upload audio file to the web server via HTTP. Also, it is possible to save recorded audio file on the client computer and open it from there.

    I would lean towards option A. It is simple to do, you can use an upload script from one of my previous articles “It’s time to look at the way you upload files”. Also, its always best to go with what a user is familiar with. Only time I would do something different, is when it’s a start up and the business is centered on the functionality, or if I’m doing it for fun.


  11. Hey Jason. Most definitely. We are planning a tutorial on how to upload videos, convert using FFMpeg and then finally playing the video. We will most probably supply source files as well!!!!

  12. im new to this but sounds really informative! will def be back

  13. hi there
    I found this on the web
    http://startyourtube.com
    it looks easy to me
    best
    jp

  14. Hi,
    Very nice tutorial ,Thanks.
    I have a requirement to record and video from an external device/camera(through online) and upload it to the server.is it possible by using ffmpeg?.

  15. Hi,
    We can even go one step further and create a clone of YouTube. All the scripts for that are easily findable on the internet. But doing the same thing as YouTube is not a solution to success. There is only one way for me. Do not try to do what has already been done by those better money-backed players. Find a niche! Targeting a niche, whether it is about a special subject or a community, is the key of success. This is already too hard to find videos about something that interest us within the millions hosted by YouTube. By focussing on a specific content, you will create a community of users of your own, with a place they will gladly share around them as it will rapidly be theirs.
    So what niche to choose? I have compiled a list of already 400 of YouTube-like sites with their niche on http://www.ilikesharingvideos.com/video-sharing-sites/en/
    If you’re interested in video sharing, you should give it an eye.
    Cheers

  16. Hey there, this is a free prebuilt php based youtube alike site that uses the FFMPEG technology. It’s totally free up to a certain point and is fully customizable. I just installed it on my localhost to have a fiddle with it and can say that it is such an awesome prebuilt internet app. http://www.phpmotion.com

Leave a Reply