Ubuntu虚拟机NDK编译ffmpeg

目录

一、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

相关推荐
bcbobo21cn39 分钟前
Linux命令的命令历史
linux·histsize·histfile
jingyu飞鸟1 小时前
linux系统源代码安装apache、编译隐藏版本号
linux·运维·apache
世事如云有卷舒1 小时前
Ubunt20.04搭建GitLab服务器,并借助cpolar实现公网访问
linux·服务器·gitlab
2401_858286112 小时前
OS15.【Linux】gdb调试器的简单使用
linux·运维·服务器·开发语言·gdb
zjw_rp5 小时前
centos停止维护后更换yum源
linux·运维·centos
行止65 小时前
OpenStack云平台管理
linux·openstack
岁岁岁平安6 小时前
CentOS-7-x86_64解决:使用NAT模式无法ping通www.baidu.com或无法ping 8.8.8.8问题。
linux·运维·centos·centos-7
运维小贺6 小时前
各服务器厂商调整BIOS睿频教程
linux·运维·服务器·性能优化
特种加菲猫6 小时前
指尖上的魔法:优雅高效的Linux命令手册
linux·笔记
★Orange★7 小时前
Linux Kernel kfifo 实现和巧妙设计
linux·运维·算法