1 安装x264相关库
如果x264在编译安装时提示错误: 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编译参数包含 --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
为防止出现找不到 libfreetype 的错误,首先修改 PKG_CONFIG_PATH 环境变量:
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
如果报错 No package 'uuid' found 则按如下步骤解决:
yum -y install libuuid-devel
如果报错 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
#######重要事项#######
extra-cflags 和 extra-ldflags 两个参数不指定对应路径会一直报这个错误,花了挺长时间来找解决方法,还是挺郁闷的,希望看到的朋友不要再走弯路了。
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环境下使用了。
8 php通过exec调用ffmpeg如出现权限问题或以下错误:
error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No such file or directory
解决方法:
vi /etc/ld.so.conf
文件中添加以下内容:
include ld.so.conf.d/*.conf
include /usr/local/lib
/usr/local/ffmpeg3.4/lib
/usr/local/x264/lib
执行ldconfig命令进行更新路径:
ldconfig
网友评论