centos5.3安装ffmpeg 流媒体环境

1. 创建一个目录ffmpeg

mkdir ffmpeg
cd ffmpeg

2. 下载以下源文件

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

3. 解压下载的源文件

bunzip2 essential-20061022.tar.bz2; tar xvf essential-20061022.tar
tar zxvf flvtool2_1.0.5_rc6.tgz
tar zxvf lame-3.97.tar.gz
bunzip2 ffmpeg-php-0.5.0.tbz2; tar xvf ffmpeg-php-0.5.0.tar
tar zxvf libogg-1.1.3.tar.gz
tar zxvf libvorbis-1.1.2.tar.gz

4. 创建解码器目录并移动源文件至该目录

mkdir /usr/local/lib/codecs/
mv essential-20061022/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/

5. 安装svn,ruby等,便于同步取得最新程序 (如果有安装,可不用重复安装)

yum install subversion
yum install ruby
yum install ncurses-devel

6. svn下载最新版本的FFMPEG/MPlayer源程序

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer

#以下编译

7. Compile LAME

cd ~/ffmpeg/lame-3.97
./configure
make
make install

8. Compile libOGG

cd ~/ffmpeg/libogg-1.1.3
./configure
make
make install

9. Compile libVorbis

cd ~/ffmpeg/libvorbis-1.1.2
./configure
make
make install

10. Compile flvtool2

cd ~/ffmpeg/flvtool2_1.0.5_rc6
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

11. Compile MPlayer

cd ~/ffmpeg/mplayer
./configure
make
make install

12. Compile FFMPEG

cd ~/ffmpeg/ffmpeg
./configure --enable-libmp3lame --enable-libogg --enable-libvorbis --disable-mmx --enable-shared
echo '#define HAVE_LRINTF 1' >> config.h

#(编译安装ffmpeg , 我使用的以下这些参数,根据自己的环境,修改增减参数,实际上我的这些参数中有部分也是需要下载源码编译的。如libx264 ,faac等我在做这件事最先就执行操作了yum -install ffmpeg ,而做完后ffmpeg不工作,总是提示我软链出了问题,google 了一下,有网友遇到了我同样的问题,这个问题出现在centos5.3或rhel5的版本中,解决办法就是推翻重做)

#./configure --enable-gpl --enable-postproc --enable-nonfree --enable-postproc --enable-libfaad --enable-avfilter --enable-pthreads --enable-libxvid --enable-libx264 --enable-libmp3lame --enable-libfaac --disable-ffserver --disable-ffplay
make
make install

#到此ffmpeg编译完成,以下13-17项可以做,也可不做,与php结合看各自需要,我没有做,偷懒~,做完后,更新动态链接库

#echo "/usr/local/lib" >> /etc/ld.so.conf
#echo "/usr/lib" >> /etc/ld.so.conf
#ldconfig

13. Finalize the codec setups (软链可以做)

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

14. Compile FFMPEG-PHP

cd ~/ffmpeg/ ffmpeg-php-0.5.0
phpize
./configure
make
make install

15. Install FFMPEG-PHP (make sure the php.ini path is correct.)

echo 'extension=/usr/local/lib/php/extensions/ no-debug-non-zts-20020429/ffmpeg.so' >> /usr/local/Zend/etc/php.ini

16. Restart Apache to load FFMPEG-PHP (Depends on OS, this is for RHEL/CentOS)

service httpd restart

17. Verify if it works

php -r 'phpinfo();' | grep ffmpeg

If you get a few lines such as

ffmpeg
ffmpeg support (ffmpeg-php) => enabled
ffmpeg-php version => 0.5.0
ffmpeg.allow_persistent => 0 => 0

Then everything is installed and working. FFMPEG, FFMPEG-PHP, MPlayer, MEncoder, flv2tool, LAME MP3 encoder & libOGG.

点赞