一、安裝依賴
yum install git
yum -y install wget
yum install perl
yum install xz -y
yum install gcc-c++ libstdc++-devel
二、編譯安裝FFmpeg
yum安裝FFmpeg比源碼編譯安裝省時省力,但缺點也很明顯,版本過老,為0.6.5版,最新版已為2.6.3,新舊版很多參數有所差異,舊版支持的格式也沒有新版豐富。
源碼編譯安裝FFmpeg非常需要耐心,每添加一種需要支持的格式就需要有相應的多媒體格式開發庫。文中所使用的軟件版本皆為最新版。
1. 安裝autoconf
cd /App/src
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz
tar xvf autoconf-2.69.tar.xz
cd autoconf-2.69
./configure
make
make install
2. 安裝automake
cd /App/src
wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.xz
tar xvf automake-1.15.tar.xz
cd automake-1.15
./configure
make
make install
3. 安裝libtool(FAAC需要)
cd /App/src
wget http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.xz
tar xvf libtool-2.4.6.tar.xz
cd libtool-2.4.6
./configure
make
make install
4. 安裝yasm支持匯編優化(FFmpeg需要)
cd /App/src
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make
make install
5. 添加動態鏈接庫配置
echo '/usr/local/lib' >> /etc/ld.so.conf.d/local.conf
6. 安裝MP3支持庫LAME
cd /App/srccd
wget http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure
make
make install
7. 安裝AAC支持庫FAAC
make時報錯:mpeg4ip.h:126: 錯誤:對‘char* strcasestr(const char*, const char*)’的新聲明
需要修改faac-1.28/common/mp4v2/mpeg4ip.h第123行至129行內容:
#ifdef __cplusplus
extern "C" {
#endif
char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif
修改為:
#ifdef __cplusplus
extern "C++" {
#endif
const char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif
cd /App/src
wget http://jaist.dl.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.bz2
tar xvf faac-1.28.tar.bz2
cd faac-1.28
./bootstrap
./configure --with-mp4v2
#按前文修改mpeg4ip.h內容
make
make install
8. 安裝AMR支持庫opencore-amr
cd /App/src
wget http://jaist.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz
tar xvf opencore-amr-0.1.3.tar.gz
cd opencore-amr-0.1.3
./configure
make
make install
9. 安裝通用音樂音頻編碼格式支持庫libvorbis
# libvorbis需要libogg,先安裝libogg庫
cd /App/src
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.xz
tar xvf libogg-1.3.2.tar.xz
cd libogg-1.3.2
./configure
make
make install
cd /App/src
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.xz
tar xvf libvorbis-1.3.5.tar.xz
cd libvorbis-1.3.5
./configure
make
make install
10. 安裝x264庫支持H.264視頻轉碼
cd /App/src
git clone git://git.videolan.org/x264.git
cd x264
./configure --enable-shared
出現下列錯誤: Found no assembler
Minimum version is nasm-2.13
If you really want to compile without asm, configure with --disable-asm.
需安裝 nasm-2.13
tar -xvf nasm-2.13.tar.gz
cd nasm-2.13
./configure --prefix=/usr --enable-shared
make
make install
重新配置 x264
./configure --prefix=/usr --enable-shared
make
make install
11. 安裝Xvid庫支持MPEG-4轉碼
cd /App/src
wget http://downloads.xvid.org/downloads/xvidcore-1.3.3.tar.bz2
tar xvf xvidcore-1.3.3.tar.bz2
cd xvidcore/build/generic
./configure
make
make install
12. 安裝Theora視頻壓縮支持庫
cd /App/src
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.xz
tar xvf libtheora-1.1.1.tar.xz
cd libtheora-1.1.1
./configure
make
make install
13. 安裝NUT支持庫
cd /App/src
安裝svn 命令:sudo yum install -y subversion
svn co svn://svn.mplayerhq.hu/nut/src/trunk libnut
cd libnut
安裝時64位Linux系統需要修改文件config.mak
在最后一個CFLAGS下一行增加:
CFLAGS += -fPIC
否則安裝FFmpeg make時報錯:
/usr/local/lib/libnut.a: could not read symbols: Bad value
make
make install
14. 安裝VP8/VP9編解碼支持庫
cd /App/src
wget -O libvpx.zip https://codeload.github.com/webmproject/libvpx/zip/master
unzip libvpx.zip
cd libvpx
./configure --enable-shared
make
make install
15. 安裝FFmpeg最新版
cd /App/src
wget http://ffmpeg.org/releases/ffmpeg-3.2.4.tar.bz2
tar xvf ffmpeg-3.2.4.tar.bz2
cd ffmpeg-3.2.4
./configure --enable-version3 --enable-libvpx --enable-libfdk-aac --enable-libmp3lame --enable-libvorbis --enable-libx264 --enable-libxvid --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --enable-libnut --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-shared
make
make install
echo '/usr/local/lib' >> /etc/ld.so.conf.d/local.conf
ldconfig
ffmpeg -version
16. 安裝segmenter
git clone https://github.com/johnf/m3u8-segmenter
cd m3u8-segmenter
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure
make
make install
ln -s /usr/local/bin/m3u8-segmenter /usr/local/bin/segmenter
三、 編譯安裝注意事項
1. 可能發現編譯FFmpeg或者其他支持庫時,即使相關的所有依賴也編譯安裝上了,仍然make報錯,主要的原因還是由於依賴的庫版本沖突,編譯時調用的是yum安裝時自動下載安裝的舊版本依賴庫。此時的方法就是卸掉所有yum安裝的舊版本FFmpeg和相關的依賴軟件包或者重新找台新的純凈的系統重新開始安裝,或者使用Ubuntu Server最新版,一般Ubuntu Server最新版FFmpeg版本還是比較新的,直接執行命令 sudo apt-get install ffmpeg會自動安裝FFmpeg和相關依賴。
2. 有愛專研的或者受制於手頭無多余機器的,只能老老實實得卸載舊軟件,從頭開始編譯安裝。如何去除舊版本yum安裝的相關軟件。我們可以借助yum deplist命令先找出所有相關軟件包,然后卸載除了公共軟件包外的所有軟件包。此方法也適用於安裝其它軟件時遇到類似同樣的問題。
yum deplist ffmpeg | grep -v ffmpeg | grep provider | awk '{print $2}' | sort -u
圖示:
wKiom1VfUsKAHheVAAH5IKViZcU955.jpg
從中挑出非公共軟件包的軟件包名卸載:
rpm -e --nodeps a52dec dirac dirac-libs faac gsm lame libtheora opencore-amr SDL x264
rpm -e --nodeps $(rpm -qa | grep -i ffmpeg)
四、參考鏈接
http://www.centoscn.com/image-text/install/2015/0523/5512.html
http://www.jianshu.com/p/99a80aa9a2d0