Shifted My Blog

Hi,I have shifted my blog to so please check out my latest posts at

Tuesday, May 01, 2007

Building a video sharing site.

Videos are the best way to express. With the popularity of sites like Youtube, Google Video, Jumpcut and lot other we see a beginning of online video sharing/editing Era.

Eg: YouTube,Google Video ,Jumpcut ,Grouper ,Revver ,vsocial,vimeo , Videoegg

With all these big players around it is difficult for any other site to come and compete. Innovation is the key to success. If you can put something extra that is really different and innovative - who knows, your site can leave YouTube and other big sites behind. So here I am explaining you how to build a basic video sharing site.

How does a video share site work?

A video sharing site perform three basic tasks

  1. Allows a user to upload video files.
  2. Convert the uploaded files to a common format that can be played on a browser (generally the format is flash video FLV)
  3. Embed a player in your site to view the video.

I . Uploading Video files.

You will find lots of open source application for file uploading available on web. You can use any of them .I have used “Uber Uploader” and it is really good .It has got AJAX Progress Bar which show you how much file is uploaded.

You can down load the file from

Note : To use this script you should have CGI-BIN Access enabled.

II .Converting the Uploaded video to Flv format.

The uploaded file needs to be converted to FLV format. To convert video file to FLV format you need additional packages installed to your linux server.

You need to install:-

GD Library 2 or higher,
FFmpeg, Mplayer + Mencoder ,
Flv2tool, Libogg + Libvorbis,
LAME MP3 Encoder

PHP Configuration:
safe_mode = off
register_globals = on (recommended)
open_basedir = (no value)
output_buffering = on
upload_max_filesize = 100M )
post_max_size = 100M

You can install the above package using YUM (recommended). The packages are available in DAG repository, so you need to add DAG repository to yum.

After you have installed the packages you just need to run few commands through php using exec command.

Following is the command to convert video file to FLV.

Note : check the path of mencoder using whereis command( whereis mencoder ) and if it is not '/usr/bin/mencoder ' then change it with the correct path in the command below.

exec("/usr/bin/mencoder testvideo.mpeg -o testvideo.flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=800:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -srate 22050");

You need to file Meta data using this command

Note : check the path of flvtool2

exec("/usr/bin/flvtool2 -Uv testvideo.flv newvideo.flv");

You can even create thumbnails by the following command

Note : check the path of mplayer

exec("/usr/bin/mplayer testvideo.mpeg -ss 1 -nosound -vo jpeg:outdir=./thumb -frames 2");

III .Embed a player in you site to view the video:-

Once you have created the FLV file the only task that is left is to display the video, for that you need an FLV player. So we need to find and download a FLV player.

Here is a link to a free FLV player Download.(

Note: But read the license before you use.

Now embed the player and specify the FLV file path.