This project provides pre-compiled Opus audio codec libraries for Android NDK, including support for multiple architectures (armeabi-v7a, arm64-v8a, x86, x86_64).
- Features
- Requirements
- Installation
- Usage
- API Documentation
- Building
- Contributing
- License
- Acknowledgments
- Multiple Architecture Support: Build for armeabi-v7a, arm64-v8a, x86, x86_64
- Complete Codec Stack: Includes libogg, libopus, and libopusenc
- Android NDK Integration: Easy integration with Android projects
- Optimized Performance: Compiled with -O2 optimization flags
- Latest Versions: Uses Opus 1.5.2, libopusenc 0.2.1, and libogg 1.3.6
- Android NDK: r21 or later
- Android API Level: 21 (Android 5.0) or higher
- NDK Build System: Uses ndk-build
- Clone this repository:
git clone https://github.com/yourusername/opus-android.git
cd opus-android- Copy the following files to your Android project:
Android.mkto yourjni/directoryApplication.mkto yourjni/directory- Source directories:
ogg/,opus/,libopusenc/
- Use the pre-compiled libraries from the
libs/directory - Add them to your Android project's
jniLibs/folder
#include <opusenc.h>
#include <ogg/ogg.h>
// Initialize encoder
OggOpusEnc *enc = ope_encoder_create_file("output.opus",
48000, 2, 0, NULL);
if (!enc) {
// Handle error
}
// Encode audio data
ope_encoder_write(enc, pcm_data, frame_size);
// Clean up
ope_encoder_drain(enc);
ope_encoder_destroy(enc);#include <opus/opus.h>
// Create decoder
OpusDecoder *decoder = opus_decoder_create(48000, 2, NULL);
if (!decoder) {
// Handle error
}
// Decode audio data
int decoded_samples = opus_decode(decoder,
opus_packet,
packet_length,
pcm_output,
max_frame_size,
0);
// Clean up
opus_decoder_destroy(decoder);# Include in your Android.mk
include $(CLEAR_VARS)
LOCAL_MODULE := your-native-module
LOCAL_SRC_FILES := your-native-code.c
LOCAL_SHARED_LIBRARIES := opus opusenc ogg
LOCAL_LDLIBS := -llog -lm
include $(BUILD_SHARED_LIBRARY)ope_encoder_create_file(): Create OggOpus encoder for file outputope_encoder_write(): Write PCM data to encoderope_encoder_drain(): Flush remaining dataopus_decoder_create(): Create Opus decoderopus_decode(): Decode Opus packet to PCM
For complete API reference, see:
# Ensure Android NDK is installed
export NDK_PATH=/path/to/android-ndk
export PATH=$PATH:$NDK_PATH# Build all architectures
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk
# Build specific architecture
ndk-build NDK_PROJECT_PATH=. APP_ABI=arm64-v8a
# Clean build
ndk-build cleanCompiled libraries will be placed in:
libs/
├── armeabi-v7a/
│ ├── libogg.so
│ ├── libopus.so
│ └── libopusenc.so
├── arm64-v8a/
│ ├── libogg.so
│ ├── libopus.so
│ └── libopusenc.so
├── x86/
│ ├── libogg.so
│ ├── libopus.so
│ └── libopusenc.so
└── x86_64/
├── libogg.so
├── libopus.so
└── libopusenc.so
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
The underlying libraries have their own licenses:
- Opus: BSD 3-Clause License
- libogg: BSD 3-Clause License
- libopusenc: BSD 3-Clause License
- Opus Codec Team for the excellent audio codec
- Xiph.Org Foundation for Ogg container format
- Android NDK team for the native development toolkit
本项目为 Android NDK 提供预编译的 Opus 音频编解码库,支持多种架构(armeabi-v7a、arm64-v8a、x86、x86_64)。
- 多架构支持: 支持 armeabi-v7a、arm64-v8a、x86、x86_64 架构
- 完整编解码栈: 包含 libogg、libopus 和 libopusenc
- Android NDK 集成: 与 Android 项目轻松集成
- 性能优化: 使用 -O2 优化标志编译
- 最新版本: 使用 Opus 1.5.2、libopusenc 0.2.1 和 libogg 1.3.6
- Android NDK: r21 或更高版本
- Android API 级别: 21 (Android 5.0) 或更高
- NDK 构建系统: 使用 ndk-build
- 克隆此仓库:
git clone https://github.com/yourusername/opus-android.git
cd opus-android- 将以下文件复制到您的 Android 项目:
Android.mk复制到您的jni/目录Application.mk复制到您的jni/目录- 源码目录:
ogg/、opus/、libopusenc/
- 使用
libs/目录中的预编译库 - 将它们添加到您的 Android 项目的
jniLibs/文件夹
#include <opusenc.h>
#include <ogg/ogg.h>
// 初始化编码器
OggOpusEnc *enc = ope_encoder_create_file("output.opus",
48000, 2, 0, NULL);
if (!enc) {
// 处理错误
}
// 编码音频数据
ope_encoder_write(enc, pcm_data, frame_size);
// 清理资源
ope_encoder_drain(enc);
ope_encoder_destroy(enc);#include <opus/opus.h>
// 创建解码器
OpusDecoder *decoder = opus_decoder_create(48000, 2, NULL);
if (!decoder) {
// 处理错误
}
// 解码音频数据
int decoded_samples = opus_decode(decoder,
opus_packet,
packet_length,
pcm_output,
max_frame_size,
0);
// 清理资源
opus_decoder_destroy(decoder);# 在您的 Android.mk 中包含
include $(CLEAR_VARS)
LOCAL_MODULE := your-native-module
LOCAL_SRC_FILES := your-native-code.c
LOCAL_SHARED_LIBRARIES := opus opusenc ogg
LOCAL_LDLIBS := -llog -lm
include $(BUILD_SHARED_LIBRARY)ope_encoder_create_file(): 创建用于文件输出的 OggOpus 编码器ope_encoder_write(): 向编码器写入 PCM 数据ope_encoder_drain(): 刷新剩余数据opus_decoder_create(): 创建 Opus 解码器opus_decode(): 将 Opus 数据包解码为 PCM
完整 API 参考请参见:
# 确保 Android NDK 已安装
export NDK_PATH=/path/to/android-ndk
export PATH=$PATH:$NDK_PATH# 构建所有架构
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk
# 构建特定架构
ndk-build NDK_PROJECT_PATH=. APP_ABI=arm64-v8a
# 清理构建
ndk-build clean编译后的库将放置在:
libs/
├── armeabi-v7a/
│ ├── libogg.so
│ ├── libopus.so
│ └── libopusenc.so
├── arm64-v8a/
│ ├── libogg.so
│ ├── libopus.so
│ └── libopusenc.so
├── x86/
│ ├── libogg.so
│ ├── libopus.so
│ └── libopusenc.so
└── x86_64/
├── libogg.so
├── libopus.so
└── libopusenc.so
欢迎贡献代码!请随时提交 Pull Request。对于重大更改,请先创建 issue 讨论您想要更改的内容。
- Fork 此仓库
- 创建您的功能分支 (
git checkout -b feature/AmazingFeature) - 提交您的更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开 Pull Request
本项目采用 BSD 3-Clause 许可证 - 详情请参阅 LICENSE 文件。
底层库有自己的许可证:
- Opus: BSD 3-Clause 许可证
- libogg: BSD 3-Clause 许可证
- libopusenc: BSD 3-Clause 许可证
- Opus Codec 团队 提供的出色音频编解码器
- Xiph.Org 基金会 提供的 Ogg 容器格式
- Android NDK 团队提供的原生开发工具包
⭐ 如果这个项目对您有帮助,请给我们一个 Star!
Made with ❤️ for Android Audio Development