opus音频编解码简介

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

1.opus简介

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

opus可@ C Y l ] W 3 x以处理各种音频A 6 : i F ; i V应用,包括IP语音,视r } C ) t p z - R频会议,游戏内聊天K C V : ( u V,甚至远程现场音乐表演。支持的特性包括:

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

2.opus主要接口

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

OPUS_EXPORT OPUS_WARN_UNUSED_RESUL3 O P ) @T OpusEncoder *opus_encoder_create(
opus_int32 Fs,
iW 4 d ] n 3 P knt channels,
int application,
int *error
);
OPUS_EXPORT int opus? T v % v q i Q_encoder_i4 Q L E Tnit(
Opush 8 G  F ] k 5Encodel V l Br *st0 d p p h 7 6 b C,
opus_int32 Fs,
int channels,
int application
) OPUS_ARG_= j + s ) J dNONNULL(1);
OP& [ W $ r x m ! 8US_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode(
OpusEncoder *st,
const opus_int16 *pcm,
int frame_size,
unsigned char *dataY a g t ! / v I,
opus_int32 max_data_bytes
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_v  S d 9 / / T eARG_NONNULL(4);
OPUS_EXPORT int opus_encoder_ctl(OpusEncodN : t ^ i Ker *st, int request, ...) OPUS_ARG_NONNULL(1);
OPUS_EXPORT void opus_encoder_dest9 x P 5 E 5 6roy(OpusEncode# w G % : d fr *st);

(2)decode接口

OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_h e 1 t f `size(int channels);
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_crz # q eate(
opus_int32 Fs,
int channels,
int *error
);
OPUS_EXPORT int opus_decoder_init(
OpusDecoder *st,
opus_int32 Fs,
int channels
) OPUS_ARG_NONNULL(1);
Ox Q % KPUS_EXPORT OPUS_R f Y $WARN_U( [ { :NUSED_RESULT int opus_decodeS c l ? G O v $ (
OpusDecoder *st,
const unsigneh V |d char *data,
opus_int32 len,
opus_int16 *pcm,
int frame_size,
inO P 4t decode_# e : ;fec
) OPUS_ARG_NONNULL(1) O^ L W 0 [ 0PUS0 Q 7 b w T b 1 ?_ARGJ w ( 8 `_NONNULL(4);
OPUS_EXPORT int opus_decoder_s C 3 [ :ctl(OpusDecoder *st, int request, ...) OPUS_9 ` GARG_NONNULL(1);
OPUS_EXPORT voQ m n @ ~id opus_deco_ o Y $ 9 r c dder_destroy(OpusDecoder *st);

opus项目地址:Y Q O 9 u . l b
https://www.opus-codec.o_ I { Z 8 D p = wrg/