目录
- 一、ffmpeg源码下载
- 二、下载ubuntu对应的NDK,并解压到opt下
-
- 1、下载并解压
- [2、配置 ~/.bashrc](#2、配置 ~/.bashrc)
- 三、源码编译、
- 四、编译过程中遇到的问题
-
- [1、/opt/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang not found](#1、/opt/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang not found)
- [2、aarch64-linux-android21-nm not found](#2、aarch64-linux-android21-nm not found)
- [3、aarch64-linux-android21-strip not found](#3、aarch64-linux-android21-strip not found)
一、ffmpeg源码下载
1、安装git(用于下载ffmpeg源码)
powershell
sudo apt update
sudo apt install git
2、创建源码目录,下载ffmpeg源码
powershell
mkdir ffmpeg_src
cd ffmpeg_src
git clone https://github.com/FFmpeg/FFmpeg.git
二、下载ubuntu对应的NDK,并解压到opt下
1、下载并解压
powershell
https://github.com/android/ndk/wiki/Unsupported-Downloads // 下载地址
sudo unzip android-ndk-r21e-linux-x86_64.zip -d /opt/
2、配置 ~/.bashrc
powershell
export ANDROID_NDK_HOME=/opt/android-ndk-r21e
export PATH=$PATH:$ANDROID_NDK_HOME
source ~/.bashrc
三、源码编译、
1、创建编译脚本
powershell
touch build_android.sh
vim build_android.sh
2、脚本文件内容
powershell
#设置 NDK 路径
NDK=/opt/android-ndk-r25c
#设置目标平台和架构
API=21
ARCH=arm64
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
SYSROOT=$TOOLCHAIN/sysroot
PREFIX=$(pwd)/android/$ARCH
#配置 FFmpeg
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-programs \
--disable-avdevice \
--enable-avfilter \
--enable-postproc \
--enable-swresample \
--enable-swscale \
--disable-encoders \
--disable-muxers \
--disable-filters \
--enable-jni \
--enable-mediacodec \
--cross-prefix=$TOOLCHAIN/bin/aarch64-linux-android$API- \
--target-os=android \
--arch=$ARCH \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic" \
--extra-ldflags=""
#编译并安装
make clean
make -j4
make install
3、设置可执行权限并运行
powershell
sudo chmod+x build_android.sh
./build_android.sh
4、编译的结果在源码根目录下的android文件夹下

四、编译过程中遇到的问题
1、/opt/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang not found
解决办法,进入到toolchains/llvm/prebuilt/linux-x86_64/bin/中看看aarch64-linux-android21-clang是否存在,如果不存在,就找一个存在的版本,并修改build_android.sh 中的API的值
2、aarch64-linux-android21-nm not found
toolchains/llvm/prebuilt/linux-x86_64/bin中已经没有这个工具了,可以用llvm-nm代替。直接把llvm-nm拷贝一份,命名为aarch64-linux-android21-nm
3、aarch64-linux-android21-strip not found
toolchains/llvm/prebuilt/linux-x86_64/bin中已经没有这个工具了,可以用llvm-strip代替。直接把llvm-strip拷贝一份,命名为aarch64-linux-android21-strip