Linux系统安装ffmpeg

2024/7/15·1 views

Centos下没有找到编译好的ffmpeg软件包,所以手动编译,Ubuntu下可以直接使用apt install ffmpeg安装

编译安装

Download FFmpeg

shell 复制代码
./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-zlib --enable-bzlib --enable-libfdk-aac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-pic --enable-pthreads --enable-libdc1394 --enable-libass --enable-pic --enable-openssl --enable-libtwolame --enable-libspeex --enable-libfreetype --enable-libx264

常见错误

注意:文中TARGET_DIR 可以不要,默认/usr/loacal,以下错误均给出了在Centos上的解决办法,其他系统可以照葫芦画瓢

ERROR: libass >= 0.11.0 not found using pkg-config

shell 复制代码
yum -y install libass*  # 安装所有libsass包
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

ERROR: libdc1394-2 not found using pkg-config

shell 复制代码
yum -y install libdc1394-devel.x86_64

ERROR: libfdk_aac not found

libfdk_aac官网下载: https://sourceforge.net/projects/opencore-amr/files/fdk-aac/

shell 复制代码
./autogen.sh
./configure CC=$(CC) --prefix=$(TARGET_DIR)
make
make install

如果你的--prefix未指定到/usr/localldconfig -p 中不能检索到libfdk-aac),那么需要在ffmpeg configure阶段使用--extra-cflags--extra-ldflags来指定你编出来的fdk_aac库在哪里:

shell 复制代码
./configure xxxxxxxxxxxxxxxxxxxxxxx --extra-cflags=-I$(TARGET_DIR)/include --extra-ldflags=-L$(TARGET_DIR)/lib/

或者添加ldconfig路径 (未测试)

ERROR: libmp3lame >= 3.98.3 not found

libmp3lame官网下载: https://sourceforge.net/projects/lame/files/lame/

shell 复制代码
./configure CC=$(CC) --prefix=$(TARGET_DIR);    
make;                                   
make install;

C compiler test failed.

shell 复制代码
yum install -y gcc

ERROR: speex not found using pkg-config

shell 复制代码
yum install -y speex-devel.x86_64

ERROR: libtheora not found

shell 复制代码
yum install -y libtheora-devel.x86_64

ERROR: libtwolame not found

源码下载地址:TwoLAME - Browse /twolame at SourceForge.net

shell 复制代码
./configure

make -j
make install

ERROR: vorbis not found using pkg-config

shell 复制代码
yum install -y libvorbis-devel.x86_64

ERROR: freetype2 not found using pkg-config

shell 复制代码
yum install freetype-devel.x86_64

ERROR: libx264 not found

shell 复制代码
git clone https://code.videolan.org/videolan/x264.git
./configure --prefix=$(TARGET_DIR) --enable-shared --enable-static --disable-asm
make
make install

ERROR: x265 not found using pkg-config

需要安装x265库,并且指定ffmpeg x265 pkgconfig的位置在哪。

shell 复制代码
git clone http://hg.videolan.org/x265
cmake source -DCMAKE_INSTALL_PREFIX=$(TARGET_DIR) -DCMAKE_PREFIX_PATH=$(TARGET_DIR)
make CC=$(CC) CFLAGS=$(CFLAGS)
make install
export PKG_CONFIG_PATH=$(TARGET_DIR)/lib/pkgconfig:$PKG_CONFIG_PATH

ffmpeg: error while loading shared libraries: libavdevice.so.60: cannot open shared object file: No such file or directory

有两种解决办法,第一种添加ffmpeg安装后的lib目录到ld.so.conf.d中

shell 复制代码
vim /etc/ld.so.conf.d/ffmpeg.conf

将路径添加进去,例如configure的时候指定的--prefix=/usr/local/ffmpeg,就里面的内容就是/usr/local/ffmpeg/lib

第二种使用ldd /usr/local/ffmpeg/bin/ffmpeg 查看缺失的库

复制代码
ldd /usr/local/ffmpeg/bin/ffmpeg | grep libavdevice # 可以查看到 libavdevice.so.60是not found
find /usr -name 'libavdevice.so.60' #查找下路径,例如/usr/local/ffmpeg/lib
export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib/ # 设置环境变量
快来和小猫聊天吧~