Wednesday, January 16, 2008

Set up ffmpeg Streaming Server

To setup a streaming server first you need ffmpeg installed in the server . Not only that you need associated software’s installed to and you need to custom compile to make the server a complete streaming server . you need ffpeg-php also .
ffmpeg-php is a PHP extension that adds functions for accessing and retrieving information from movies and audio files. ffmpeg-php provides access to the many audio and video formats supported by ffmpeg.


First we can try the easy way . using yum . You can download the repository of rpmforge from http://dag.wieers.com/rpm/ . then
yum install ffmpeg
This will install ffmpeg . But for a complete streaming setup it is always better to compile and install fmpeg with all the necessary modules to give support for most of the extensions .

Login to your server as root, then:
cd /usr/src && mkdir install && cd install
Download faad2 and faac
from http://faac.sourceforge.net/oldsite/download.php get Faad2 and faac (new versions)

wget http://prdownloads.sourceforge.net/faac/faad2-2.0.tar.gz?download
wget http://prdownloads.sourceforge.net/faac/faac-1.24.tar.gz?download

Verify that you have these components are installed
rpm -qa automake
rpm -qa autoconf
rpm -qa libtool
rpm -qa m4
rpm -qa gcc-c++

If any are missing than simply yum install (packagename), if you dont have a package
manager than get one, it will save you alot of time
and headaches.

Installing Faac
tar -zxvf faac-1.24.tar.gz && cd faac
sh bootstrap
./configure
make
make install
cd ..

Installing Faad2
tar -zxvf faad2-2.0.tar.gz
cd faad2 && less README.linux
There is 2 bugs with this package, so need to manually edit these files
nano Makefile.am
Edit the file to look like this
SUBDIRS = libfaad common frontend plugins
EXTRA_DIST = faad2.spec

cd common/mp4ff && nano mp4ffint.h
Comment out this line
//void mp4ff_track_add(mp4ff_t *f);

Save file and cd ../..
autoreconf -vif
./configure
make
make install
Then
# cd /usr/local/src

Download the sources to your server:
# wget http://www3.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2
# wget http://rubyforge.org/frs/download.php/9225/flvtool2_1.0.5_rc6.tgz
# wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
# wget http://superb-west.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.0.tbz2
# wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
# wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
Extract all sources:
# tar -xzf flvtool2_1.0.5_rc6.tgz
# tar -xzf lame-3.97.tar.gz
# tar -xzf libogg-1.1.3.tar.gz
# tar -xzf libvorbis-1.1.2.tar.gz
# tar -xjf essential-20061022.tar.bz2
# tar -xjf ffmpeg-php-0.5.0.tbz2
Create new directory:
# mkdir /usr/local/lib/codecs/
We need to install SVN and Ruby On Rails:
# up2date -i subversion
# up2date -i ruby
# svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
# svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
# cd /usr/local/src/mplayer
# svn update
Copy Codecs for MPlayer:
# mv /usr/local/src/essential-20061022/* /usr/local/lib/codecs/
# chmod -R 755 /usr/local/lib/codecs/
Secure folder TMP:
# mkdir /usr/local/src/tmp
# chmod 777 /usr/local/src/tmp
# export TMPDIR=/usr/local/src/tmp
Lame:
# cd /usr/local/src/lame-3.97
# ./configure
# make && make install

LibOgg:
# cd /usr/local/src/libogg-1.1.3
# ./configure && make && make install
LibVorbis:
# cd /usr/local/src/libvorbis-1.1.2
# ./configure && make && make install
FlvTool2:
# cd /usr/local/src/flvtool2_1.0.5_rc6/
# ruby setup.rb config
# ruby setup.rb setup
# ruby setup.rb install
MPlayer:
# cd /usr/local/src/mplayer
# ./configure && make && make install
FFMpeg:
# cd /usr/local/src/ffmpeg/
# ./configure –enable-libmp3lame –enable-libogg –enable-libvorbis –disable-mmx –enable-shared –enable-faad –enable-faac –enable-a52
# echo ‘#define HAVE_LRINTF 1 ‘>>config.h
# make
# make install
# ln -s /usr/local/lib/libavformat.so.50 /usr/lib/libavformat.so.50
# ln -s /usr/local/lib/libavcodec.so.51 /usr/lib/libavcodec.so.51
# ln -s /usr/local/lib/libavutil.so.49 /usr/lib/libavutil.so.49
# ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
# ln -s /usr/local/lib/libavformat.so.51 /usr/lib/libavformat.so.51
# cd /usr/local/src/
FFMpeg-PHP:
# cd /usr/local/src/ffmpeg-php-0.5.0/
# phpize
# ./configures
# make
# make install
Now the check the php version . I will give sample here.

# echo ‘extension=/usr/local/lib/php/extensions/no-debug-non-zts-20020429/ffmpeg.so’ >> /usr/local/Zend/etc/php.ini
# service httpd restart
This will most probably setup us a streaming server. You will get lots off errors if everything doesn’t go correctly. Then we should troubleshoot till everything goes right . Based on the server we may need to enable and disable shared for it to work. Sometimes if you get vhook error you can try disabling that and try again and so on.

There is a script for installing ffmpeg in the server . Please check this link http://www.cihilt.com/ffmpeg_installation_in_5min

No comments: