下载ffmpeg源码
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
切换分支
查看远程分支,切换release版本最新的分支到本地,为了稳定,编译少bug,选择release版本的
git branch -a
git checkout -b remotes/origin/release/5.0
安装环境
sudo apt-get update -qq && sudo apt-get -y install \
autoconf \
automake \
build-essential \
cmake \
git-core \
libass-dev \
libfreetype6-dev \
libsdl2-dev \
libtool \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
pkg-config \
texinfo \
wget \
zlib1g-dev
sudo apt-get install nasm
sudo apt-get install yasm
安装libx264
H.264 video encoder
启用需要 configured 配置 —enable-gpl —enable-libx264sudo apt-get install libx264-dev -y
安装libx265
H.265/HEVC video encodersudo apt-get install libx265-dev libnuma-dev -y
安装libvpx
VP8/VP9 video encoder/decoder
启用需要 configured 配置 —enable-libvpxsudo apt-get install libvpx-dev -y
libfdk-aac
AAC audio encoder.
Requires ffmpeg to be configured with —enable-libfdk-aac (and —enable-nonfree if you also included —enable-gpl)sudo apt-get install libfdk-aac-dev -y
libmp3lame
MP3 audio encoder.
Requires ffmpeg to be configured with —enable-libmp3lamesudo apt-get install libmp3lame-dev -y
libopus
Opus audio decoder and encoder.
Requires ffmpeg to be configured with —enable-libopussudo apt-get install libopus-dev -y
libaom
AV1 video encoder/decoder:
手动安装在ffmpeg_build文件夹下,也可以收到下载release版本编译安装git -C aom pull 2> /dev/null || git clone --depth 1 https://aomedia.googlesource.com/aom && \
mkdir aom_build && \
cd aom_build && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom && \
PATH="$HOME/bin:$PATH" make && \
make install
配置configure
生成静态库,动态库, 安装到相对目录./bin文件下./configure --prefix=./bin --enable-static --enable-shared
配置&&编译&&安装
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--extra-libs="-lpthread -lm" \
--bindir="$HOME/bin" \
--enable-gpl \
--disable-libaom \
--enable-libass \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvorbis \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-shared \
--enable-nonfree && \
PATH="$HOME/bin:$PATH" make -j 8 && \
make install && \
hash -r
最终可执行文件安装到了bin目录下,库文件安装到了ffmpeg_build下
- 使用时需要配置的环境变量
#export PATH=/usr/local/ffmpeg/bin:$PATH # 指定可执行程序路径
export LD_LIBRARY_PATH=/root/ffmpeg_build/lib:$LD_LIBRARY_PATH # 指定程序链接时查找的路径
export LIBRARY_PATH=/root/ffmpeg_build/lib:$LIBRARY_PATH # 程序编译时查找的路径
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/root/ffmpeg_build/include # 指定 gcc 头文件查找路径
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/root/ffmpeg_build/include # 指定 g++ 头文件查找路径