CentOS下安裝FFmpeg

1.安裝依賴包

  1. 安裝autoconf
cd /root/source
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
  1. 安裝automake
cd /root/source
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
  1. 安裝libtool(FAAC需要)
cd /root/source
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
  1. 安裝yasm支持匯編優(yōu)化(FFmpeg需要)
cd /root/source
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
  1. 安裝MP3支持庫(kù)LAME
cd /root/source
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
  1. 安裝AAC支持庫(kù)FAAC
    make時(shí)報(bào)錯(cuò):mpeg4ip.h:126: 錯(cuò)誤:對(duì)‘char* strcasestr(const char, const char)’的新聲明
    需要修改common/mp4v2/mpeg4ip.h第123行至129行內(nèi)容:
#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 /root/source
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內(nèi)容
make
make install
主要提示:可能受限于FFmpeg版本的緣故,安裝了AAC庫(kù),在ffmpeg-3.2.4版本下編譯ffmpeg,使用--enable-libfaac選項(xiàng)時(shí),會(huì)報(bào)找不到libfaac錯(cuò)誤。百度了一番,看了FFmpeg的WiKi百科,發(fā)現(xiàn)它使用libfdk-aac庫(kù)替代libfaac庫(kù),安裝后測(cè)試果然解決問題。
cd /root/source
wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
tar xzvf fdk-aac.tar.gz
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --disable-shared --with-pic
#--with-pic 很重要,一定要帶上,不然在編譯FFmpeg時(shí)會(huì)報(bào)錯(cuò)
make
make install
  1. 安裝AMR支持庫(kù)opencore-amr
cd /root/source
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
  1. 安裝通用音樂音頻編碼格式支持庫(kù)libvorbis
支持庫(kù)libvorbis需要依賴libogg,先安裝libogg庫(kù)
cd /root/source
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
再安裝libvorbis庫(kù)
cd /root/source
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
  1. 安裝x264庫(kù)支持H.264視頻轉(zhuǎn)碼
cd /root/source
git clone git://git.videolan.org/x264.git
cd x264
./configure --enable-shared
make
make install
  1. 安裝Xvid庫(kù)支持MPEG-4轉(zhuǎn)碼
cd /root/source
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
  1. 安裝Theora視頻壓縮支持庫(kù)
cd /root/source
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
  1. 安裝NUT支持庫(kù)
該軟件需要用svn獲取源代碼,svn可以直接用yum install svn來裝。

安裝時(shí)64位Linux系統(tǒng)需要修改文件config.mak

# 在最后一個(gè)CFLAGS下一行增加:
CFLAGS += -fPIC

否則安裝FFmpeg make時(shí)報(bào)錯(cuò):

/usr/local/lib/libnut.a: could not read symbols: Bad value
cd /root/source
svn co svn://svn.mplayerhq.hu/nut/src/trunk libnut
cd libnut
./configure
#configure后修改上述的config.mak
make
make install
  1. 安裝VP8/VP9編解碼支持庫(kù)
cd /root/source
#git clone http://git.chromium.org/webm/libvpx.git
#直接獲取比較好,沒裝git
wget -O libvpx.zip https://codeload.github.com/webmproject/libvpx/zip/master
unzip libvpx.zip
cd libvpx
./configure --enable-shared
make
make install
  1. 安裝FFmpeg最新版
cd /root/source
wget http://ffmpeg.org/releases/ffmpeg-3.2.4.tar.bz2
tar xvf ffmpeg-3.2.4.tar.bz2
cd ffmpeg-3.2.4
#老版本的--enable-libfaac,已替換為--enable-libfdk-aac
./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
#若出現(xiàn)下述錯(cuò)誤,在此修改config.mak文件,然后再make,切記別重新configure
make install

若make的時(shí)候,報(bào)以下錯(cuò)誤

/usr/bin/ld: libavcodec/mqc.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
libavcodec/mqc.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

解決方法是:

#config.mak L75加入 -fPIC,然后重新編譯
#直接替換,順序可能不一樣
HOSTCFLAGS=-O3 -g -std=c99 -Wall -fPIC
  1. 添加動(dòng)態(tài)鏈接庫(kù)配置
echo '/usr/local/lib' >> /etc/ld.so.conf.d/local.conf
#更新緩存
ldconfig
安裝到這里就大功告成啦,一路安裝真心不容易,查看下版本:
[root@localhost djnj]# ffmpeg -version
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
configuration: --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
libavutil      55. 34.101 / 55. 34.101
libavcodec     57. 64.101 / 57. 64.101
libavformat    57. 56.101 / 57. 56.101
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100

看到這個(gè)滿滿的幸福和成就感。


參考文檔:

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容