ffmpeg编译Android版本的armeabi-v7a和arm64-v8a

2024-05-30 04:18

本文主要是介绍ffmpeg编译Android版本的armeabi-v7a和arm64-v8a,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近在做一个Android播放音频的项目,整个音频处理流程:接收网络音频流aac格式,本地解码成pcm原始音频码流并播放。

其中解码aac音频到pcm的过程使用到了ffmpeg,需要编译ffmpeg生成Android平台上需要的so文件,通过搜索各种网络资料,也是折腾了好久终于可以生成armeabi-v7a和arm64-v8a的so文件,所以在这记录下整个编译流程,主要参考的就是参考文档连接中第一篇博客,此外也添加了编译过程中各种报错的解决方案:

1. 准备编译环境,使用Linux系统,不要尝试Windows系统,切记~

2. 下载ffmpeg源码,并解压:

https://www.ffmpeg.org/releases/ffmpeg-3.4.tar.gz

3. 解压ffmpeg

tar -xzvf ffmpeg-3.4.tar.gz

4. 下载ndk,使用的android-ndk-r14b-linux-x86_64.zip

https://developer.android.google.cn/ndk/downloads/older_releases

5. 解压ndk,并生成自己的tools-chains目录

For arm: python make_standalone_toolchain.py --arch arm --stl=libc++ --install-dir /home/(your computer name or user name)/my_toolchains/arm --force

For arm64: python make_standalone_toolchain.py --arch arm64 --stl=libc++ --install-dir /home/(your computer name or user name)/my_toolchains/arm64 --force

For x86: python make_standalone_toolchain.py --arch x86 --stl=libc++ --install-dir /home/(your computer name or user name)/my_toolchains/x86 --force

For x86_64: python make_standalone_toolchain.py --arch x86_64 --stl=libc++ --install-dir /home/(your computer name or user name)/my_toolchains/x86_64 --force

For arm: python make_standalone_toolchain.py --arch arm --api 24 --stl=libc++ --install-dir /home/(your computer name or user name)/my_toolchains/arm --force

6. 编写编译arm64脚本,build_android_arm64.sh,并运行编译得到相应的so

#!/bin/bashTOOLCHAIN=/root/wzj_ffmpeg/my_toolchains/arm64
CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
rm -f $(pwd)/compat/strtod.o
function build_one
{
./configure --prefix=$PREFIX --enable-shared --disable-static --enable-protocol=file --enable-pic --enable-small --disable-programs --disable-doc --disable-symver --target-os=android --enable-cross-compile --cross-prefix=$CROSS_PREFIX --extra-cflags="-Os -fpic $ADDI_CFLAGS" --extra-ldflags="$ADDI_LDFLAGS" --sysroot=$TOOLCHAIN/sysroot $ADDITIONAL_CONFIG_FLAG
make clean
make -j8
make install
}CPU=arm64-v8a
mkdir -p $(pwd)/android/$CPU
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-march=armv8-a"
ADDI_LDFLAGS="-L$TOOLCHAIN/sysroot/usr/lib"
ADDITIONAL_CONFIG_FLAG="--arch=aarch64 --enable-yasm"
build_one

7. 编写编译armv7a脚本,build_android_armv7a.sh,并运行编译得到相应的so

#!/bin/bashTOOLCHAIN=/root/wzj_ffmpeg/my_toolchains/arm
CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
rm -f $(pwd)/compat/strtod.o
function build_one
{
./configure --prefix=$PREFIX --enable-shared --disable-static --enable-protocol=file --enable-pic --enable-small --disable-programs --disable-doc --disable-symver --target-os=android --enable-cross-compile --cross-prefix=$CROSS_PREFIX --extra-cflags="-Os -fpic $ADDI_CFLAGS" --extra-ldflags="$ADDI_LDFLAGS" --sysroot=$TOOLCHAIN/sysroot $ADDITIONAL_CONFIG_FLAG
make clean
make -j8
make install
}CPU=armeabi-v7a
mkdir -p $(pwd)/android/$CPU
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm -march=armv7-a -mfloat-abi=softfp -mthumb -mfpu=vfpv3-d16 -mtune=cortex-a8"
ADDI_LDFLAGS="-marm -march=armv7-a -Wl,--fix-cortex-a8"
ADDITIONAL_CONFIG_FLAG="--arch=arm --disable-asm"
build_one

 

参考文档连接:

https://github.com/ejoker88/FFmpeg-3.4-Android/wiki/Tutorial-:-FFmpeg-3.4-for-Android

https://github.com/ejoker88/FFmpeg-3.4-Android

https://yesimroy.gitbooks.io/android-note/content/compile_ffmpeg_for_android.html

https://www.jianshu.com/p/feab970fd74c

这篇关于ffmpeg编译Android版本的armeabi-v7a和arm64-v8a的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1015555

相关文章

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

在macOS上安装jenv管理JDK版本的详细步骤

《在macOS上安装jenv管理JDK版本的详细步骤》jEnv是一个命令行工具,正如它的官网所宣称的那样,它是来让你忘记怎么配置JAVA_HOME环境变量的神队友,:本文主要介绍在macOS上安装... 目录前言安装 jenv添加 JDK 版本到 jenv切换 JDK 版本总结前言China编程在开发 Java

Go语言编译环境设置教程

《Go语言编译环境设置教程》Go语言支持高并发(goroutine)、自动垃圾回收,编译为跨平台二进制文件,云原生兼容且社区活跃,开发便捷,内置测试与vet工具辅助检测错误,依赖模块化管理,提升开发效... 目录Go语言优势下载 Go  配置编译环境配置 GOPROXYIDE 设置(VS Code)一些基本

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

java使用protobuf-maven-plugin的插件编译proto文件详解

《java使用protobuf-maven-plugin的插件编译proto文件详解》:本文主要介绍java使用protobuf-maven-plugin的插件编译proto文件,具有很好的参考价... 目录protobuf文件作为数据传输和存储的协议主要介绍在Java使用maven编译proto文件的插件

Android ClassLoader加载机制详解

《AndroidClassLoader加载机制详解》Android的ClassLoader负责加载.dex文件,基于双亲委派模型,支持热修复和插件化,需注意类冲突、内存泄漏和兼容性问题,本文给大家介... 目录一、ClassLoader概述1.1 类加载的基本概念1.2 android与Java Class

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

Android DataBinding 与 MVVM使用详解

《AndroidDataBinding与MVVM使用详解》本文介绍AndroidDataBinding库,其通过绑定UI组件与数据源实现自动更新,支持双向绑定和逻辑运算,减少模板代码,结合MV... 目录一、DataBinding 核心概念二、配置与基础使用1. 启用 DataBinding 2. 基础布局

Python中对FFmpeg封装开发库FFmpy详解

《Python中对FFmpeg封装开发库FFmpy详解》:本文主要介绍Python中对FFmpeg封装开发库FFmpy,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、FFmpy简介与安装1.1 FFmpy概述1.2 安装方法二、FFmpy核心类与方法2.1 FF

Android ViewBinding使用流程

《AndroidViewBinding使用流程》AndroidViewBinding是Jetpack组件,替代findViewById,提供类型安全、空安全和编译时检查,代码简洁且性能优化,相比Da... 目录一、核心概念二、ViewBinding优点三、使用流程1. 启用 ViewBinding (模块级