linux缺少libx264库的解决办法
最近在编译安装ffmpeg 的时候报了系统没有安装libx264等问题,故以此笔记加以记录。
安装 libx264
在编译安装libx264时,报了缺少nasm,需要先安装nasm。
安装 nasm
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz --no-check-certificate
tar -zxvf nasm-2.14.tar.gz
./configure
make && make install
#添加PATH 至/etc/profile
export PATH=$PATH:/usr/local/bin
source /etc/profile
安装x264
git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --enable-shared
## --enable-shared 参数需要带上,不然只有安装x264命令而没有生成相关lib 库文件
make && make install
ffmpeg 重新编译安装
wget http://www.ffmpeg.org/releases/ffmpeg-5.0.1.tar.gz
tar -zxvf ffmpeg-5.0.1.tar.gz
cd ffmpeg-5.0.1
./configure --enable-shared --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/usr/local/ffmpeg --enable-postproc --enable-pthreads --enable-static --enable-libx264
make && make install
# 测试是否成功
ffmpeg -y -i /ffmpeg-5.0.1/6_16_3.dav -c:v libx264 -crf 24 output-file.mp4
报错处理
error while loading shared libraries: libavdevice.so.59: cannot open shared object file: No such file or directory
相关库文件没有加载上,编辑/etc/ld.so.conf 添加相关库文件的目录
cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/ffmpeg/lib/
/usr/local/lib/
# /usr/local/ffmpeg/lib/ 是 ffmpeg 的编译目录
# /usr/local/lib/ 是x264的编译生成的库文件 ,没有指定的编译目录的生成配置都是系统默认的该目录下
#
ldconfig 加载生效