opus是一款开源免费、跨平台的音频编解码器。它适用于互联网上的交互式语音和音乐传输,但也适用于存储和流媒体应用。

1.opus简介

opus的前身是celt编码器。通过诸多的对比测试,低码率下Opus完胜曾经优势明显的HE AAC,中码率就已经可以媲敌码率高出30%左右的AAC格式,而高码率下更接近原始音频。

opus可以处理各种音频应用,包括IP语音,视频会议,游戏内聊天,甚至远程现场音乐表演。支持的特性包括:

比特率从6 kb/s到510 kb/s
采样率从8 kHz(窄带)到48 kHz(全频段)
帧大小从2.5 ms到60 ms
支持恒定比特率(CBR)和可变比特率(VBR)
从窄带到全频段的音频带宽
支持演讲和音乐
支持单声道和立体声
最多支持255个频道(多流帧)
可动态调整比特率、音频带宽和帧大小
良好的丢失鲁棒性和丢包隐蔽性(PLC)
浮点和定点实现

2.opus主要接口

opus的接口声明在include/opus.h中 (1)encode接口

OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create(
    opus_int32 Fs,
    int channels,
    int application,
    int *error
);
OPUS_EXPORT int opus_encoder_init(
    OpusEncoder *st,
    opus_int32 Fs,
    int channels,
    int application
) OPUS_ARG_NONNULL(1);
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode(
    OpusEncoder *st,
    const opus_int16 *pcm,
    int frame_size,
    unsigned char *data,
    opus_int32 max_data_bytes
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st);

(2)decode接口

OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels);
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create(
    opus_int32 Fs,
    int channels,
    int *error
);
OPUS_EXPORT int opus_decoder_init(
    OpusDecoder *st,
    opus_int32 Fs,
    int channels
) OPUS_ARG_NONNULL(1);
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(
    OpusDecoder *st,
    const unsigned char *data,
    opus_int32 len,
    opus_int16 *pcm,
    int frame_size,
    int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);

3.其他项目:

3.1opus-tools

opus-tools包含了一组将opus与wav进行编解码的工具。

3.2opusfile

opusfile提供了一个高级API,用于在.opus文件中进行解码和查找,类似于libvorbisfile为Vorbis提供的功能。

3.3libopusenc

Libopusenc提供了用于创建.opus文件和流的高级API。

opus项目地址: https://www.opus-codec.org/