linux上安装ffmpeg
服务器是从腾讯云租的,centos7.9
默认安装没有带libx264库,导致修改视频后很模糊。
先安装 libx264 库:
wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
tar -xvf x264-master
cd x264-master
./configure --enable-shared
make && make install
默认会安装到 /usr/local/ 位置。
继续安装 ffmpeg:
wget https://ffmpeg.org/releases/ffmpeg-6.0.tar.xz
tar -xvf ffmpeg-6.0.tar.xz
cd ffmpeg-6.0
./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264
make && make install
把ffmpeg加到环境变量中:
vi /etc/profile
# 在最后PATH添加环境变量:
export PATH=$PATH:/usr/local/ffmpeg/bin
:wq
# 设置生效
source /etc/profile
// 出错,需要先安装 nasm/yasm not found or too old. Use –disable-x86asm for a crippled build.
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install
// 出错:ERROR: x264 not found using pkg-config
错误提示 x264 not found using pkg-config
表明在使用 pkg-config
时未能找到 libx264
。
- 确保
libx264
已经安装。你可以通过pkg-config --list-all | grep x264
来检查libx264
是否已经被pkg-config
找到。 - 如果
libx264
已经安装,但是pkg-config
未能找到,可能是因为pkg-config
的搜索路径没有包括libx264
的安装路径。你可以通过设置PKG_CONFIG_PATH
环境变量来添加额外的搜索路径。比如,如果libx264
安装在/usr/local/lib
,你可以运行:export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
// 出错:ffmpeg: error while loading shared libraries: libx264.so.164: cannot open shared object file: No such file or directory
- 确认
libx264.so.164
是否真的存在。你可以使用find
命令来查找这个文件:find / -name 'libx264.so.164'
- 如果
libx264.so.164
不存在,可能是因为你的libx264
库版本过低或过高。你需要安装正确版本的libx264
。你可以从 x264 官方网站 下载正确版本的源码,然后编译安装。 - 如果
libx264.so.164
存在,但是ffmpeg
无法找到,可能是因为动态库搜索路径(由LD_LIBRARY_PATH
环境变量和/etc/ld.so.conf
文件定义)没有包含libx264.so.164
所在的目录。你可以通过以下命令添加动态库搜索路径:export LD_LIBRARY_PATH=/usr/local/lib/libx264.so.164:$LD_LIBRARY_PATH
,然后再运行ffmpeg
。 - 在修改了动态库搜索路径后,你需要运行
ldconfig
命令来更新动态库缓存:sudo ldconfig
然后再运行ffmpeg
。