在CentOS上编译安装FFmpeg
技术支持服务电话:15308000360 【7x24提供运维服务,解决各类系统/软硬件疑难技术问题】
在CentOS编译安装ffmpeg比较麻烦,以前也搞过多次,由于博客调整,特重新记录一下,以备不时之需。
若此篇文章还不能解决您的问题,请联系QQ:38585404 (有偿技术支持)
使用yum安装ffmpeg和相关软件
快速安装 ffmpeg 直接安装:
yum install ffmpeg ffmpeg-devel若没有找到相应包,需要先加入要应的包。
将下列代码命名为
dag.repo
放在 /etc/yum.repos.d
目录 下。
[dag] name=Dag RPM Repository for Red Hat Enterprise Linux baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag gpgcheck=1 enabled=1然后再执行上方的安装命令。 安装 ffmpeg-php 扩展
wget /path/to/this/file/ffmpeg-php-0.5.2.1.tbz2 tar -xjf ffmpeg-0.5.2.1.tbz2 phpize ./configure make make install修改 php.ini 文件 安装完成后
将会在
/usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so
看到php扩展文件。
打开
php.ini
文件,加入下面两行[ffmpeg] extension=ffmpeg.so重启WEB服务器。使用phpinfo即可看到ffmpeg相关信息。
php 使用方法
$extension = "ffmpeg"; $extension_soname = $extension . "." . PHP_SHLIB_SUFFIX; $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname; // load extension if(!extension_loaded($extension)) { dl($extension_soname) or die("Can't load extension $extension_fullname\n"); } ?>安装 Mplayer 和 Mencoder
yum install mplayer mencoder常见问题
常见问题及解决方案请参考这里:http://www.mysql-apache-php.com/ffmpeg-install.htm
自行编译安装 ffmpeg
安装依赖项
yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel安装相应软件包
可以建立目录存放软件包
mkdir ~/ffmpeg_sources注意:以下软件包请有选择的安装,如果不需要请在
./configure
时移除或关闭相关选项安装 yasm
Yasm是一个完全重写的NASM汇编。目前,它支持x86和AMD64指令集。 x264 和 FFmpeg都使用Yasm.
cd ~/ffmpeg_sources git clone --depth 1 git://github.com/yasm/yasm.git cd yasm autoreconf -fiv ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" make make install make distclean或
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz tar zxf yasm-1.3.0.tar.gz cd yasm-1.3.0 ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" make make install make distclean . ~/.bash_profile安装 x264 H.264 编码器。http://trac.ffmpeg.org/wiki/Encode/H.264
cd ~/ffmpeg_sources git clone --depth 1 git://git.videolan.org/x264 cd x264 ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" --enable-static make make install make distclean或
wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2 tar jxf last_x264.tar.bz2 cd x264-snapshot-20130311-2245/ ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" --enable-shared make make install make distclean需要
ffmpeg
配置./configure --enable-gpl --enable-libx264
注:由于libx264的code有GPL信息,所以,支持libx264时,需要—enable-gpl,ffmpeg在license方面还是比我们国内的人更重视
安装 x265
H.265/HEVC编码器.http://trac.ffmpeg.org/wiki/Encode/H.265
cd ~/ffmpeg_sources hg clone https://bitbucket.org/multicoreware/x265 cd ~/ffmpeg_sources/x265/build/linux cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/usr/local/ffmpeg" -DENABLE_SHARED:bool=off ../../source make make install或
cd ~/ffmpeg_sources wget https://bitbucket.org/multicoreware/x265/downloads/x265_1.9.tar.gz cd ~/ffmpeg_sources/x265 cmake ./source -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/usr/local/ffmpeg" -DENABLE_SHARED:bool=off make make install需要
ffmpeg
配置./configure --enable-gpl --enable-libx265
安装 libfdk_aac
AAC音频编码器,Fraunhofer AAC library
cd ~/ffmpeg_sources git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac cd fdk-aac autoreconf -fiv ./configure --prefix="/usr/local/ffmpeg" --enable-shared make make install make distclean需要
ffmpeg
配置--enable-libfdk_aac
,如果指定了--enable-gpl
还要配置--enable-nonfree
安装 libmp3lame
Mp3音频编码器
wget http://iweb.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz tar zxf lame-3.99.5.tar.gz cd lame-3.99.5 ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" --enable-shared --enable-nasm make make install make distclean需要
ffmpeg
配置--enable-libmp3lame
安装 libopus Opus
音频编解码器
cd ~/ffmpeg_sources git clone git://git.opus-codec.org/opus.git cd opus autoreconf -fiv ./configure --prefix="/usr/local/ffmpeg" --disable-shared make make install make distclean或
wget http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz tar zxf opus-1.0.3.tar.gz cd opus-1.0.3 ./configure --prefix="/usr/local/ffmpeg" --enable-shared make make install make distclean需要
ffmpeg
配置--enable-libopus
安装 libogg库
libogg是Ogg流库,libtheora、libvorbis需要libogg库,speex需要它。
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz tar xzvf libogg-1.3.2.tar.gz cd libogg-1.3.2 CFLAGS="-fPIC" ./configure --prefix="/usr/local/ffmpeg" --disable-shared make make install make distclean安装 libvorbis库
Vorbis音频编码器,需要libogg库。http://trac.ffmpeg.org/wiki/CompilationGuide/Centos#libogg
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz tar xzvf libvorbis-1.3.4.tar.gz cd libvorbis-1.3.4 LDFLAGS="-L/usr/local/ffmpeg/lib" CPPFLAGS="-I/usr/local/ffmpeg/include" ./configure --prefix="/usr/local/ffmpeg" --with-ogg="/usr/local/ffmpeg" --disable-shared make make install make distclean需要
ffmpeg
配置--enable-libvorbis
安装 libvpx
VP8/VP9视频编码器
cd ~/ffmpeg_sources git clone --depth 1 http://git.chromium.org/webm/libvpx.git cd libvpx ./configure --prefix="/usr/local/ffmpeg" --enable-examples make make install make clean需要
ffmpeg
配置--enable-libvpx
安装 libfaac
ACC音频编码器
wget http://ncu.dl.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz tar zxf faac-1.28.tar.gz cd faac-1.28 ./bootstrap ./configure --prefix=/usr/local/ffmpeg --with-mp4v2 --enable-shared make make install make distclean需要
ffmpeg
配置--enable-libfaac
make时可能会出现如下错误:
In file included from mp4common.h:29:0,from 3gp.cpp:28: mpeg4ip.h:126:58: error: new declaration ‘char* strcasestr(const char*, const char*)’ /usr/include/string.h:369:28: error: ambiguates old declaration ‘const char* strcasestr(const char*, const char*)’ make[3]: *** [3gp.o] Error 1 make[3]: Leaving directory `/usr/local/pc/ffmpeg/faac-1.28/common/mp4v2' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/usr/local/pc/ffmpeg/faac-1.28/common' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/usr/local/pc/ffmpeg/faac-1.28' make: *** [all] Error 2解决方法: 先执行:
make clean修改源文件:
vim common/mp4v2/mpeg4ip.h找到这句:
char *strcasestr(const char *haystack, const char *needle);
把这一行注释掉,在前面加 // 重新继续编译:
make make install
开始编译安装 ffmpeg
cd ~/ffmpeg_sources git clone --depth 1 git://source.ffmpeg.org/ffmpeg cd ffmpeg PKG_CONFIG_PATH="/usr/local/ffmpeg/lib/pkgconfig" ./configure --prefix="/usr/local/ffmpeg" --extra-cflags="-I/usr/local/ffmpeg/include" --extra-ldflags="-L/usr/local/ffmpeg/lib" --bindir="/usr/local/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libx264 --enable-libx265 --enable-libfaac --enable-libvpx make make install make distclean hash -r注: 编译完成后
ffmpeg
,ffprobe
,ffserver
,lame
,x264
都可以使用。编译安装时可以参考Windows Build:http://ffmpeg.zeranoe.com/builds/
如果还需要持续更新请保留
ffmpeg_sources
目录。编辑/etc/ld.so.conf文件加入如下内容
/usr/local/lib
/usr/local/ffmpeg/lib
保存退出后执行ldconfig命令
/usr/local/ffmpeg/lib
保存退出后执行ldconfig命令
其它可选软件包
安装 OpenCORE AMR
wget http://iweb.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz tar zxf opencore-amr-0.1.3.tar.gz ./configure --prefix="/usr/local/ffmpeg" –enable-shared make make install需要
ffmpeg
配置--enable-libopencore-amrnb
和/或 --enable-libopencore-amrwb
安装 VisualOn AAC
注:github的tag和master版均无法autoconf,用zeranoe版代替
wget wget http://ffmpeg.zeranoe.com/builds/source/external_libraries/vo-aacenc-0.1.3.tar.xz xz -d vo-aacenc-0.1.3.tar.xz tar xf vo-aacenc-0.1.3.tar cd vo-aacenc-0.1.3 ./configure --prefix="/usr/local/ffmpeg" make make install也可
wget http://iweb.dl.sourceforge.net/project/opencore-amr/vo-aacenc/vo-aacenc-0.1.3.tar.gz需要
ffmpeg
配置--enable-libvo-aacenc
安装 VisualOn AMR-WB
注:github的tag和master版均无法autoconf,用zeranoe版代替
wget http://ffmpeg.zeranoe.com/builds/source/external_libraries/vo-amrwbenc-0.1.2.tar.xz xz -d vo-amrwbenc-0.1.2.tar.xz tar xf vo-amrwbenc-0.1.2.tar cd vo-amrwbenc-0.1.2 ./configure --prefix="/usr/local/ffmpeg"需要
ffmpeg
配置--enable-libvo-amrwbenc
安装 frei0r
先安装新版autoconf,这会覆盖掉系统中的旧版本哦
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz tar zxf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure --prefix="/usr/local/ffmpeg" make make install
wget http://files.dyne.org/frei0r/releases/frei0r-plugins-1.4.tar.gz tar zxf frei0r-plugins-1.4.tar.gz cd frei0r-plugins-1.4 ./configure --prefix="/usr/local/ffmpeg" make make install安装 gnutls
注意:/etc/ld.so.conf要加上lib64。并且不要使用yum remove gnutls gnutls-devel 首先安装nettle:
wget http://www.lysator.liu.se/~nisse/archive/nettle-2.5.tar.gz tar zxf nettle-2.5.tar.gz cd nettle-2.5 ./configure --prefix="/usr/local/ffmpeg" –enable-shared make make install然后安装gnutls新版:
wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.9.1.tar.xz xz -d gnutls-3.1.9.1.tar.xz tar xf gnutls-3.1.9.1.tar cd gnutls-3.1.9.1 PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure –enable-shared make make install安装 rtmpdump
wget http://rtmpdump.mplayerhq.hu/download/rtmpdump-2.3.tgz tar zxf rtmpdump-2.3.tgz cd rtmpdump-2.3 make make install
安装 schroedinger
注:先安装好orc库
wget http://code.entropywave.com/download/orc/orc-0.4.17.tar.gz tar zxf orc-0.4.17.tar.gz cd orc-0.4.17 ./configure --prefix="/usr/local/ffmpeg" make make install /sbin/ldconfig
wget http://diracvideo.org/download/schroedinger/schroedinger-1.0.11.tar.gz tar zxf schroedinger-1.0.11.tar.gz cd schroedinger-1.0.11 PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure make make install安装 soxr
注:新版libsoxr貌似与当前ffmpeg不兼容,用旧版
yum install -y xz wget http://hivelocity.dl.sourceforge.net/project/soxr/soxr-0.1.0-Source.tar.xz xz -d soxr-0.1.0-Source.tar.xz tar xf soxr-0.1.0-Source.tar cd soxr-0.1.0-Source ./go cd Release/ make make install /sbin/ldconfig安装 speex
音频编码解码器。需要安装libogg库
yum install speex-devel或
wget http://downloads.xiph.org/releases/speex/speex-1.2rc1.tar.gz tar zxf speex-1.2rc1.tar.gz cd speex-1.2rc1 ./configure --prefix="/usr/local/ffmpeg" make make installffmpeg
./configure
添加 --enable-libspeex
安装 libfreetype
字体呈现库,使用
drawtext
http://ffmpeg.org/ffmpeg-filters.html#drawtext-1
yum install freetype-develffmpeg
./configure
添加 --enable-libfreetype
安装 libsdl库
wget http://www.libsdl.org/release/SDL-1.2.15.tar.gz tar zxf SDL-1.2.15.tar.gz cd SDL-1.2.15 ./configure --prefix="/usr/local/ffmpeg" make make install /sbin/ldconfig安装 theora
Theora视频编码器,需要需要libogg,libvorbis和libsdl库
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2 tar zjf libtheora-1.1.1.tar.bz2 ./configure --prefix="/usr/local/ffmpeg" --with-ogg="/usr/local/ffmpeg" --disable-examples --enable-shared --disable-sdltest --disable-vorbistest make make install make distcleanffmpeg
./configure
添加 --enable-libtheora
安装 twolame
wget http://downloads.sourceforge.net/twolame/twolame-0.3.13.tar.gz tar zxf twolame-0.3.13 .tar.gz cd twolame-0.3.13 ./configure --prefix="/usr/local/ffmpeg" make make install /sbin/ldconfig安装 xvid
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz tar zxf xvidcore-1.3.2.tar.gz cd xvidcore cd build/generic ./configure --prefix="/usr/local/ffmpeg" make make install更新FFmpeg及相关组件
更新依赖项
删除旧文件,更新依赖项
rm -rf ~/ffmpeg_build ~/bin/{ffmpeg,ffprobe,ffserver,lame,vsyasm,x264,yasm,ytasm} # yum install autoconf automake cmake gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel更新 x264
cd ~/ffmpeg_sources/x264 make distclean git pull然后运行
./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" --enable-static make make install make distclean更新 x265
cd ~/ffmpeg_sources/x265 rm -rf ~/ffmpeg_sources/x265/build/linux/* hg update cd ~/ffmpeg_sources/x265/build/linux然后运行
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/usr/local/ffmpeg" -DENABLE_SHARED:bool=off ../../source make make install更新 libfdk_aac
cd ~/ffmpeg_sources/libfdk_aac make distclean git pull然后运行
cd fdk-aac autoreconf -fiv ./configure --prefix="/usr/local/ffmpeg" --disable-shared make make install make distclean更新 libvpx
cd ~/ffmpeg_sources/libvpx make clean git pull然后运行
cd libvpx ./configure --prefix="/usr/local/ffmpeg" --disable-examples make make install make clean更新FFmpeg
cd ~/ffmpeg_sources/ffmpeg make distclean git pull然后运行
cd ffmpeg PKG_CONFIG_PATH="/usr/local/ffmpeg/lib/pkgconfig" ./configure --prefix="/usr/local/ffmpeg" --extra-cflags="-I/usr/local/ffmpeg/include" --extra-ldflags="-L/usr/local/ffmpeg/lib" --bindir="/usr/local/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 make make install make distclean hash -r还原所有本文安装内容
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffserver,lame,vsyasm,x264,yasm,ytasm} # yum erase autoconf automake cmake gcc gcc-c++ git libtool mercurial nasm pkgconfig zlib-devel hash -r注:如安装其它软件包需要自行删除
自动安装shell
https://gist.github.com/gboudreau/f24aed76b4cc91bfb2c1
#!/bin/sh # Based on instructions found here: http://wiki.razuna.com/display/ecp/FFMpeg+Installation+on+CentOS+and+RedHat#FFMpegInstallationonCentOSandRedHat-InstallX264 if [ "`/usr/bin/whoami`" != "root" ]; then echo "You need to execute this script as root." exit 1 fi cat > /etc/yum.repos.d/centos.repo< [centos] name=CentOS-6 – Base baseurl=http://mirror.centos.org/centos/6/os/x86_64/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 enabled=1 priority=1 protect=1 includepkgs=SDL SDL-devel gsm gsm-devel libtheora theora-tools libdc1394 libdc1394-devel libraw1394-devel EOF rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 rpm -Uhv http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm yum -y update yum -y install glibc gcc gcc-c++ autoconf automake libtool git make nasm pkgconfig yum -y install SDL-devel a52dec a52dec-devel alsa-lib-devel faac faac-devel faad2 faad2-devel yum -y install freetype-devel giflib gsm gsm-devel imlib2 imlib2-devel lame lame-devel libICE-devel libSM-devel libX11-devel yum -y install libXau-devel libXdmcp-devel libXext-devel libXrandr-devel libXrender-devel libXt-devel yum -y install libogg libvorbis vorbis-tools mesa-libGL-devel mesa-libGLU-devel xorg-x11-proto-devel zlib-devel yum -y install libtheora theora-tools yum -y install ncurses-devel yum -y install libdc1394 libdc1394-devel yum -y install amrnb-devel amrwb-devel opencore-amr-devel cd /opt wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz tar xzvf xvidcore-1.3.2.tar.gz && rm -f xvidcore-1.3.2.tar.gz cd xvidcore/build/generic ./configure --prefix="/usr/local/ffmpeg" && make && make install cd /opt wget http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz tar xzvf libogg-1.3.1.tar.gz && rm -f libogg-1.3.1.tar.gz cd libogg-1.3.1 ./configure --prefix="/usr/local/ffmpeg" --disable-shared && make && make install cd /opt wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz tar xzvf libvorbis-1.3.4.tar.gz && rm -f libvorbis-1.3.4.tar.gz cd libvorbis-1.3.4 ./configure --prefix="/usr/local/ffmpeg" --with-ogg="/usr/local/ffmpeg" --disable-shared && make && make install cd /opt wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz tar xzvf libtheora-1.1.1.tar.gz && rm -f libtheora-1.1.1.tar.gz cd libtheora-1.1.1 ./configure --prefix="/usr/local/ffmpeg" --with-ogg="/usr/local/ffmpeg" --disable-examples --disable-shared --disable-sdltest --disable-vorbistest && make && make install cd /opt wget http://downloads.sourceforge.net/opencore-amr/vo-aacenc-0.1.2.tar.gz tar xzvf vo-aacenc-0.1.2.tar.gz && rm -f vo-aacenc-0.1.2.tar.gz cd vo-aacenc-0.1.2 ./configure --prefix="/usr/local/ffmpeg" --disable-shared && make install yum -y remove yasm cd /opt wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz tar xzfv yasm-1.2.0.tar.gz && rm -f yasm-1.2.0.tar.gz cd yasm-1.2.0 ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" && make install export "PATH=$PATH:/usr/local/bin" cd /opt git clone http://git.chromium.org/webm/libvpx.git cd libvpx git checkout tags/v1.3.0 ./configure --prefix="/usr/local/ffmpeg" --disable-examples && make && make install cd /opt git clone git://git.videolan.org/x264.git cd x264 ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" --enable-static && make install export LD_LIBRARY_PATH=/usr/local/lib/:/usr/local/ffmpeg/lib/ echo /usr/local/lib >> /etc/ld.so.conf.d/custom-libs.conf echo /usr/local/ffmpeg/lib/ >> /etc/ld.so.conf.d/custom-libs.conf ldconfig cd /opt git clone git://source.ffmpeg.org/ffmpeg.git cd ffmpeg git checkout release/2.2 PKG_CONFIG_PATH="/usr/local/ffmpeg/lib/pkgconfig" export PKG_CONFIG_PATH ./configure --prefix="/usr/local/ffmpeg" --extra-cflags="-I/usr/local/ffmpeg/include" --extra-ldflags="-L/usr/local/ffmpeg/lib" --bindir="/usr/local/bin" \ --extra-libs=-ldl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx --enable-libfaac \ --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libvo-aacenc --enable-libxvid --disable-ffplay \ --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --arch=x86_64 && make install # Test the resulting ffmpeg binary cp /usr/local/bin/ffmpeg /usr/bin/ ffmpeg -vgit clone --depth 1 http://chromium.googlesource.com/webm/libvpx.git