ubuntu下编译ffmpeg

Ubuntu下编译ffmpeg

官网指导:https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

下载源代码
1
git clone https://git.ffmpeg.org/gitweb/ffmpeg.git
切换分支

查看远程分支,切换release版本最新的分支到本地,为了稳定,编译少bug,选择release版本的

1
2
git branch -a
git checkout -b remotes/origin/release/4.1

在当前目录创建个bin文件夹,最为编译安装文件夹

1
mkdir bin
安装环境
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
1
2
sudo apt-get install nasm
sudo apt-get install yasm
安装libx264

H.264 video encoder
启用需要 configured 配置 –enable-gpl –enable-libx264

1
sudo apt-get install libx264-dev -y

安装libx265

H.265/HEVC video encoder.

1
sudo apt-get install libx265-dev libnuma-dev -y

安装libvpx

VP8/VP9 video encoder/decoder
启用需要 configured 配置 –enable-libvpx

1
sudo 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)

1
sudo apt-get install libfdk-aac-dev -y

libmp3lame

MP3 audio encoder.
Requires ffmpeg to be configured with –enable-libmp3lame.

1
sudo apt-get install libmp3lame-dev -y

libopus

Opus audio decoder and encoder.
Requires ffmpeg to be configured with –enable-libopus.

1
sudo apt-get install libopus-dev -y

libaom
AV1 video encoder/decoder:
手动安装在ffmpeg_build文件夹下,也可以收到下载release版本编译安装

1
2
3
4
5
6
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文件下

1
./configure --prefix=./bin--enable-static --enable-shared

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
编译并安装
1
2
3
4
#-j 8 多个编译一起执行,加快变异速度。多线程?多核处理?
make -j 8
#安装
make install

在bin文件夹中lib有生成的静态库和动态库

1
2
3
4
5
6
7
8
9
10
11
root@ubuntu:/home/hx/Downloads/ffmpeg/bin/lib# ls
libavcodec.a libavfilter.so.7 libswresample.a
libavcodec.so libavfilter.so.7.40.101 libswresample.so
libavcodec.so.58 libavformat.a libswresample.so.3
libavcodec.so.58.35.100 libavformat.so libswresample.so.3.3.100
libavdevice.a libavformat.so.58 libswscale.a
libavdevice.so libavformat.so.58.20.100 libswscale.so
libavdevice.so.58 libavutil.a libswscale.so.5
libavdevice.so.58.5.100 libavutil.so libswscale.so.5.3.100
libavfilter.a libavutil.so.56 pkgconfig
libavfilter.so libavutil.so.56.22.100