11、ffmpeg学习笔记—ffmpeg源码编译-Android
16lz
2021-01-22
所需材料 1、ubuntu_16.04 2、android-ndk-r14b 3、ffmpeg 源码
1、创建工作目录
我是在桌面创建的develop目录。 1bassy@ubuntu:~/Desktop$ mkdir develop
2bassy@ubuntu:~/Desktop$ cd develop
3bassy@ubuntu:~/Desktop/develop$
2、安装git工具
安装git,用来下载ffmepg源码。bassy@ubuntu:~/Desktop/develop$ sudo apt-get install git
2Reading package lists... Done
3Building dependency tree
4Reading state information... Done
5...
3、下载ffmepg源码
进入工作目录develop,使用git下载ffmepg源码。 1bassy@ubuntu:~/Desktop/develop$ git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
2Cloning into 'ffmpeg'...
3remote: Counting objects: 516515, done.
4remote: Compressing objects: 100% (114032/114032), done.
5^Cceiving objects: 6% (34752/516515), 8.20 MiB | 141.00 KiB/s
当然,如果你觉得下载太慢的话,可以去官网使用迅雷等工具下载,然后解压出来。下载完成后,如下:
bassy@ubuntu:~/Desktop/develop$ cd ffmpeg/
2bassy@ubuntu:~/Desktop/develop/ffmpeg$ ll
3total 1584
4drwxrwxrwx 18 bassy bassy 4096 Jun 6 10:27 ./
5drwxrwxr-x 3 bassy bassy 4096 Jun 7 08:08 ../
6-rwxrw-rw- 1 bassy bassy 56143 Jun 6 10:26 Changelog*
7-rwxrw-rw- 1 bassy bassy 73279 Jun 6 10:26 cmdutils.c*
8-rwxrw-rw- 1 bassy bassy 24505 Jun 6 10:26 cmdutils.h*
9-rwxrw-rw- 1 bassy bassy 10627 Jun 6 10:26 cmdutils_opencl.c*
10drwxrwxrwx 13 bassy bassy 4096 Jun 6 10:26 compat/
11-rwxrw-rw- 1 bassy bassy 228905 Jun 6 10:26 configure*
12-rwxrw-rw- 1 bassy bassy 418 Jun 6 10:26 CONTRIBUTING.md*
13-rwxrw-rw- 1 bassy bassy 18092 Jun 6 10:26 COPYING.GPLv2*
14-rwxrw-rw- 1 bassy bassy 35147 Jun 6 10:26 COPYING.GPLv3*
15-rwxrw-rw- 1 bassy bassy 26526 Jun 6 10:26 COPYING.LGPLv2.1*
16-rwxrw-rw- 1 bassy bassy 7651 Jun 6 10:26 COPYING.LGPLv3*
17-rwxrw-rw- 1 bassy bassy 274 Jun 6 10:26 CREDITS*
18drwxrwxrwx 4 bassy bassy 4096 Jun 6 10:26 doc/
19drwxrwxrwx 2 bassy bassy 4096 Jun 6 10:26 ffbuild/
20-rwxrw-rw- 1 bassy bassy 169685 Jun 6 10:26 ffmpeg.c*
21-rwxrw-rw- 1 bassy bassy 2412 Jun 6 10:26 ffmpeg_cuvid.c*
22-rwxrw-rw- 1 bassy bassy 15057 Jun 6 10:26 ffmpeg_dxva2.c*
23-rwxrw-rw- 1 bassy bassy 44795 Jun 6 10:26 ffmpeg_filter.c*
24-rwxrw-rw- 1 bassy bassy 19841 Jun 6 10:26 ffmpeg.h*
25-rwxrw-rw- 1 bassy bassy 148299 Jun 6 10:26 ffmpeg_opt.c*
26-rwxrw-rw- 1 bassy bassy 3064 Jun 6 10:26 ffmpeg_qsv.c*
27-rwxrw-rw- 1 bassy bassy 6720 Jun 6 10:26 ffmpeg_vaapi.c*
28-rwxrw-rw- 1 bassy bassy 4469 Jun 6 10:26 ffmpeg_vdpau.c*
29-rwxrw-rw- 1 bassy bassy 6642 Jun 6 10:26 ffmpeg_videotoolbox.c*
30-rwxrw-rw- 1 bassy bassy 132011 Jun 6 10:26 ffplay.c*
31-rwxrw-rw- 1 bassy bassy 134506 Jun 6 10:26 ffprobe.c*
32-rwxrw-rw- 1 bassy bassy 128352 Jun 6 10:26 ffserver.c*
33-rwxrw-rw- 1 bassy bassy 51173 Jun 6 10:26 ffserver_config.c*
34-rwxrw-rw- 1 bassy bassy 5814 Jun 6 10:26 ffserver_config.h*
35drwxrwxrwx 7 bassy bassy 4096 Jun 6 10:27 .git/
36-rwxrw-rw- 1 bassy bassy 50 Jun 6 10:26 .gitattributes*
37-rwxrw-rw- 1 bassy bassy 279 Jun 6 10:26 .gitignore*
38-rwxrw-rw- 1 bassy bassy 595 Jun 6 10:26 INSTALL.md*
39drwxrwxrwx 14 bassy bassy 49152 Jun 6 10:26 libavcodec/
40drwxrwxrwx 3 bassy bassy 4096 Jun 6 10:26 libavdevice/
41drwxrwxrwx 4 bassy bassy 16384 Jun 6 10:26 libavfilter/
42drwxrwxrwx 3 bassy bassy 20480 Jun 6 10:26 libavformat/
43drwxrwxrwx 6 bassy bassy 4096 Jun 6 10:26 libavresample/
44drwxrwxrwx 12 bassy bassy 4096 Jun 6 10:26 libavutil/
45drwxrwxrwx 2 bassy bassy 4096 Jun 6 10:26 libpostproc/
46drwxrwxrwx 6 bassy bassy 4096 Jun 6 10:26 libswresample/
47drwxrwxrwx 7 bassy bassy 4096 Jun 6 10:26 libswscale/
48-rwxrw-rw- 1 bassy bassy 4368 Jun 6 10:26 LICENSE.md*
49-rwxrw-rw- 1 bassy bassy 28407 Jun 6 10:26 MAINTAINERS*
50-rwxrw-rw- 1 bassy bassy 7142 Jun 6 10:26 Makefile*
51drwxrwxrwx 2 bassy bassy 4096 Jun 6 10:26 presets/
52-rwxrw-rw- 1 bassy bassy 1893 Jun 6 10:26 README.md*
53-rwxrw-rw- 1 bassy bassy 8 Jun 6 10:26 RELEASE*
54drwxrwxrwx 7 bassy bassy 4096 Jun 6 10:27 tests/
55drwxrwxrwx 2 bassy bassy 4096 Jun 6 10:27 tools/
56-rwxrw-rw- 1 bassy bassy 474 Jun 6 10:26 .travis.yml*
4、安装NDK
NDK下载地址:https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip 下载之后,解压到工作目录develop下,如下所示:
1
bassy@ubuntu:~/Desktop/develop$ ll
2total 16
3drwxrwxr-x 4 bassy bassy 4096 Jun 7 08:29 ./
4drwxr-xr-x 5 bassy bassy 4096 Jun 7 08:19 ../
5drwxr-xr-x 11 bassy bassy 4096 Mar 15 14:20 android-ndk-r14b/
6drwxrwxrwx 18 bassy bassy 4096 Jun 6 10:27 ffmpeg/
5、ffmpeg编译配置
在ffmpeg目录下新建一个文件“build_android.sh”,并输入如下内容,注意,请根据自己的情况进行适当的修改:
2NDK=/home/bassy/Desktop/develop/android-ndk-r14b
3SYSROOT=$NDK/platforms/android-14/arch-arm/
4TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
5
6CPU=arm
7PREFIX=$(pwd)/android/$CPU
8ADDI_CFLAGS="-marm"
9TARGET_ARCH="arm"
10
11
12function build_one
13{
14./configure \
15 --prefix=$PREFIX \
16 --disable-shared \
17 --enable-static \
18 --disable-doc \
19 --disable-ffmpeg \
20 --disable-ffplay \
21 --disable-ffprobe \
22 --disable-ffserver \
23 --disable-avdevice \
24 --disable-doc \
25 --disable-symver \
26 --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
27 --target-os=android \
28 --arch=$TARGET_ARCH\
29 --enable-cross-compile \
30 --sysroot=$SYSROOT \
31 --extra-cflags="-Os -fPIC -DANDROID $ADDI_CFLAGS" \
32 --extra-ldflags="$ADDI_LDFLAGS" \
33 $ADDITIONAL_CONFIGURE_FLAG
34make clean
35make
36make install
37}
38
39build_one
bassy@ubuntu:~/Desktop/develop/ffmpeg$ sudo chmod +x build_android.sh
2[sudo] password for bassy:
3bassy@ubuntu:~/Desktop/develop/ffmpeg$ ll *build_*
4-rwxrwxr-x 1 bassy bassy 777 Jun 7 08:36 build_android.sh*
注意,上面有行代码:“SYSROOT=$NDK/platforms/android-14/arch-arm/”指定了Android Platform的版本,这个很重要的,因为它决定了你用它开发的时候所能使用的Android SDK的版本。举个例子,如果这里填写的是android-21,开发时minSdkVersion填写的是android-14,会出现很多奇怪的错误。如果需要编译动态库的话,请修改上面的配置“--disable--shared”改为“--enable-shared”。
如需要编译其它CPU架构的话,可查看https://github.com/RoyGuanyu/build-scripts-of-ffmpeg-x264-for-android-ndk,或者打开ffmpeg目录下的configure文件,看看里面声明的常量值。
更多配置,请用文本查看器打开“(ffmpeg)/configure”文件,里面可以找到对应的说明。以下是其中一部分内容。
...
2
3Program options:
4 --disable-programs do not build command line programs
5 --disable-ffmpeg disable ffmpeg build
6 --disable-ffplay disable ffplay build
7 --disable-ffprobe disable ffprobe build
8 --disable-ffserver disable ffserver build
9
10Documentation options:
11 --disable-doc do not build documentation
12 --disable-htmlpages do not build HTML documentation pages
13 --disable-manpages do not build man documentation pages
14 --disable-podpages do not build POD documentation pages
15 --disable-txtpages do not build text documentation pages
16
17Component options:
18 --disable-avdevice disable libavdevice build
19 --disable-avcodec disable libavcodec build
20 --disable-avformat disable libavformat build
21 --disable-swresample disable libswresample build
22 --disable-swscale disable libswscale build
23
24...
6、开始编译
进入在ffmpeg目录,执行“build_android.sh”,如下:1
bassy@ubuntu:~/Desktop/develop/ffmpeg$ sudo ./build_android.sh
接下来可以去喝杯水,休闲地等它编译……快的话,十多分钟就完成编译了。...
2INSTALL libavutil/lzo.h
3INSTALL libavutil/avconfig.h
4INSTALL libavutil/ffversion.h
5INSTALL libavutil/libavutil.pc
6bassy@ubuntu:~/Desktop/develop/ffmpeg$
7、查看编译结果
进入在"ffmpeg/android/arm"可以看到编译结果。1
bassy@ubuntu:~/Desktop/develop/ffmpeg/android/arm$ ll
2total 16
3drwxr-xr-x 4 root root 4096 Jun 7 09:03 ./
4drwxr-xr-x 3 root root 4096 Jun 7 09:03 ../
5drwxr-xr-x 8 root root 4096 Jun 7 09:03 include/
6drwxr-xr-x 3 root root 4096 Jun 7 09:03 lib/
7bassy@ubuntu:~/Desktop/develop/ffmpeg/android/arm$ ll lib/
8total 138992
9drwxr-xr-x 3 root root 4096 Jun 7 09:03 ./
10drwxr-xr-x 4 root root 4096 Jun 7 09:03 ../
11-rw-r--r-- 1 root root 90607318 Jun 7 09:03 libavcodec.a
12-rw-r--r-- 1 root root 13182384 Jun 7 09:03 libavfilter.a
13-rw-r--r-- 1 root root 33612772 Jun 7 09:03 libavformat.a
14-rw-r--r-- 1 root root 1636078 Jun 7 09:03 libavutil.a
15-rw-r--r-- 1 root root 377648 Jun 7 09:03 libswresample.a
16-rw-r--r-- 1 root root 2886158 Jun 7 09:03 libswscale.a
17drwxr-xr-x 2 root root 4096 Jun 7 09:03 pkgconfig/
"include"是头文件,"lib"是静态库,在开发的时候会用到。- libavcodecencoding/decoding library
- libavfiltergraph-based frame editing library
- libavformatI/O and muxing/demuxing library
- libavdevicespecial devices muxing/demuxing library
- libavutilcommon utility library
- libswresampleaudio resampling, format conversion and mixing
- libpostprocpost processing library
- libswscalecolor conversion and scaling library
至此,ffmpeg的编译已经完成了,直下来将介绍如果编写第一个ffmpeg程序。
更多相关文章
- Ubuntu Android/Sdk/build-tools/23.0.3/aapt": error=2, 没有那
- java漏洞成黑客目标微软呼吁用户更新软件
- Linux下java/bin目录下的命令集合
- eclipse写javaweb工程时文件目录为WebContent而不是WenRoot的不
- [疯狂Java]NIO.2:walkFileTree、FileVisitor(遍历文件/目录)