NDK开发之交叉编译FFmpeg

FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL 或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。

它包含了非常先进的音频/视频编 解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开发的 FFmpeg在Linux平台下开发,但它同样也可以在其它操作系统环境中编译运行,包括Windows、Mac OS X等。这个项目最早由Fabrice Bellard发起,2004年至2015年间由Michael Niedermayer主要负责 维护。许多FFmpeg的开发人员都来自MPlayer项目,而且当前FFmpeg也是放在MPlayer项目组的服务 器上。项目的名称来自MPEG视频编码标准,前面的”FF”代表”Fast Forward”。 多媒体视频处理工具 FFmpeg有非常强大的功能包括视频采集功能、视频格式转换、视频抓图、给视频加水印等

libavformat:用于各种音视频封装格式的生成和解析,包括获取解码所需信息以生成解码上下文结构和 读取音视频帧等功能; libavcodec:用于各种类型声音/图像编解码; libavutil:包含一些公共的工具函 数; libswscale:用于视频场景比例缩放、色彩映射转换; libpostproc:用于后期效果处理; ffmpeg:该项目提供的一个工具,可用于格式转换、解码或电视卡即时编码等; ffsever:一个 HTTP 多媒体即时广播串流服务器; ffplay:是一个简单的播放器,使用ffmpeg 库解析和解码,通过SDL显 示;

FFmpeg源码下载

1
2
3
4
5
http://www.ffmpeg.org/releases/ (ffmpeg历史版本下载) 

wget http://www.ffmpeg.org/releases/ffmpeg-4.0.2.tar.bz2 解压

tar -xjf ffmpeg-4.0.2.tar.bz2

NDK的下载

1
2
3
4
5
6
7
1.下载:在浏览器,下载中心,复制链接地址: https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip? hl=zh_cn
2.wget 去下载操作:
wget https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip? hl=zh_cn
3.修改名称:
mv android-ndk-r17c-linux-x86_64.zip\?hl\=zh_cn android-ndk-r17c-linux- x86_64.zip
4.解压:
unzip android-ndk-r17c-linux-x86_64.zip

FFmpeg的一些配置项

1
2
3
可通过下面命令查看
./configure --help -> ffmpeg_help.txt
sz ffmpeg_help.txt

部分配置项释义

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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
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
–disable-pixelutils disable pixel utils in libavutil
单个组件选项
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 # 启用指定的解码器
# 禁止AAN DCT变换
# 禁用avutil中的像素单元
–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优化
ffmpeg_sh_help.txt 需要关注的选项
–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内存分析追踪
Usage: configure [options]Options: [defaults in brackets after descriptions]

【这是帮助选项,可以得到我们先查阅的内容,例如:./configure --help】 Help options:
--help
的帮助信息】
--quiet
这个从来没有用过】
--list-decoders

常用)
--list-encoders

常用)
--list-hwaccels

的硬件加速器】
--list-demuxers
--list-muxers
--list-parsers
--list-protocols
--list-bsfs

筛选器】
--list-indevs

备】
--list-outdevs

备】
--list-filters

特效时,就有用】
print this message 【当前所看到的所有内容,就是用--help输出 Suppress showing informative output 【禁止显示信息输出, show all available decoders【显示所有可用的解码器】 (非常 show all available encoders【显示所有可用的编码器】 (非常 show all available hardware accelerators 【显示所有可用
show all available demuxers 【显示所有可用的解复用器】 show all available muxers 【列出所有支持的封装】
show all available parsers 【显示所有可用的解析器】
show all available protocols 【列出支持的通信协议】
show all available bitstream filters 【显示所有可用的位流
show all available input devices 【显示所有可用的输入设 show all available output devices 【显示所有可用的输出设 show all available filters 【显示所有可用过滤器,当要做复杂
【这是标准选项,很多重要信息在这里面,例如:设置编译输出后的路径等】 【disable 关闭】
【enable 开启】
Standard options:
--logfile=FILE log tests and output to FILE [ffbuild/config.log] 【编 译时日志信息输出路径,默认:ffbuild/config.log】
--disable-logging do not log configure debug information 【关闭:不记录配置 调试信息】
--fatal-warnings fail if any configure warning is generated 【如果生成任 何配置警告则失败,注意:不能加,因为编译过程中,警告是会有的】
--prefix=PREFIX (非常常用)
--bindir=DIR 文件】 PREFIX
--datadir=DIR 录中安装数据文件】 PREFIX
install in PREFIX [/usr/local] 【我们最终产出的目录】 install binaries in DIR [PREFIX/bin] 【在目录中安装二进制 install data files in DIR [PREFIX/share/ffmpeg] 【在目
--docdir=DIR
[PREFIX/share/doc/ffmpeg] 【在目录中安装文档】 PREFIX
install documentation in DIR
install libs in DIR [PREFIX/lib] 【在目录中安装libs】 install shared libs in DIR [LIBDIR] 【在目录中安装共享 install includes in DIR [PREFIX/include] 【在目录中安装 install man page in DIR [PREFIX/share/man] 【在目录中安 install pkg-config files in DIR [LIBDIR/pkgconfig]
--libdir=DIR
PREFIX

--shlibdir=DIR 库】
--incdir=DIR includes】 PREFIX --mandir=DIR
装手册页】 PREFIX --pkgconfigdir=DIR
【在目录中安装pkg配置文件】 --enable-rpath
use rpath when linking programs (USE WITH CARE) --install-name-dir=DIR Darwin directory name for installed targets 【已安装目标
use rpath to allow installing libraries in paths 【使用 rpath允许在路径中安装库,没有用过】
的目录名】
not part of the dynamic linker search path

【许可选项:不用关注】
Licensing options:

--enable-gpl

--enable-version3
--enable-nonfree

allow use of GPL code, the resulting libs
and binaries will be under GPL [no]
upgrade (L)GPL to version 3 [no]
allow use of nonfree code, the resulting libs
and binaries will be unredistributable [no]

【配置选项,至关重要:关系到 编译成动态库 或 静态库】
Configuration options:

--disable-static

常用)
--enable-shared

--enable-small

以尝试加入进去】 (非常常用)
do not build static libraries [no] 【生成静态库】 (非常 build shared libraries [no] 【不生成动态库】 (非常常用)
optimize for size instead of speed 【可以优化库的大小,可
--disable-runtime-cpudetect disable detecting CPU capabilities at runtime
(smaller binary)

--enable-gray enable full grayscale support (slower color)
--disable-swscale-alpha disable alpha channel support in swscale
--disable-all disable building components, libraries and programs
--disable-autodetect disable automatically detected external libraries

[no]
【这个一般是在 Windows/Linux/MacOS 编译出 ffplay,ffmpeg 可执行程序,在Android中用不到】 Program options:
--disable-programs do not build command line programs

--disable-ffmpeg disable ffmpeg build 【ffmpeg:该项目提供的一个工具,可用于 格式转换、解码或电视卡即时编码等;】
--disable-ffplay disable ffplay build 【ffplay:是一个简单的播放器,使用 ffmpeg 库解析和解码,通过SDL显示;】
--disable-ffprobe

Documentation options:

--disable-doc
--disable-htmlpages
--disable-manpages
--disable-podpages
--disable-txtpages

disable ffprobe build 【分析媒体文件信息】
do not build documentation
do not build HTML documentation pages
do not build man documentation pages
do not build POD documentation pages
do not build text documentation pages

【FFmpeg 是由各个模块所组成的】 FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。它包括了领先的 音/视频编码库libavcodec等。 libavformat:用于各种音视频封装格式的生成和解析,包括获取解码所需信息以生成解码上下文结构和读取 音视频帧等功能;
libavcodec:用于各种类型声音/图像编解码;
libavutil:包含一些公共的工具函数;
libswscale:用于视频场景比例缩放、色彩映射转换;
libpostproc:用于后期效果处理;
Component options:
--disable-avdevice disable libavdevice build 【可以操作我们的摄像头,视频输出 等等,(但是在Android中是不支持的)】
--disable-avcodec disable libavcodec build 【包含了音视频编解码的东西,默认是 开启的,肯定不能关闭掉】 (非常常用)
--disable-avformat disable libavformat build 【默认开启的,音视频封装格式的生 成与解析】 (非常常用)
--disable-swresample disable libswresample build 【对音频进行重采样的(例如:把 单声道变成双声道,就需要此模块)】 (非常常用)
--disable-swscale

此模块】
--disable-postproc

掉】 (非常常用)
--disable-avfilter

模块】
disable libswscale build 【如果对一个视频 放大 缩小 就需要 disable libpostproc build 【后期处理的,这个模块可以关闭 disable libavfilter build 【给视频加字幕,加水印,就需要此
--disable-everything
--disable-encoder=NAME
--enable-encoder=NAME
--disable-encoders
--disable-decoder=NAME
--enable-decoder=NAME
--disable-decoders
--disable-hwaccel=NAME
--enable-hwaccel=NAME
--disable-hwaccels
--disable-muxer=NAME
--enable-muxer=NAME
--disable-muxers

disable all components listed below
disable encoder NAME
enable encoder NAME
disable all encoders

合并在一起 例如.mp4,不想这样就可以关闭)】
--disable-demuxer=NAME
--enable-demuxer=NAME
--disable-demuxers
--enable-parser=NAME
--disable-parser=NAME
--disable-parsers
--enable-bsf=NAME
--disable-bsf=NAME
--disable-bsfs
--enable-protocol=NAME
--disable-protocol=NAME disable protocol NAME

--disable-protocols
--enable-indev=NAME
--disable-indev=NAME
--disable-indevs
--enable-outdev=NAME
--disable-outdev=NAME
--disable-outdevs
--disable-devices
--enable-filter=NAME

disable all protocols
enable input device NAME
disable input device NAME
disable input devices
enable output device NAME
disable output device NAME
disable output devices
disable all devices
enable filter NAME

enable libavresample build (deprecated) [no]
disable pthreads [autodetect]
disable Win32 threads [autodetect]
disable OS/2 threads [autodetect]

--enable-avresample
--disable-pthreads
--disable-w32threads
--disable-os2threads
--disable-network
--disable-dct
--disable-dwt
--disable-error-resilience disable error resilience code

--disable-lsp
--disable-lzo
--disable-mdct
--disable-rdft
--disable-fft
--disable-faan
--disable-pixelutils

disable LSP code
disable LZO decoder code
disable MDCT code
disable RDFT code
disable FFT code
disable floating point AAN (I)DCT code
disable pixel utils in libavutil

【单个组件选项,可以查看下,有些选项不使用是可以关闭的】

Individual component options:

disable network support [no]
disable DCT code
disable DWT code

disable decoder NAME
enable decoder NAME
disable all decoders
disable hwaccel NAME
enable hwaccel NAME
disable all hwaccels
disable muxer NAME
enable muxer NAME
disable all muxers 【混合封装(音视频等于 一段音频 一段视频
disable demuxer NAME
enable demuxer NAME
disable all demuxers
enable parser NAME
disable parser NAME
disable all parsers
enable bitstream filter NAME
disable bitstream filter NAME
disable all bitstream filters
enable protocol NAME

【编码可以去关闭掉】

--disable-filter=NAME disable filter NAME
--disable-filters disable all filters

编译FFmpeg

编译脚本

放置到FFmpeg主目录下,如test_build.sh

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
#!/bin/bash
# 首先定义一个NDK目录的变量 NDK_ROOT NDK_ROOT=/root/DerryAll/Tools/android-ndk-r17c
# 此变量执行ndk中的交叉编译gcc所在目录 TOOLCHAIN=$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
#从as的 externalNativeBuild/xxx/build.ninja, 反正下面的配置,可以压制警告的意思 FLAGS="-isystem $NDK_ROOT/sysroot/usr/include/arm-linux-androideabi - D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack- protector-strong -no-canonical-prefixes -march=armv7-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
# 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/arm-linux-androideabi- \
--disable-shared \
--enable-static \
--sysroot=$NDK_ROOT/platforms/android-21/arch-arm \
--extra-cflags="$FLAGS $INCLUDES" \
--extra-cflags="-isysroot $NDK_ROOT/sysroot/" \
--arch=arm \
--target-os=android
make clean
make install

执行编译

1
2
3
./configure 【报错,需要关闭 asm 汇编相关】
./configure --disable-x86asm 【生成 Makefile 已经帮你关闭 asm 】
sh test_build.sh