在linux环境安装FFmpeg的时候,常常有直接使用命令无法顺利安装的情况。 在alpine的容器下可以简单的用apk add 来进行FFmpeg和ffmpeg-dev的安装。 但是如果在ubuntu环境下直接使用apt-get常常会有各种问题。 这里是完整的在ubuntu环境下编译安装FFmpeg的流程。
- 安装相关依赖
apt-get update
apt-get install build-essential autoconf automake libtool pkg-config \
libavcodec-dev libavformat-dev libavutil-dev \
libswscale-dev libresample-dev libavdevice-dev \
libopus-dev libvpx-dev libx264-dev libx265-dev \
yasm wget vim
- 编译安装FFmpeg
cd ~
mkdir ffmpeg
cd ffmpeg
wget https://ffmpeg.org/releases/ffmpeg-5.0.2.tar.bz2
tar xjvf ffmpeg-5.0.2.tar.bz2
cd ffmpeg-5.0.2
./configure --prefix=/usr/local/ffmpeg --enable-shared --disable-static \
--enable-gpl --enable-libx264 --enable-libx265 --enable-libopus --enable-libvpx
make -j$(nproc)
make install
安装之后在/usr/local/ffmpeg/bin 下执行ffmpeg时可能会报错
./ffmpeg: error while loading shared libraries: libavdevice.so.59: cannot open shared object file: No such file or directory
这个时候修改/etc/ld.so.conf文件,添加/usr/local/ffmpeg/lib, 路径编译时prefix的路径下的lib,然后执行
ldconfig
这时候FFmpeg就应该正常安装了。
ffmpeg version 5.0.2 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
configuration: --prefix=/usr/local/ffmpeg --enable-shared --enable-gpl --enable-libx264 --enable-libx265 --enable-libopus --enable-libvpx
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
Hyper fast Audio and Video encoder