1.下载ffmpeg

1
2
wget http://www.ffmpeg.org/releases/ffmpeg-4.0.2.tar.bz2
tar -xjf ffmpeg-4.0.2.tar.bz2

2.编译选项说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# 保存选项到本地
./configure --help -> ffmpeg_help.txt

Help options:
–help print this message # 帮助选项
–quiet Suppress showing informative output # 信息输出显示
–list-decoders show all available decoders # 可用解码器
–list-encoders show all available encoders # 可用编码器
–list-hwaccels show all available hardware accelerators # 可用硬件编解码器
–list-demuxers show all available demuxers # 可用解复用
–list-muxers show all available muxers # 可用复用器
–list-parsers show all available parsers # 可用解析器
–list-protocols show all available protocols # 可用协议
–list-bsfs show all available bitstream filters # 可用比特流过滤器
–list-indevs show all available input devices # 可用输入设备
–list-outdevs show all available output devices # 可用输出设备
–list-filters show all available filters # 可用过滤器

#一般选项
Standard options:
–logfile=FILE log tests and output to FILE [config.log] # 生成指定的log文件
–disable-logging do not log configure debug information # 禁止调试信息
–fatal-warnings fail if any configure warning is generated # 任何警告则失败
–prefix=PREFIX install in PREFIX [$prefix_default] # 安装目录
–bindir=DIR install binaries in DIR [PREFIX/bin] # exe和dll安装目录
–datadir=DIR install data files in DIR [PREFIX/share/ffmpeg] # 数据安装目录
–docdir=DIR install documentation in DIR [PREFIX/share/doc/ffmpeg]# 文档安装目录 –libdir=DIR install libs in DIR [PREFIX/lib] # 静态库安装目录
–shlibdir=DIR install shared libs in DIR [LIBDIR] # 共享库安装目录
–incdir=DIR install includes in DIR [PREFIX/include] # 头文件安装目录
–mandir=DIR install man page in DIR [PREFIX/share/man] # 帮助文档安装目录
–pkgconfigdir=DIR install pkg-config files in DIR [LIBDIR/pkgconfig] # pkg- config安装目录
–enable-rpath use rpath to allow installing libraries in paths # 调用程序所用目录 not part of the dynamic linker search path
use rpath when linking programs (USE WITH CARE)
–install-name-dir=DIR Darwin directory name for installed targets

# 许可选项
Licensing options:
–enable-gpl allow use of GPL code, the resulting libs # 允许使用GPL
and binaries will be under GPL [no]
–enable-version3 upgrade (L)GPL to version 3 [no] # 更新GPL版本
–enable-nonfree allow use of nonfree code, the resulting libs # 允许使用非免费程序 and binaries will be unredistributable [no]

# 配置选项
Configuration options:
–disable-static do not build static libraries [no] # 禁止静态库
–enable-shared build shared libraries [no] # 启用共享库
–enable-small optimize for size instead of speed # 启用最小尺寸而非速度
–disable-runtime-cpudetect disable detecting CPU capabilities at runtime (smaller binary) # 禁用实时的CPU效率检测
–enable-gray enable full grayscale support (slower color) # 启用灰度(颜色、空间转换) –disable-swscale-alpha disable alpha channel support in swscale # 禁用swscale中的 透明度
–disable-all disable building components, libraries and programs # 禁用所有,包括组 件、库、程序
–enable-raise-major increase major version numbers in sonames [no] # 提升版本号

# 项目选项
Program options:
–disable-programs do not build command line programs # 禁止生成所有exe
–disable-ffmpeg disable ffmpeg build # 禁止生成ffmpeg.exe
–disable-ffplay disable ffplay build # 禁止生成ffplay.exe
–disable-ffprobe disable ffprobe build # 禁止生成ffprobe.exe
–disable-ffserver disable ffserver build # 禁止生成ffserver.exe

# 文档选项
Documentation options:
–disable-doc do not build documentation # 禁止生成doc文件
–disable-htmlpages do not build HTML documentation pages # 禁止生成HTML文档页
–disable-manpages do not build man documentation pages # 禁止生成帮助文档页
–disable-podpages do not build POD documentation pages # 禁止生成POD文档页
–disable-txtpages do not build text documentation pages # 禁止生成txt文档页

# 组件选项
Component options:
–disable-avdevice disable libavdevice build # 禁止libavdevice构造
–disable-avcodec disable libavcodec build # 禁止libavcodec构造
–disable-avformat disable libavformat build # 禁止libavformat构造
–disable-swresample disable libswresample build # 禁止libswresample构造
–disable-swscale disable libswscale build # 禁止libswscale构造
–disable-postproc disable libpostproc build # 禁止libpostproc构造
–disable-avfilter disable libavfilter build # 禁止libavfilter构造
–enable-avresample enable libavresample build [no] # 允许libavresample构造
–disable-pthreads disable pthreads [autodetect] # 禁止pthread构造
–disable-w32threads disable Win32 threads [autodetect] # 禁止使用win32线程
–disable-os2threads disable OS/2 threads [autodetect] # 禁止使用OS/2线程
–disable-network disable network support [no] # 禁止网络支持
–disable-dct disable DCT code # 禁止DCT代码
–disable-dwt disable DWT code # 禁止DWT代码
–disable-error-resilience disable error resilience code # 禁止纠错
–disable-lsp disable LSP code # 禁止行同步脉冲
–disable-lzo disable LZO decoder code # 禁止LZO压缩编码
–disable-mdct disable MDCT code # 禁止修正离散余弦变换
–disable-rdft disable RDFT code # 禁止实数离散傅里叶变换
–disable-fft disable FFT code # 禁止快速傅氏变换算法
–disable-faan disable floating point AAN (I)DCT code # 禁止AAN DCT变换
–disable-pixelutils disable pixel utils in libavutil # 禁用avutil中的像素单元

# 单个组件选项
Individual component options:
–disable-everything disable all components listed below # 禁用下面已列出的全部组件 –disable-encoder=NAME disable encoder NAME # 禁用指定的编码器
–enable-encoder=NAME enable encoder NAME # 启用指定的编码器
–disable-encoders disable all encoders # 禁用所有的编码器
–disable-decoder=NAME disable decoder NAME # 禁用指定的解码器
–enable-decoder=NAME enable decoder NAME # 启用指定的解码器
–disable-decoders disable all decoders # 禁用所有的解码器
–disable-hwaccel=NAME disable hwaccel NAME # 禁用指定的硬件加速
–enable-hwaccel=NAME enable hwaccel NAME # 启用指定的硬件加速
–disable-hwaccels disable all hwaccels # 禁用全部的硬件加速
–disable-muxer=NAME disable muxer NAME # 禁用指定的混合器
–enable-muxer=NAME enable muxer NAME # 启用指定的混合器
–disable-muxers disable all muxers # 禁用所有的混合器
–disable-demuxer=NAME disable demuxer NAME # 禁用指定的解复用器
–enable-demuxer=NAME enable demuxer NAME # 启用指定的解复用器
–disable-demuxers disable all demuxers # 禁用所有的解复用器
–enable-parser=NAME enable parser NAME # 启用指定的分析器
–disable-parser=NAME disable parser NAME # 禁用指定的分析器
–disable-parsers disable all parsers # 禁用所有的分析器
–enable-bsf=NAME enable bitstream filter NAME # 启用指定的流过滤器
–disable-bsf=NAME disable bitstream filter NAME # 禁用指定的流过滤器
–disable-bsfs disable all bitstream filters # 禁用所有的流过滤器
–enable-protocol=NAME enable protocol NAME # 启用指定的协议
–disable-protocol=NAME disable protocol NAME # 禁用指定的协议
–disable-protocols disable all protocols # 禁用所有的协议
–enable-indev=NAME enable input device NAME # 启用指定的输入设备
–disable-indev=NAME disable input device NAME # 禁用指定的输入设备
–disable-indevs disable input devices # 禁用输入设备
–enable-outdev=NAME enable output device NAME # 启用指定的输出设备
–disable-outdev=NAME disable output device NAME# 禁用指定的输出设备
–disable-outdevs disable output devices # 禁用输出设备
–disable-devices disable all devices # 禁用所有设备
–enable-filter=NAME enable filter NAME # 启用指定的过滤器
–disable-filter=NAME disable filter NAME # 禁用指定的过滤器
–disable-filters disable all filters # 禁用所有的过滤器

# 添加依赖库支持
External library support:
Using any of the following switches will allow FFmpeg to link to the corresponding external library. All the components depending on that library will become enabled, if all their other dependencies are met and they are not explicitly disabled. E.g. –enable-libwavpack will enable linking to libwavpack and allow the libwavpack encoder to be built, unless it is specifically disabled with –disable-encoder=libwavpack.
Note that only the system libraries are auto-detected. All the other external libraries must be explicitly enabled.
Also note that the following help text describes the purpose of the libraries themselves, not all their features will necessarily be usable by FFmpeg.
–enable-avisynth enable reading of AviSynth script files [no] # 启用读取AVISynth脚 本文件
–disable-bzlib disable bzlib [autodetect] # 启用bzlib
–enable-chromaprint enable audio fingerprinting with chromaprint [no] # 启用音频指 纹技术
–enable-frei0r enable frei0r video filtering [no] # 启用frei0r视频筛选
–enable-gcrypt enable gcrypt, needed for rtmp(t)e support # 启用加密
if openssl, librtmp or gmp is not used [no]
–enable-gmp enable gmp, needed for rtmp(t)e support # 启用gmp
if openssl or librtmp is not used [no]
–enable-gnutls enable gnutls, needed for https support # 启用gnutls
if openssl is not used [no]
–disable-iconv disable iconv [autodetect] # 禁用iconv
–enable-jni enable JNI support [no] # 启用JNI支持
–enable-ladspa enable LADSPA audio filtering [no] # 启用LADSPA音频过滤
–enable-libass enable libass subtitles rendering, # 启用libass
needed for subtitles and ass filter [no]
–enable-libbluray enable BluRay reading using libbluray [no] # 启用libbluray
–enable-libbs2b enable bs2b DSP library [no] # 启用bs2b DSP库
–enable-libcaca enable textual display using libcaca [no] # 启用libcaca用于文本显示 –enable-libcelt enable CELT decoding via libcelt [no] # 启用CEKT解码
–enable-libcdio enable audio CD grabbing with libcdio [no] # 通过libcdio启用音频CD –enable-libdc1394 enable IIDC-1394 grabbing using libdc1394 # 启用libdc1394
and libraw1394 [no]
–enable-libfdk-aac enable AAC de/encoding via libfdk-aac [no] # 启用libfdk-aac解 码/编码
–enable-libflite enable flite (voice synthesis) support via libflite [no] # 启用 libflite
–enable-libfontconfig enable libfontconfig, useful for drawtext filter [no] # 启 用libfontconfig
–enable-libfreetype enable libfreetype, needed for drawtext filter [no]# 启用 libfreetype
–enable-libfribidi enable libfribidi, improves drawtext filter [no] # 启用 libfribidi,改善绘画过滤
–enable-libgme enable Game Music Emu via libgme [no] # 启用libgme
–enable-libgsm enable GSM de/encoding via libgsm [no] # 启用libgsm做GSM编/解码
–enable-libiec61883 enable iec61883 via libiec61883 [no] # 启用libiec61883
–enable-libilbc enable iLBC de/encoding via libilbc [no] # 启用libilbc做iLBC编/解码 –enable-libkvazaar enable HEVC encoding via libkvazaar [no] # 启用libkvazaar做HEVC 编码
–enable-libmodplug enable ModPlug via libmodplug [no] # 启用ModPlug通过libmodplug –enable-libmp3lame enable MP3 encoding via libmp3lame [no] # 启用MP3编码通过
libmp3lame
–enable-libnut enable NUT (de)muxing via libnut, # 启用NUT解复用通过libnut
native (de)muxer exists [no]
–enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no] # 启用ARN-NB解/编码
–enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no] # 启 用ARM-WB解码
–enable-libopencv enable video filtering via libopencv [no] # 启用视频过滤通过 opencv
–enable-libopenh264 enable H.264 encoding via OpenH264 [no] # 启用H.264编码
–enable-libopenjpeg enable JPEG 2000 de/encoding via OpenJPEG [no] # 启用JPEG编解 码
–enable-libopenmpt enable decoding tracked files via libopenmpt [no] # 启用解码文件 通过libopenmpt
–enable-libopus enable Opus de/encoding via libopus [no] # 启用Oplus编解码
–enable-libpulse enable Pulseaudio input via libpulse [no] # 启用Pulse输入
–enable-librubberband enable rubberband needed for rubberband filter [no] # 启用 rubberband
–enable-librtmp enable RTMP[E] support via librtmp [no] # 启用RTMP支持通过librtmp –enable-libschroedinger enable Dirac de/encoding via libschroedinger [no] # 启用 Dirac编解码通过libschroedinger
–enable-libshine enable fixed-point MP3 encoding via libshine [no] # 启用libshine 固定MP3点
–enable-libsmbclient enable Samba protocol via libsmbclient [no] # 启用Samba协议 –enable-libsnappy enable Snappy compression, needed for hap encoding [no] # 启用 Snappy压缩
–enable-libsoxr enable Include libsoxr resampling [no] # 启用libsoxr采样
–enable-libspeex enable Speex de/encoding via libspeex [no] # 启用Speex编解码
–enable-libssh enable SFTP protocol via libssh [no] # 启用SFTP协议
–enable-libtesseract enable Tesseract, needed for ocr filter [no] # 启用Tesseract –enable-libtheora enable Theora encoding via libtheora [no] # 启用Theora编码
–enable-libtwolame enable MP2 encoding via libtwolame [no] # 启用MP2编码
–enable-libv4l2 enable libv4l2/v4l-utils [no] # 启用libv412
–enable-libvidstab enable video stabilization using vid.stab [no] # 启用 libvidstab
–enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no] # 启用AMR- WB
–enable-libvorbis enable Vorbis en/decoding via libvorbis, # 启用Vorbis编解码 native implementation exists [no]
–enable-libvpx enable VP8 and VP9 de/encoding via libvpx [no] # 启用VP8/VP9编解码 –enable-libwavpack enable wavpack encoding via libwavpack [no] # 启用wavpack编码 –enable-libwebp enable WebP encoding via libwebp [no] # 启用WbebP编码
–enable-libx264 enable H.264 encoding via x264 [no] # 启用H.264编码
–enable-libx265 enable HEVC encoding via x265 [no] # 启用HEVC编码
–enable-libxavs enable AVS encoding via xavs [no] # 启用AVS编码
–enable-libxcb enable X11 grabbing using XCB [autodetect] # 启用X11
–enable-libxcb-shm enable X11 grabbing shm communication [autodetect] # 启用X11 –enable-libxcb-xfixes enable X11 grabbing mouse rendering [autodetect] # 启用X11 –enable-libxcb-shape enable X11 grabbing shape rendering [autodetect] # 启用X11 –enable-libxvid enable Xvid encoding via xvidcore, # 启用Xvid编码
native MPEG-4/Xvid encoder exists [no]
–enable-libzimg enable z.lib, needed for zscale filter [no] # 启用z.lib
–enable-libzmq enable message passing via libzmq [no] # 启用消息传递通过libzmq
–enable-libzvbi enable teletext support via libzvbi [no] # 启用文本支持
–disable-lzma disable lzma [autodetect] # 禁用lzma
–enable-decklink enable Blackmagic DeckLink I/O support [no] # 启用阻塞IO支持
–enable-mediacodec enable Android MediaCodec support [no] # 启用安卓MediaCodec支持 –enable-netcdf enable NetCDF, needed for sofalizer filter [no] # 启用NetCDF
–enable-openal enable OpenAL 1.1 capture support [no] # 启用OpenAL1.1采集支持
–enable-opencl enable OpenCL code # 启用OpenCL代码
–enable-opengl enable OpenGL rendering [no] # 启用OpenGL
–enable-openssl enable openssl, needed for https support # 启用openssl,需支持https if gnutls is not used [no]
–disable-schannel disable SChannel SSP, needed for TLS support on # 启用SSP Windows if openssl and gnutls are not used [autodetect]
–disable-sdl2 disable sdl2 [autodetect] # 禁用sdl2
–disable-securetransport disable Secure Transport, needed for TLS support # 禁用安 全传输
on OSX if openssl and gnutls are not used [autodetect]
–disable-xlib disable xlib [autodetect] # 禁用xlib
–disable-zlib disable zlib [autodetect] # 禁用zlib
The following libraries provide various hardware acceleration features:
–disable-audiotoolbox disable Apple AudioToolbox code [autodetect] # 禁用苹果音频工 具箱
–disable-cuda disable dynamically linked Nvidia CUDA code [autodetect] # 禁用CUDA 编程
–disable-cuvid disable Nvidia CUVID support [autodetect] # 启用Nvidia CUVID
–disable-d3d11va disable Microsoft Direct3D 11 video acceleration code
[autodetect] # 禁用微软Direct3D 11视频加速
–disable-dxva2 disable Microsoft DirectX 9 video acceleration code [autodetect] # 禁用微软錎irectX视频加速
–enable-libmfx enable Intel MediaSDK (AKA Quick Sync Video) code via libmfx [no] # 启用Intel音频SDk
–enable-libnpp enable Nvidia Performance Primitives-based code [no] # 启用Nvidia性 能代码
–enable-mmal enable Broadcom Multi-Media Abstraction Layer (Raspberry Pi) via MMAL [no] # 启用网络多媒体结构层
–disable-nvenc disable Nvidia video encoding code [autodetect] # 禁用Nvidia视频编码 –enable-omx enable OpenMAX IL code [no] # 启用OpenMAX IL代码
–enable-omx-rpi enable OpenMAX IL code for Raspberry Pi [no] # 启用OpenMAX IL代码 –disable-vaapi disable Video Acceleration API (mainly Unix/Intel) code
[autodetect] # 禁用视频加速API
–disable-vda disable Apple Video Decode Acceleration code [autodetect] # 禁用苹果 视频解码加速代码
–disable-vdpau disable Nvidia Video Decode and Presentation API for Unix code
[autodetect] # 禁用Nvidia视频编码和表达API
–disable-videotoolbox disable VideoToolbox code [autodetect] # 禁用视频工具箱代码 编译工具选项
Toolchain options:
–arch=ARCH select architecture [$arch] # 选择架构
–cpu=CPU select the minimum required CPU (affects instruction selection, may crash on older CPUs) # 选择CPU
–cross-prefix=PREFIX use PREFIX for compilation tools [$cross_prefix] # 交叉编译工 具目录
–progs-suffix=SUFFIX program name suffix [] # 程序后缀名
–enable-cross-compile assume a cross-compiler is used # 启用交叉编译
–sysroot=PATH root of cross-build tree # 交叉编译根目录
–sysinclude=PATH location of cross-build system headers # 交叉编译头文件目录
–target-os=OS compiler targets OS [$target_os] # 交叉编译的目标系统
–target-exec=CMD command to run executables on target # 交叉编译启动程序命令
–target-path=DIR path to view of build directory on target # 交叉编译的安装目录
–target-samples=DIR path to samples directory on target # 交叉编译samples存放目录 –tempprefix=PATH force fixed dir/prefix instead of mktemp for checks # 交叉编译的 temp目录
–toolchain=NAME set tool defaults according to NAME # 编译工具
–nm=NM use nm tool NM [$nm_default]
–ar=AR use archive tool AR [$ar_default]
–as=AS use assembler AS [$as_default]
–ln_s=LN_S use symbolic link tool LN_S [$ln_s_default]
–strip=STRIP use strip tool STRIP [$strip_default]
–windres=WINDRES use windows resource compiler WINDRES [$windre_default]
–yasmexe=EXE use yasm-compatible assembler EXE [$yasmexe_default]# 使用yasm编译 –cc=CC use C compiler CC [$cc_default] # 使用gcc编译
–cxx=CXX use C compiler CXX [$cxx_default] # 使用g++编译
–objcc=OCC use ObjC compiler OCC [$cc_default] # 使用object C编译工具occ编译
–dep-cc=DEPCC use dependency generator DEPCC [$cc_default] # 使用依赖生成DEPCC
–ld=LD use linker LD [$ld_default] # 使用连接LD
–pkg-config=PKGCONFIG use pkg-config tool PKGCONFIG [$pkg_config_default] # 使用 pkg-config工具
–pkg-config-flags=FLAGS pass additional flags to pkgconf [] # 传递额外标志到pkg- config
–ranlib=RANLIB use ranlib RANLIB [$ranlib_default] # 使用RANLIB
–doxygen=DOXYGEN use DOXYGEN to generate API doc [$doxygen_default] # 生成doxygen 文档
–host-cc=HOSTCC use host C compiler HOSTCC # 使用HOST c编译
–host-cflags=HCFLAGS use HCFLAGS when compiling for host # 使用HCFLAGS
–host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host # 使用HCPPFLAGSS –host-ld=HOSTLD use host linker HOSTLD # 使用host连接器
–host-ldflags=HLDFLAGS use HLDFLAGS when linking for host # 使用HLDFLAGS
–host-libs=HLIBS use libs HLIBS when linking for host # 使用HLIBS
–host-os=OS compiler host OS [$target_os] # 编译主机系统
–extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS] # 添加ECFLAGS到CFLAGS
–extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS [$CXXFLAGS] # 添加ECFLAGS到 CXXFLAGS
–extra-objcflags=FLAGS add FLAGS to OBJCFLAGS [$CFLAGS] # 添加FLAGS到OBJCFLAGS –extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [\$LDFLAGS] # 添加ELDFLAGS到 LDFLAGS
–extra-ldexeflags=ELDFLAGS add ELDFLAGS to LDEXEFLAGS [\$LDEXEFLAGS] # 添加 ELDFLAGS到LDEXEFLAGS
–extra-ldlibflags=ELDFLAGS add ELDFLAGS to LDLIBFLAGS [\$LDLIBFLAGS] # 添加 ELDFLAGS到LDLIBFLAGS
–extra-libs=ELIBS add ELIBS [\$ELIBS] # 添加ELIBS
–extra-version=STRING version string suffix [] # 添加版本
–optflags=OPTFLAGS override optimization-related compiler flags # 重写优化编译标志 –build-suffix=SUFFIX library name suffix [] # 添加库名字路径
–enable-pic build position-independent code # 添加位置独立代码
–enable-thumb compile for Thumb instruction set # 编译錞humb指令集
–enable-lto use link-time optimization # 使用连接时优化
–env=”ENV=override” override the environment variables # 重写环境变量
高级选项
Advanced options (experts only):
–malloc-prefix=PREFIX prefix malloc and related names with PREFIX # 申请路径
–custom-allocator=NAME use a supported custom allocator # 申请名字
–disable-symver disable symbol versioning # 禁用symver
–enable-hardcoded-tables use hardcoded tables instead of runtime generation # 启 用硬件编码表
–disable-safe-bitstream-reader # 禁用安全流阅读器
disable buffer boundary checking in bitreaders
(faster, but may crash)
–sws-max-filter-size=N the max filter size swscale uses
[$sws_max_filter_size_default] # 最大过滤器大小N
优化选项
Optimization options (experts only):
–disable-asm disable all assembly optimizations # 禁用全部汇编程序优化
–disable-altivec disable AltiVec optimizations # 禁用邋AltiVec优化
–disable-vsx disable VSX optimizations # 急用VSX优化
–disable-power8 disable POWER8 optimizations # 禁用power8优化
–disable-amd3dnow disable 3DNow! optimizations # 禁用3D Now!优化
–disable-amd3dnowext disable 3DNow! extended optimizations # 禁用3D Now!扩展优化 –disable-mmx disable MMX optimizations # 禁用MMX优化
–disable-mmxext disable MMXEXT optimizations # 禁用MMXEXT优化
–disable-sse disable SSE optimizations # 禁用SSE优化
–disable-sse2 disable SSE2 optimizations # 禁用SSE2优化
–disable-sse3 disable SSE3 optimizations # 禁用SSE3优化
–disable-ssse3 disable SSSE3 optimizations # 禁用SSSE3优化
–disable-sse4 disable SSE4 optimizations # 禁用SSE4优化
–disable-sse42 disable SSE4.2 optimizations # 禁用SSE4.2优化
–disable-avx disable AVX optimizations # 禁用AVX优化
–disable-xop disable XOP optimizations # 禁用XOP优化
–disable-fma3 disable FMA3 optimizations # 禁用FMA3优化
–disable-fma4 disable FMA4 optimizations # 禁用FMA4优化
–disable-avx2 disable AVX2 optimizations # 禁用AVX2优化
–disable-aesni disable AESNI optimizations # 禁用AESNI优化
–disable-armv5te disable armv5te optimizations # 禁用armv5te优化
–disable-armv6 disable armv6 optimizations # 禁用armv6优化
–disable-armv6t2 disable armv6t2 optimizations # 禁用armv6t2优化
–disable-vfp disable VFP optimizations # 禁用VFP优化
–disable-neon disable NEON optimizations # 禁用NEON优化
–disable-inline-asm disable use of inline assembly # 禁用内部组合优化
–disable-yasm disable use of nasm/yasm assembly # 禁用nasm/yasm组合
–disable-mipsdsp disable MIPS DSP ASE R1 optimizations # 禁用MIPS DSP ASE R1优化 –disable-mipsdspr2 disable MIPS DSP ASE R2 optimizations # 禁用MIPS DSP ASE R2优化 –disable-msa disable MSA optimizations # 禁用MSA优化
–disable-mipsfpu disable floating point MIPS optimizations # 禁用浮点MIPS优化
–disable-mmi disable Loongson SIMD optimizations # 禁用长SIMD优化
–disable-fast-unaligned consider unaligned accesses slow # 禁用快速非对齐,非对齐速度 慢
开发选项
Developer options (useful when working on FFmpeg itself):
–disable-debug disable debugging symbols # 禁用调试符号
–enable-debug=LEVEL set the debug level [$debuglevel] # 禁用调试等级
–disable-optimizations disable compiler optimizations # 禁用编译器优化
–enable-extra-warnings enable more compiler warnings # 启用编译器警告
–disable-stripping disable stripping of executables and shared libraries # 禁用可 执行程序剥脱共享库
–assert-level=level 0(default), 1 or 2, amount of assertion testing, # 启用段保护等 级
2 causes a slowdown at runtime.
–enable-memory-poisoning fill heap uninitialized allocated space with arbitrary data # 启用内存填充,用任意数填充
–valgrind=VALGRIND run “make fate” tests through valgrind to detect memory # 启用 内存检测
leaks and errors, using the specified valgrind binary.
Cannot be combined with –target-exec
–enable-ftrapv Trap arithmetic overflows # 启用算术运算溢出
–samples=PATH location of test samples for FATE, if not set use # 指定测试示例位置 \$FATE_SAMPLES at make invocation time.
–enable-neon-clobber-test check NEON registers for clobbering (should be # 启用 neon clobber测试
used only for debugging purposes)
–enable-xmm-clobber-test check XMM registers for clobbering (Win64-only; # 启用 xmm clobber测试
should be used only for debugging purposes)
–enable-random randomly enable/disable components # 启用组件随机开启或关闭
–disable-random # 禁用组件随机开启或关闭
–enable-random=LIST randomly enable/disable specific components or # 启用随机列表 –disable-random=LIST component groups. LIST is a comma-separated list # 禁用随机列 表
of NAME[:PROB] entries where NAME is a component
(group) and PROB the probability associated with
NAME (default 0.5).
–random-seed=VALUE seed value for –enable/disable-random # 启用随机种子值
–disable-valgrind-backtrace do not print a backtrace under Valgrind
(only applies to –disable-optimizations builds) # 禁用valgrind内存分析追踪

3.FFMPEG各模块简述

FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。它包括了领先的 音/视频编码库libavcodec等。
libavformat:用于各种音视频封装格式的生成和解析,包括获取解码所需信息以生成解码上下文结构和读取 音视频帧等功能;
libavcodec:用于各种类型声音/图像编解码;
libavutil:包含一些公共的工具函数;
libswscale:用于视频场景比例缩放、色彩映射转换;
libpostproc:用于后期效果处理;

4.编译ffmpeg

1
./configure --disable-x86asm

编译成功后的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash

# 首先定义一个NDK目录的变量 NDK_ROOT
NDK_ROOT=/home/jackou/tools/android-ndk-r17c

# 此变量执行ndk中的交叉编译gcc所在目录
TOOLCHAIN=$NDK_ROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64

#从as的 externalNativeBuild/xxx/build.ninja, 反正下面的配置,可以压制警告的意思
#FLAGS="-isystem $NDK_ROOT/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=arm64-v8a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fPIC"

FLAGS="-isystem $NDK_ROOT/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv8-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fPIC"

INCLUDES=" -isystem $NDK_ROOT/sources/android/support/include"

# 1.定义编译后,所存放的目录
PREFIX=./android/arm

# 2.--enable-small 优化大小 非常重要,必须优化才行的哦
# 3.--disable-programs 不编译ffmpeg程序(命令行工具),我们是需要获取静态、动态库
# 4.--disable-avdevice 关闭avdevice模块,此模块在android中无用
# 5.--disable-encoders 关闭所有编码器(播放不需要编码)
# 6.--disable-muxers 关闭所有复用器(封装器),不需要生成mp4这样的文件,所有关闭
# 7.--disable-filters 关闭所有滤镜
# 8.--enable-cross-compile 开启交叉编译(ffmpeg是跨平台的,注意:并不是所有库都有这么happy的选项)
# 9.--cross-prefix 看右边的值就知道是干嘛的,gcc的前缀..
# 10.disable-shared / enable-static 这个不写也可以,默认就是这样的,(代表关闭动态库,开启静态库)
# 11.--sysroot 寻找NDK所有的库
# 12.--extra-cflags 会传给gcc的参数
# 13.--arch --target-os

./configure \
--prefix=$PREFIX \
--enable-small \
--disable-programs \
--disable-avdevice \
--disable-encoders \
--disable-muxers \
--disable-filters \
--enable-cross-compile \
--cross-prefix=$TOOLCHAIN/bin/aarch64-linux-android- \
--disable-shared \
--enable-static \
--sysroot=$NDK_ROOT/platforms/android-21/arch-arm64 \
--extra-cflags="$FLAGS $INCLUDES" \
--extra-cflags="-isysroot $NDK_ROOT/sysroot" \
--arch=aarch64 \
--extra-libs=-lgcc \
--target-os=android

make clean

make install

导入AS中Cmakelist编译脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
cmake_minimum_required(VERSION 3.4.1)

file(GLOB allCpp *.cpp)

add_library(
native-lib
SHARED
${allCpp})

find_library(
log-lib
log)

# 引入FFmpeg的头文件
include_directories(${CMAKE_SOURCE_DIR}/include)

# 引入FFmpeg的库文件,设置内部的方式引入,指定库的目录是 -L 指定具体的库-l
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/${CMAKE_ANDROID_ARCH_ABI}")

target_link_libraries(
native-lib

# 具体的库文件,链接到总库
# 这样写会报错,有坑
# avcodec avfilter avformat avutil swresample swscale

# 先把有依赖的库,先依赖进来
avformat avcodec avfilter avutil swresample swscale

${log-lib})

5.Makefile构建系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 这里面能够决定编译 Login.c Test.c

# 1.源文件在的位置。宏函数 my-dir 返回当前目录(包含 Android.mk 文件本身的目录)的路径。
# LOCAL_PATH 其实就是Android.mk文件本身的目录的路径
LOCAL_PATH := $(call my-dir)

$(info "LOCAL_PATH:======== ${LOCAL_PATH}")

# 2.清理
include $(CLEAR_VARS)

# TODO 预编译库的引入 == 提前编译好的库
LOCAL_MODULE := getndk

# 指定静态库
# LOCAL_SRC_FILES := libgetndk.a

# 指定动态库
LOCAL_SRC_FILES := libgetndk.so

# 预编译静态库的Makeifle脚本
# include $(PREBUILT_STATIC_LIBRARY)

# 预编译共享库的Makeifle脚本
include $(PREBUILT_SHARED_LIBRARY)

#引入其他makefile文件。CLEAR_VARS 变量指向特殊 GNU Makefile,可为您清除许多 LOCAL_XXX 变量
#不会清理 LOCAL_PATH 变量
include $(CLEAR_VARS)
# TODO end

# 3.指定库名字 apk/lib/libMyLoginJar.so == 总库
#存储您要构建的模块的名称 每个模块名称必须唯一,且不含任何空格
#如果模块名称的开头已是 lib,则构建系统不会附加额外的前缀 lib;而是按原样采用模块名称,并添加 .so 扩展名。
LOCAL_MODULE := MyLoginJar

#包含要构建到模块中的 C 和/或 C++ 源文件列表 以空格分开
LOCAL_SRC_FILES := Login.c \
Test.c

# TODO 开始链接进来
# 静态库的链接
# LOCAL_STATIC_LIBRARIES := getndk
# 动态库链接
LOCAL_SHARED_LIBRARIES := getndk

# 导入 log
#LOCAL_LDLIBS := -llog
# 链接数学库和log库
LOCAL_LDLIBS := -lm -llog

# 4.动态库
#构建动态库BUILD_SHARED_LIBRARY 最后生成总动态库 ---> apk/lib/armeabi-v7a/libMyLoginJar.so
include $(BUILD_SHARED_LIBRARY)
# 静态库
# include $(BUILD_STATIC_LIBRARY)

6.Cmake构建工程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
cmake_minimum_required(VERSION 3.10.2)
project("ndk28_cmake")

# 批量导入 cpp c源文件
file(GLOB SOURCE ${CMAKE_SOURCE_DIR}/cpp/*.cpp ${CMAKE_SOURCE_DIR}/cpp/*.c)

# 添加一个库(动态库SHARED,静态库STATIC)
add_library(native-lib # 库的名字 ---> libnative-lib.so
SHARED # 动态库
# cpp的源文件:把cpp源文件编译成 libnative-lib.so 库
${SOURCE}
)


# TODO >>>>>>>>>>>>>>>>>>>>>>>> 预编译库(已经有了 xxx.so / xxx.a)的导入方式
# TODO 方式一:推荐的方式
#[[
# 第一步:导入fmod头文件
include_directories("${CMAKE_SOURCE_DIR}/cpp/inc")
# 第二步:导入库文件 (方式一)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/jniLibsaaa/${CMAKE_ANDROID_ARCH_ABI}")
# 第三步链接到总库中去
target_link_libraries( # native-lib是我们的总库
native-lib # 被链接的总库
log # 自动寻找 # 具体的库 链接到 libnative-lib.so里面去
fmod # 具体的库 链接到 libnative-lib.so里面去
fmodL # 具体的库 链接到 libnative-lib.so里面去
)
]]

# TODO 方式二:以前更多使用的方式
#[[
# 第一步:导入fmod头文件
include_directories("${CMAKE_SOURCE_DIR}/cpp/inc")
# 第二步:导入库文件 (方式二)
add_library(fmod SHARED IMPORTED)
set_target_properties(fmod PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/jniLibsaaa/${CMAKE_ANDROID_ARCH_ABI}/libfmod.so)

add_library(fmodL SHARED IMPORTED)
set_target_properties(fmodL PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/jniLibsaaa/${CMAKE_ANDROID_ARCH_ABI}/libfmodL.so)

# 第三步链接到总库中去
target_link_libraries( # native-lib是我们的总库
native-lib # 被链接的总库
log # 自动寻找 # 具体的库 链接到 libnative-lib.so里面去
fmod # 具体的库 链接到 libnative-lib.so里面去
fmodL # 具体的库 链接到 libnative-lib.so里面去
)
#]]

# TODO >>>>>>>>>>>>>>>>>>>>>>>> 判断静态库还是动态库 (静态库会直接Copy到总库,动态库则不会)
#[[
# >>>>>>>>>>> 下面代码不参与 判断 start
# 第一步:导入fmod头文件
include_directories("${CMAKE_SOURCE_DIR}/cpp/inc")
# 第二步:导入库文件 (方式二)
add_library(fmod SHARED IMPORTED)
set_target_properties(fmod PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/jniLibsaaa/${CMAKE_ANDROID_ARCH_ABI}/libfmod.so)
add_library(fmodL SHARED IMPORTED)
set_target_properties(fmodL PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/jniLibsaaa/${CMAKE_ANDROID_ARCH_ABI}/libfmodL.so)
# >>>>>>>>>>> 上面代码不参与 判断 end

## OFF=0=false ON=1=true
# set(isSTATIC OFF)
set(isSTATIC ON)

if(${isSTATIC})
# 导入静态库
add_library(getndk STATIC IMPORTED)
# 开始真正导入 静态库 System.loadLibrary("getndk"); // 如果是动态库,这里需要加载,否则注释
set_target_properties(getndk PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/cpp/libgetndk.a)
message("isSTATIC == static")
else(${isSTATIC})
# 导入动态库
add_library(getndk SHARED IMPORTED)
# 开始真正导入 动态库 System.loadLibrary("getndk"); // 如果是动态库,这里需要加载,否则注释
set_target_properties(getndk PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/jniLibsaaa/${CMAKE_ANDROID_ARCH_ABI}/libgetndk.so)
message("isSTATIC == shared")

endif(${isSTATIC})

target_link_libraries( # native-lib是我们的总库
native-lib # 被链接的总库
log # 自动寻找 # 具体的库 链接到 libnative-lib.so里面去
getndk # TODO 具体的库 链接到 libnative-lib.so里面去【这个库,有可能是静态库,有可能是动态库】
fmod # 具体的库 链接到 libnative-lib.so里面去
fmodL # 具体的库 链接到 libnative-lib.so里面去
)
]]


# rtmp的时候,就全盘采用 源码构建方式
# TODO >>>>>>>>>>>>>>>>>>>>>>>> 依赖源码的方式(已经有了 xxxc / xxx.c / xxx.c ...)的导入方式

#引入get子目录下的CMakeLists.txt
add_subdirectory(${CMAKE_SOURCE_DIR}/cpp/libget)

#引入count子目录下的CMakeLists.txt
add_subdirectory(${CMAKE_SOURCE_DIR}/cpp/libcount)

target_link_libraries( # native-lib是我们的总库
native-lib # 被链接的总库
log # 自动寻找 # 具体的库 链接到 libnative-lib.so里面去
get # 具体的库 链接到 libnative-lib.so里面去
count # 具体的库 链接到 libnative-lib.so里面去
)
1
2
3
4
5
6
7
8
9
10
## 子目录下的cmakelist
cmake_minimum_required(VERSION 3.10.2)

file(GLOB SOURCE *.cpp)

add_library(
count
SHARED # 最终生成 libcount.so
${SOURCE}
)
1
2
3
4
5
6
7
8
9
cmake_minimum_required(VERSION 3.10.2)

file(GLOB SOURCE *.c)

add_library(
get
STATIC # 最终生成 libget.a
${SOURCE}
)
1
2
3
4
5
6
7
8
9
# 旧版本日志输出到output.txt中,新版本输出到/.cxx/cmake/debug/armeabi-v7a/metadata_generation_stderr.txt或者cmake_server_log.txt中
# (无) = 重要消息;
# STATUS = 非重要消息;
# WARNING = CMake 警告, 会继续执行;
# AUTHOR_WARNING = CMake 警告 (dev), 会继续执行;
# SEND_ERROR = CMake 错误, 继续执行,但是会跳过生成的步骤;
# FATAL_ERROR = CMake 错误, 终止所有处理过程;

message(STATUS "this print message!")

7. Cmake变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#申明变量
set(var jack)
messgae(STATUS ${var})

# CMake中所有变量都是string类型。可以使用set()和unset()命令来声明或移除一个变量
# 移除变量
unset(var)
message("my_var = ${var}") # 会取不到值,因为被移除了
# TODO CMake列表(lists)
# 声明列表:set(列表名 值1 值2 ... 值N) 或 set(列表名 "值1;值2;...;值N")
set(list_var 1 2 3 4 5) # 字符串列表呢? CMake中所有变量都是string类型
# 或者
set(list_var2 "1;2;3;4;5") # 字符串列表呢? CMake中所有变量都是string类型 message("list_var = ${list_var}")
message("list_var2 = ${list_var2}")

# TODO CMake流程控制-条件命令
# true(1,ON,YES,TRUE,Y,非0的值)
# false(0,OFF,NO,FALSE,N,IGNORE,NOTFOUND)
set(if_tap OFF) # 定义一个变量if_tap,值为false
set(elseif_tap ON) # 定义一个变量elseif_tap,值为ture
if(${if_tap})
message("if")
elseif(${elseif_tap})
message("elseif")
else(${if_tap}) # 可以不加入 ${if_tap}
message("else")
# endif(${if_tap}) # 结束if
endif() # 结束if 可以不加
# 注意:elseif和else部分是可选的,也可以有多个elseif部分,缩进和空格对语句解析没有影响


# TODO CMake流程控制-循环命令
set(a "")
# a STREQUAL "xxx"(a等不等xxx,不等于)
# NOT == !
while(NOT a STREQUAL "xxx")
set(a "${a}x")
message(">>>>>>a = ${a}")
endwhile()

# break()命令可以跳出整个循环
# continue()可以继续当前循环

foreach(item 1 2 3)
message("1item = ${item}")
endforeach(item) # 结束for

foreach(item RANGE 2) # RANGE 默认从0开始, 所以是:0 1 2
message("2item = ${item}")
endforeach(item)

foreach(item RANGE 1 6 2) # 1 3 5 每次跳级2
message("3item = ${item}")
endforeach(item)

set(list_va3 1 2 3) # 列表
# foreach(item IN LISTS ${list_va3}) 没有报错,没有循环
foreach(item IN LISTS list_va3)
message("4item = ${item}")
endforeach(item)

# 函数定义
# TODO CMake自定义函数 Shell的函数很类似
#[[
ARGC:表示传入参数的个数
ARGV0:表示第一个参数,ARGV1、ARGV2以此类推即可
ARGV:表示所有参数
#]]
function(num_method n1 n2 n3)
message("call num_method method")
message("n1 = ${n1}")
message("n2 = ${n2}")
message("n3 = ${n3}")
message("ARGC = ${ARGC}")
message("arg1 = ${ARGV0} arg2 = ${ARGV1} arg3 = ${ARGV2}") message("all args = ${ARGV}")
endfunction(num_method)
num_method(1 2 3) # 调用num_method函数