一、准备工作
1.1、ffmpeg源码下载
官网下载
1.2、linux 系统
1.3、linux ndk下载
官网下载
二、编译脚本编写
#!/bin/bash
ARCHS="armv7 arm64"
PREFIX=out/lib
ANDROID_VERSION=android-21
NDK_PATH=/studySourceCode/android-ndk-r21b
TOOLCHAIN=$NDK_PATH/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAN/bin/arm-linux-androideabi-
SYSROOT=$NDK_PATH/platforms/$ANDROID_VERSION/arch-$ARCH
for ARCH in $ARCHS; do
echo "************ START *************"
echo "NDK_PATH=$NDK_PATH ANDROID_VERSION=$ANDROID_VERSION"
./configure --disable-x86asm \
--target-os=linux \
--arch=$ARCH \
--prefix=$PREFIX/$ARCH \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-fferver \
--disable-doc \
--disable-symver \
--enable-cross-compile \
--cross-prefix=$CROSS_COMPILE \
--sysroot=$SYSROOT \
--extra-cflags="-fpic"
make clean
make -j8
make install
echo "PREFIX=$PREFIX/$ARCH"
echo "TOOLCHAIN=${TOOLCHAIN}"
echo "CROSS_COMPILE=${CROSS_COMPILE}"
echo "SYSROOT=${SYSROOT}"
echo "************* END ************"
done
2.1、
这里首先要注意的一行是:
./configure --disable-x86asm
生成编译相关的配置
因为如今网络上很多编译脚本中都是写的
./configure
,
如今使用不带参执行这个命令会发现其实压根不会执行任何操作去生成配置,后面如果去执行ffmpeg_build.sh
编译会引发 No such file or directory(没有那个文件或目录) 的问题
2.2 编译参数
参数 | 说明 |
---|---|
--arch | 指定cpu位数 |
--prefix | 指定安装路径(但是我用这个无法指定路径,还是生成在默认路径/usr/local) |
--disable-encoders | 禁止所有的编码 |
--enable-encoder=NAME | 开启名字为NAME的编码,例如--enable-encoder=h264,mp3,m4a,wav,aac |
--disable-encoder=NAME | 禁止名字为NAME的编码,例如--enable-encoder=h264,mp3,m4a,wav,aac |
--disable-decoders | 禁止所有的解码 |
--enable-decoder=NAME | 开启名字为NAME的解码,例如--enable-decoder=h264,mp3,m4a,wav,aac |
--disable-decoder=NAME | 禁止名字为NAME的解码,例如--disable-decoder=h264,mp3,m4a,wav,aac |
更多配置参数参考
./configure --help
三、开始编译
3.1、生成相关配置
./configure --disable-x86asm
3.2、执行编译脚本
. ffmpeg_build.sh
这里单独拿出了./configure --disable-x86asm
,因为怕有些读者不是从笔者这里复制的脚本,./configure --disable-x86asm
的作用读者可以参考第二节
最后等待编译完成即可。
四、常见错误
4.1、./configure 权限不够
chmod 777 /.configure
4.2
-bash: --prefix=out/lib: 没有那个文件或目录
Makefile:2: ffbuild/config.mak: 没有那个文件或目录
Makefile:40: /tools/Makefile: 没有那个文件或目录
Makefile:41: /ffbuild/common.mak: 没有那个文件或目录
Makefile:97: /libavutil/Makefile: 没有那个文件或目录
Makefile:97: /ffbuild/library.mak: 没有那个文件或目录
Makefile:99: /fftools/Makefile: 没有那个文件或目录
Makefile:100: /doc/Makefile: 没有那个文件或目录
Makefile:101: /doc/examples/Makefile: 没有那个文件或目录
Makefile:167: /tests/Makefile: 没有那个文件或目录
make: *** 没有规则可以创建目标“/tests/Makefile”。 停止。
Makefile:2: ffbuild/config.mak: 没有那个文件或目录
Makefile:40: /tools/Makefile: 没有那个文件或目录
Makefile:41: /ffbuild/common.mak: 没有那个文件或目录
Makefile:97: /libavutil/Makefile: 没有那个文件或目录
Makefile:97: /ffbuild/library.mak: 没有那个文件或目录
Makefile:99: /fftools/Makefile: 没有那个文件或目录
Makefile:100: /doc/Makefile: 没有那个文件或目录
Makefile:101: /doc/examples/Makefile: 没有那个文件或目录
Makefile:167: /tests/Makefile: 没有那个文件或目录
make: *** 没有规则可以创建目标“/tests/Makefile”。 停止。
Makefile:2: ffbuild/config.mak: 没有那个文件或目录
Makefile:40: /tools/Makefile: 没有那个文件或目录
Makefile:41: /ffbuild/common.mak: 没有那个文件或目录
Makefile:97: /libavutil/Makefile: 没有那个文件或目录
Makefile:97: /ffbuild/library.mak: 没有那个文件或目录
Makefile:99: /fftools/Makefile: 没有那个文件或目录
Makefile:100: /doc/Makefile: 没有那个文件或目录
Makefile:101: /doc/examples/Makefile: 没有那个文件或目录
Makefile:167: /tests/Makefile: 没有那个文件或目录
make: *** 没有规则可以创建目标“/tests/Makefile”。 停止。
./configure --disable-x86asm
生成相关配置
如果是相关参数中的文件没有找到,检查脚本中的反斜杠 \
换行符是否都有,像笔者这里之前测试就马虎忘记写了一行,所以有了如下错误:
--prefix=out/lib: 没有那个文件或目录