【Android RTMP】音频数据采集编码 ( 音频数据采集编码 | AAC 高级音频编码 | FAAC 编码器 | Ubuntu 交叉编译 FAAC 编码器 )
文章目录
一、 音频数据采集、编码
1 . 音频数据采集 : Android 中有两种方式可以采集音频数据 ;
① Java 层使用 AudioRecord ;
② Native 层使用 OpenSL ES ;
2 . 音频数据编码 :
① 视频数据回顾 : 手机使用 Camera 采集 NV21 格式的图像数据 , x264 编码库将图像数据编码成 H.264 格式的视频数据 ;
② 音频数据编码 : 手机端采集 PCM 音频采样数据 , FAAC 编码库将 PCM 采样编码成 AAC 格式的音频数据 ;
二、 AAC 高级音频编码
1 . 高级音频编码 ( Advanced Audio Coding , AAC ) :
① MPEG-2 AAC 编码 : 初期 AAC 编码时基于 MPEG-2 有损数字音频压缩编码标准 , 称为 MPEG-2 AAC 编码 ;
② MPEG-4 AAC 编码 : 后期 AAC 编码又基于 MPEG-4 标准基础上添加了 PNS 技术 , 称为 MPEG-4 AAC 编码 ;
③ 与 MP3 编码对比 : AAC 压缩编码音质要高于 MP3 格式 ;
一般情况下 , 多媒体压缩格式 , 视频采用 H.264 格式压缩编码 , 音频采用 AAC 格式压缩编码 ;
三、 FAAC 编码器
1 . FAAC 编码器 : 在 Android 平台推荐使用 FAAC 编码器 , 免费 ; FAAC ( Freeware Advanced Audio Coder ) ;
2 . FAAC 编码器下载 :
① 官方网站 : 可以在 FAAC 官网 下载 FAAC 开源库 ;
② 下载 FAAC 编码库 : 点击此处 , 进入下载页面
上述界面中 FAAD2 是解码库 , FAAC 是编码库 ;
这里下载 FAAC Source code 中的 TAR.GZ 文件 ;
四、 Ubuntu 18.04.4 交叉编译 FAAC 编码器
1 . 将下载的 FAAC 编码器源码拷贝到 Ubuntu 的 /root/rtmp 目录下 ;
2 . 解压源码 :
$ tar xvf faac-1.29.9.2.tar.gz
3 . 查看源码路径 : 该源码中也有 configure 脚本 , 用于配置生成 Makefile 文件 ;
root@octopus:~/rtmp# cd faac-1.29.9.2
root@octopus:~/rtmp/faac-1.29.9.2# ls
aclocal.m4 ChangeLog compile config.h.in configure COPYING docs include install-sh ltmain.sh Makefile.in NEWS TODO
AUTHORS common config.guess config.sub configure.ac depcomp frontend INSTALL libfaac Makefile.am missing README
4 . 查看 configure 帮助信息 : 执行 ./configure --help
命令 , 可以查看编译配置信息 ;
$ ./configure --help
# 默认情况下, 编译 FAAC 时, 会同时编译静态库和动态库, Android 交叉编译推荐只编译静态库
--enable-shared[=PKGS] build shared libraries [default=yes]
--enable-static[=PKGS] build static libraries [default=yes]
# Android 中使用动态库时, 必须指定 pic, 表示编码出与位置无关的代码段
--with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
both]
5 . 交叉编译工具链 :
① 其它开源库的惯例 : 在 FFMPEG 和 x264 交叉编译时 , 都指定了 --cross-prefix 交叉编译工具链前缀 ;
② FAAC 中指定交叉编译工具链的方法 : 在 FAAC 中没有提供该配置 , 那就只能通过环境变量设置 , 将交叉编译工具链的 gcc 设置成环境变量 ;
③ 解析说明 FAAC 中的环境变量 :
Some influential environment variables:
# C 编码器命令行, 即 gcc, 这里可以直接指定交叉编译工具链的 gcc
CC C compiler command
# 指定传递给 gcc 的参数
CFLAGS C compiler flags
# 传递给链接器的参数
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
# 传递给链接器的库
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
# C++ 编译器
CXX C++ compiler command
# C++ 编译器参数
CXXFLAGS C++ compiler flags
LT_SYS_LIBRARY_PATH
User-defined run-time library search path.
CPP C preprocessor
CXXCPP C++ preprocessor
6 . 交叉编译脚本 : 写一个 Shell 脚本 , 辅助交叉编译 FAAC 静态库 ;
参考之前的 FFMPEG 和 x264 的 Shell 编译脚本 ;
版本注意事项 : 基于 android-17 版本进行编译, Android Studio 开发时可以将最小兼容版本配置到 17 ;
#!/bin/bash
# NDK 根目录
NDK_ROOT=/root/NDK/android-ndk-r17c
# TOOLCHAIN 变量指向 gcc g++ 等交叉编译工具所在的目录
TOOLCHAIN=$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
# 具体的交叉编译工具链前缀
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi
# gcc 编译器参数, 这里指定使用 android-17 版本的库进行编译
FLAGS="-isysroot $NDK_ROOT/sysroot -isystem $NDK_ROOT/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=17 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -O0 -fPIC"
# 编译结果输出路径
# 注意这里不能使用 ./android/armeabi-v7a, 报错 error: expected an absolute directory name
# 改成绝对路径, 或者使用下面的方法
PREFIX=`pwd`/android/armeabi-v7a
# FAAC 中没有指定交叉编译工具链的选项, 只能在此处通过环境变量的方式进行指定
# 这里指定使用 android-17 版本的库进行编译
export CC="$CROSS_COMPILE-gcc --sysroot=$NDK_ROOT/platforms/android-17/arch-arm"
# 指定 gcc 编译器的参数
export CFLAGS="$FLAGS"
# 配置 Makefile 生成规则
./configure \
--prefix=$PREFIX \
--host=arm-linux \
--with-pic \
--enable-shared=no
# 清除之前的编译内容
make clean
# 开启新的 FFMPEG 编译安装过程
make install
7 . 执行编译脚本 :
# 赋予 build.sh 脚本 执行权限
$ chmod -R 777 build.sh
# 执行编译脚本
$ ./build.sh
8 . 编译完毕 :
root@octopus:~/rtmp/faac-1.29.9.2# ls
aclocal.m4 build.sh compile config.h.in config.sub COPYING frontend install-sh ltmain.sh Makefile.in README
android ChangeLog config.guess config.log configure depcomp include libfaac Makefile missing stamp-h1
AUTHORS common config.h config.status configure.ac docs INSTALL libtool Makefile.am NEWS TODO
root@octopus:~/rtmp/faac-1.29.9.2# cd android/
root@octopus:~/rtmp/faac-1.29.9.2/android# tree
.
└── armeabi-v7a
├── bin
│ └── faac
├── include
│ ├── faaccfg.h
│ └── faac.h
├── lib
│ ├── libfaac.a
│ └── libfaac.la
└── share
└── man
└── man1
└── faac.1
7 directories, 6 files
root@octopus:~/rtmp/faac-1.29.9.2/android#
相关文章
- android开机动画多长时间_Android开机动画原理分析
- android 浏览器 开发,Android 浏览器的开发实例分享
- android 读取本地数据库db文件(Android sqlite)
- android activity singletask,Android Activity启动模式之singleTask实例详解
- android sdk根目录,Android SDK位置
- android declare-styleable 和style,Android 关于declare-styleable属性的写法….
- robotium android,Robotium 测试Android apk安装包
- android toast 自定义时间,Android 自定义 Toast 显示时间「建议收藏」
- 【软件开发规范六】《Android开发编码规范》
- 【Android 插件化】Hook 插件化框架 ( Hook Activity 启动过程 | 静态代理 )
- 【错误记录】Android Studio 编译报错 ( AppCompat does not support the current theme features )
- 【Android 逆向】ptrace 函数 ( C 标准库 ptrace 函数简介 | ptrace 函数真实作用 )
- 【ijkplayer】编译 Android 版本的 ijkplayer ③ ( 执行 compile-ffmpeg.sh clean 命令 | 下载并配置 android-ndk-r10e )
- 【错误记录】Android Studio 编译时 lint 检查报错 ( WARNING: DSL element ‘android.dataBinding.enabled‘ is obsolet )
- 【Android UI】贝塞尔曲线 ④ ( 使用 android.graphics.Path 提供的 cubicTo 方法绘制三阶贝塞尔曲线示例 )
- 【错误记录】Android Studio 编译报错 ( Could not resolve com.android.tools.build:gradle:7.4.2. )
- 并非所有Android应用都能够在Windows 11上运行
- 全新Win11预览版上线:遗憾仍不支持Android应用程序
- 代号“Passport”:Android 12代码显示Google正开发可折叠手机
- Android自动化测试经验分享UiObejct.getFromParent()的使用方法
- android自定义窗口标题示例分享
- android开发教程之wifi开发示例