1 安裝x264相關(guān)庫
如果x264在編譯安裝時(shí)提示錯(cuò)誤: Minimum version is nasm-2.13堡妒,則需要先安裝nasm:
wget "http://www.nasm.us/pub/nasm/releasebuilds/2.13.01/nasm-2.13.01.tar.xz"
tar xvf nasm-2.13.01.tar.xz
cd nasm-2.13.01
./configure
make&make install
安裝 x264
wget "https://download.videolan.org/pub/videolan/x264/snapshots/last_stable_x264.tar.bz2"
tar xvf last_stable_x264.tar.bz2
cd x264-snapshot-20180607-2245-stable/
./configure --prefix=/usr/local/x264 --enable-shared --enable-static
make&make install
2 安裝 libfreetype
如果ffmpeg編譯參數(shù)包含 --enable-libass 則需要先安裝 libfreetype fribidi fontconfig libass
wget "https://download.savannah.gnu.org/releases/freetype/freetype-2.9.1.tar.gz"
tar zxvf freetype-2.9.1.tar.gz
cd freetype-2.9.1/
./configure --prefix=/usr/local --disable-static
make
make install
3 安裝 fribidi
wget "https://github.com/fribidi/fribidi/releases/download/v1.0.4/fribidi-1.0.4.tar.bz2"
tar xf fribidi-1.0.4.tar.bz2
cd fribidi-1.0.4
./configure --prefix=/usr/local/ --enable-shared
make
make install
4 安裝 fontconfig
為防止出現(xiàn)找不到 libfreetype 的錯(cuò)誤配乱,首先修改 PKG_CONFIG_PATH 環(huán)境變量:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
wget "https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.13.0.tar.gz"
tar zxvf fontconfig-2.13.0.tar.gz
cd fontconfig-2.13.0
./configure --prefix=/usr/local/ --enable-shared --enable-libxml2
make
make install
如果報(bào)錯(cuò) No package 'uuid' found 則按如下步驟解決:
yum -y install libuuid-devel
如果報(bào)錯(cuò) WARNING: 'gperf' is missing on your system. 則按如下步驟解決:
wget http://mirrors.ustc.edu.cn/gnu/gperf/gperf-3.1.tar.gz
tar zxvf gperf-3.1.tar.gz
cd gperf-3.1
./configure
make
make install
5 安裝 libass
wget https://github.com/libass/libass/releases/download/0.14.0/libass-0.14.0.tar.xz
tar xvf libass-0.14.0.tar.xz
cd libass-0.14.0
./configure --prefix=/usr/local/ --disable-static
make
make install
6 安裝 ffmpeg
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
wget "http://ffmpeg.org/releases/ffmpeg-3.4.tar.bz2"
tar xvf ffmpeg-3.4.tar.bz2
cd ffmpeg-3.4
./configure --prefix=/usr/local/ffmpeg3.4/ --enable-shared --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/x264/include --extra-ldflags=-L/usr/local/x264/lib --enable-libass
make
make install
#######重要事項(xiàng)#######
extra-cflags 和 extra-ldflags 兩個(gè)參數(shù)不指定對應(yīng)路徑會一直報(bào)這個(gè)錯(cuò)誤,花了挺長時(shí)間來找解決方法,還是挺郁悶的搬泥,希望看到的朋友不要再走彎路了桑寨。
libavcodec/libavcodec.so: undefined reference to `x264_encoder_open_152'
7 編譯完成后,在 /etc/profile 文件下增加如下字段:
FFMPEG=/usr/local/ffmpeg3.4
X264=/usr/local/x264
export FFMPEG X264
export PATH=$PATH:$FFMPEG/bin:$X264/bin
export LD_LIBRARY_PATH=$X264/lib:$FFMPEG/lib:$LD_LIBRARY_PATH
這樣ffmpeg就能在linux環(huán)境下使用了忿檩。
8 php通過exec調(diào)用ffmpeg如出現(xiàn)權(quán)限問題或以下錯(cuò)誤:
error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No such file or directory
解決方法:
vi /etc/ld.so.conf
文件中添加以下內(nèi)容:
include ld.so.conf.d/*.conf
include /usr/local/lib
/usr/local/ffmpeg3.4/lib
/usr/local/x264/lib
執(zhí)行l(wèi)dconfig命令進(jìn)行更新路徑:
ldconfig