转自:http://trac.ffmpeg.org/wiki/CentosCompilationGuide
【yasi】如果能用yum install ffmpeg-devel,就尽量不要用这里的源码build方式,除非yum install的版本太低了。yum install ffmpeg-devel 参考这里,有时yum install ffmpeg-devel会遇到下面的问题,请多试几次
Compile FFmpeg on CentOS 6.x
Contents
This guide is based on minimal CentOS and will provide a local, non-system installation of FFmpeg with several external encoding libraries. These instructions should also work for recent Red Hat Enterprise Linux (RHEL) and Fedora. This is a non-invasive guide and undoing all steps is simple and is shown at the end of this page.
Get the Dependencies
Note: The # indicates that the command should be executed as superuser or root.
Get the dependencies:
# yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel
Make a directory to put all of the source code into:
mkdir ~/ffmpeg_sources
Compilation & Installation
Note: If you do not require certain encoders you may skip the relevant section and then remove the appropriate ./configure option in FFmpeg. For example, if libvorbis is not needed, then skip that section and then remove --enable-libvorbis from the Install FFmpeg section.
【yasi】注意下面所有的库,如果是下载源码压缩包build的,最好先找到对应的最新版,然后更新对应的源代码下载命令
Yasm
Yasm is an assembler used by x264 and FFmpeg.
cd ~/ffmpeg_sources curl -O http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz tar xzvf yasm-1.2.0.tar.gz cd yasm-1.2.0 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" make make install make distclean . ~/.bash_profile
x264
H.264 video encoder.
cd ~/ffmpeg_sources git clone --depth 1 git://git.videolan.org/x264 cd x264 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-shared make make install make distclean
libfdk_aac
AAC audio encoder.
cd ~/ffmpeg_sources git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac cd fdk-aac autoreconf -fiv ./configure --prefix="$HOME/ffmpeg_build" --enable-shared make make install make distclean
libmp3lame
MP3 audio encoder.
cd ~/ffmpeg_sources curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz tar xzvf lame-3.99.5.tar.gz cd lame-3.99.5 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-shared --enable-nasm make make install make distclean
libopus
Opus audio decoder and encoder.
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz tar xzvf opus-1.0.3.tar.gz cd opus-1.0.3 ./configure --prefix="$HOME/ffmpeg_build" --enable-shared make make install make distclean
libogg
Ogg bitstream library. Required by libtheora and libvorbis.
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz tar xzvf libogg-1.3.1.tar.gz cd libogg-1.3.1 ./configure --prefix="$HOME/ffmpeg_build" --enable-shared make make install make distclean
libvorbis
Vorbis audio encoder. Requires libogg.
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz tar xzvf libvorbis-1.3.3.tar.gz cd libvorbis-1.3.3 ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --enable-shared make make install make distclean
libvpx
VP8/VP9 video encoder.
cd ~/ffmpeg_sources git clone --depth 1 http://git.chromium.org/webm/libvpx.git cd libvpx ./configure --prefix="$HOME/ffmpeg_build" --enable-examples make make install make clean
【yasi】做下面的FFmpeg操作之前,最好先做FFmpeg之后的几项操作(freetype、speex、threaro),并且在FFmpeg的./configure选项后面加上--enable-libspeex等配置项(如果需要这些库的话)。make FFmpeg库是一个及其漫长的过程哈,要有心理准备哦~~~
FFmpeg
cd ~/ffmpeg_sources git clone --depth 1 git://source.ffmpeg.org/ffmpeg cd ffmpeg PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" export PKG_CONFIG_PATH #./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --extra-libs="-ldl" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 ./configure --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --extra-libs="-ldl" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libtheora --enable-libfreetype --enable-libspeex --enable-shared make make install make distclean hash -r . ~/.bash_profile
Compilation is now complete and ffmpeg (also ffprobe, ffserver, lame, and x264) should now be ready to use. The rest of this guide shows how to update or remove FFmpeg.
Note: Keep the ffmpeg_sources directory and all contents if you intend to update or uninstall as shown below.
Additional Libraries
Other libraries codecs that you may require (but probably do not). These must be installed before you compile ffmpeg.
libfreetype
Font rendering library. Required for the drawtext video filter.
# yum install freetype-devel
Add --enable-libfreetype to your ffmpeg ./configure.
libspeex
Speex audio decoder and encoder.
# yum install speex-devel
Add --enable-libspeex to your ffmpeg ./configure.
libtheora
Theora video encoder. Requires libogg.
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz tar xzvf libtheora-1.1.1.tar.gz cd libtheora-1.1.1 ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-examples --enable-shared --disable-sdltest --disable-vorbistest make make install make distclean
Add --enable-libtheora to your ffmpeg ./configure.
Updating
Development of FFmpeg is active and an occasional update can give you new features and bug fixes. First, remove the old files and then update the dependencies:
rm -rf ~/ffmpeg_build ~/bin/{ffmpeg,ffprobe,ffserver,lame,vsyasm,x264,yasm,ytasm} # yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel
Update x264
cd ~/ffmpeg_sources/x264 make distclean git pull
Then run ./configure, make, and make install as shown in the Install x264 section.
Update libfdk_aac
cd ~/ffmpeg_sources/libfdk_aac make distclean git pull
Then run ./configure, make, and make install as shown in the Install libfdk_aac section.
Update libvpx
cd ~/ffmpeg_sources/libvpx make clean git pull
Then run ./configure, make, and make install as shown in the Install libvpx section.
Update FFmpeg
cd ~/ffmpeg_sources/ffmpeg make distclean git pull
Then run ./configure, make, and make install as shown in the Install FFmpeg section.
Reverting changes made by this guide
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffserver,lame,vsyasm,x264,yasm,ytasm} # yum erase autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel hash -r
If You Need Help
Feel free to ask your questions at the #ffmpeg IRC channel or the ffmpeg-user mailing list.
Also See
【yasi】注意,可能会遇到下面的情况:
在mremote中开了几个tab,都是同一台远程centos机器,在其中一个tab中做完了上面的所有步骤之后,执行下面的命令可以得到相应的结果:
[root@localhost vlc-2.1.1]# pkg-config --cflags libavutil
-I/usr/local/include
[root@localhost vlc-2.1.1]# pkg-config --libs libavutil
-L/usr/local/lib -lavutil
但是这时在另一个tab中,执行相同的命令,却得到空的结果,但实际上libavutil已经安装成功了。
解决方法:
假设libavutil默认安装时libavutil.pc安装到了 /usr/lib64/lib/pkgconfig/ 中,而 echo $PKG_CONFIG_PATH 结果中没有这个路径,这时要在当前tab中执行
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib64/lib/pkgconfig/ && export PKG_CONFIG_PATH
这样,pkg-config 命令就能找到先前安装的 libavutil 的 /usr/lib64/lib/pkgconfig/avutil.pc 文件了,从而 pkg-config 就能正确给出 libavutil 的 include 和 lib 信息了。