安装平台

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
             ............
.';;;;;. .,;,. ----------
.,;;;;;;;. ';;;;;;;. OS: Deepin 20 x86_64
.;::::::::' .,::;;,''''',. Model: 10SMCTO1WW ThinkCentre M920t-N000
,'.:::::::: .;;'. '; Kernel: 5.4.70-amd64-desktop
;' 'cccccc, ,' :: '.. .: Uptime: 4 days, 4 hours, 14 minutes
,, :ccccc. ;: .c, '' :. ,; Packages: 2561 (dpkg), 9 (snap)
.l. cllll' ., .lc :; .l' l. Shell: zsh 5.7.1
.c :lllc ;cl: .l' .ll. :' Resolution: 1920x1080
.l 'looc. . ,o: 'oo' c, DE: Deepin
.o. .:ool::coc' .ooo' o. WM: KWin
:: ..... .;dddo ;c Theme: deepin-dark [GTK2/3]
l:... .';lddddo. ,o Icons: Papirus [GTK3]
lxxxxxdoolllodxxxxxxxxxc :l Terminal: konsole
,dxxxxxxxxxxxxxxxxxxl. 'o, CPU: Intel i5-9500F (6) @ 4.400GHz
,dkkkkkkkkkkkkko;. .;o; GPU: AMD ATI Radeon HD 8570 / R7 240/340 / R520 OEM
.;okkkkkdl;. .,cl:. Memory: 4032MiB / 7836MiB
.,:cccccccc:,.

安装本体

ffmpeg-4.3.git
官网https://ffmpeg.org/

安装依赖

SDL

Simple DirectMedia Layer 是一个跨平台的开发库,旨在通过 OpenGL 和 Direct3D 提供对音频、键盘、鼠标、操纵杆和图形硬件的低级访问。它用于视频播放软件、模拟器和流行游戏。
SDL官网https://www.libsdl.org/

nasm

Netwide Assembler 是 x86 架构的汇编与反汇编工具。
如果在在 arm 等其他平台,交叉编译工具链中包含有对应的汇编器,则交叉编译 ffmpeg 时需要 --disable-x86asm 选项。
NASM 官网:https://www.nasm.us/

x264

x264 是开源的 h264 编码器。
ffmpeg 工程中实现了 h264 解码器,但无 h264 编码器。因此需要安装第三方编码器 x264
x264 官网https://www.videolan.org/developers/x264.html

x265

x265 是开源的 h265 编码器。
ffmpeg 工程中实现了 h265 解码器,但无 h265 编码器。因此需要安装第三方编码器 x265
x265 官网:http://www.x265.org/

libmp3lame

libmp3lame 是开源的 mp3 编码器。
libmp3lame 官网http://lame.sourceforge.net/

libopencore-amr

libopencore-amr 是开源 amr 编解码器
libopencore-amr 官网https://sourceforge.net/projects/opencore-amr/files/

编译安装过程

先安装上述依赖,一般优先apt install。如果源里没有则下载源码编译安装。

ffmpeg 不是使用 automake 等工具,而是自己编写的构建脚本。

  1. configure
    Configure 一方面用于检测 FFmpeg 的编译环境,另一方面根据用户配置的选项生成 config.mak,config.h 文件(可能还有 config.asm),提供给 Makefile 使用。FFmpeg 的 configure 脚本很复杂(一个 4000-5000 行的 Shell 脚本)。
1
2
3
4
5
6
7
8
9
10
11
./configure \
--prefix=PATH \
--enable-sdl \
--enable-gpl \
--enable-version3 \
--enable-libmp3lame \
--enable-debug \
--enable-libopencore-amrnb \
--enable-libopencore-amrwb \
--enable-libx265 \
--enable-libx264

--enable-gpl--enable-version3是 ffmpeg 中使用不同的链接动态库需要不同的开源协议支持。一般可以查询官网 wiki 或者脚本会提示需要指定开源协议版本。
./configure --help查看可用选项。其中 ffmpeg 也内置 fate 测试和检查工具等。
2. make
3. make install

测试

ffmpeg -v

1
2
3
4
5
6
7
8
9
10
11
12
13
ffmpeg version N-99648-g0c9cf6ea9a Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Uos 8.3.0.3-3+rebuild)
configuration: --prefix=/home/sun/.local --enable-sdl --enable-gpl --enable-version3 --disable-x86asm --enable-libmp3lame --enable-debug --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx265 --enable-libx264
libavutil 56. 60.100 / 56. 60.100
libavcodec 58.111.101 / 58.111.101
libavformat 58. 62.100 / 58. 62.100
libavdevice 58. 11.102 / 58. 11.102
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Missing argument for option 'v'.
Error splitting the argument list: Invalid argument

参考资料