23 #include <opus_multistream.h>
53 0, 1, 1, 2, 2, 2, 2, 3
64 { 0, 4, 1, 2, 3, 5, 6 },
65 { 0, 6, 1, 2, 3, 4, 5, 7 },
76 { 0, 1, 5, 6, 2, 4, 3 },
77 { 0, 1, 6, 7, 4, 5, 2, 3 },
81 int coupled_stream_count,
88 bytestream_put_byte(&p, 1);
89 bytestream_put_byte(&p, channels);
90 bytestream_put_le16(&p, avctx->
delay);
92 bytestream_put_le16(&p, 0);
96 bytestream_put_byte(&p, channels <= 8 ? 1 : 255);
97 bytestream_put_byte(&p, stream_count);
98 bytestream_put_byte(&p, coupled_stream_count);
101 bytestream_put_byte(&p, 0);
112 "Quality-based encoding not supported, "
113 "please specify a bitrate and VBR setting.\n");
117 ret = opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(avctx->
bit_rate));
118 if (ret != OPUS_OK) {
120 "Failed to set bitrate: %s\n", opus_strerror(ret));
124 ret = opus_multistream_encoder_ctl(enc,
128 "Unable to set complexity: %s\n", opus_strerror(ret));
130 ret = opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(!!opts->
vbr));
133 "Unable to set VBR: %s\n", opus_strerror(ret));
135 ret = opus_multistream_encoder_ctl(enc,
136 OPUS_SET_VBR_CONSTRAINT(opts->
vbr == 2));
139 "Unable to set constrained VBR: %s\n", opus_strerror(ret));
141 ret = opus_multistream_encoder_ctl(enc,
145 "Unable to set expected packet loss percentage: %s\n",
149 ret = opus_multistream_encoder_ctl(enc,
153 "Unable to set maximum bandwidth: %s\n", opus_strerror(ret));
162 const uint8_t *channel_mapping;
165 int coupled_stream_count, header_size,
frame_size;
175 "Channel layout undefined for %d channels.\n", avctx->
channels);
180 32000 * coupled_stream_count;
182 "No bit rate set. Defaulting to %d bps.\n", avctx->
bit_rate);
187 "Please choose a value between 500 and %d.\n", avctx->
bit_rate,
193 switch (frame_size) {
198 "LPC mode cannot be used with a frame duration of less "
199 "than 10ms. Enabling restricted low-delay mode.\n"
200 "Use a longer frame duration if this is not what you want.\n");
213 "Frame duration must be exactly one of: 2.5, 5, 10, 20, 40 or 60.\n",
220 "Compression level must be in the range 0 to 10. "
221 "Defaulting to 10.\n");
246 "Invalid frequency cutoff: %d. Using default maximum bandwidth.\n"
247 "Cutoff frequency must be exactly one of: 4000, 6000, 8000, 12000 or 20000.\n",
255 coupled_stream_count,
258 if (ret != OPUS_OK) {
260 "Failed to create encoder: %s\n", opus_strerror(ret));
265 if (ret != OPUS_OK) {
287 ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->
delay));
290 "Unable to get number of lookahead samples: %s\n",
303 opus_multistream_encoder_destroy(enc);
312 const int sample_size = avctx->
channels *
323 audio = frame->
data[0];
338 ret = opus_multistream_encode_float(opus->
enc, (
float *)audio,
342 ret = opus_multistream_encode(opus->
enc, (opus_int16 *)audio,
348 "Error encoding frame: %s\n", opus_strerror(ret));
366 opus_multistream_encoder_destroy(opus->
enc);
376 #define OFFSET(x) offsetof(LibopusEncContext, opts.x)
377 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
379 {
"application",
"Intended application type",
OFFSET(application),
AV_OPT_TYPE_INT, { .i64 = OPUS_APPLICATION_AUDIO }, OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY,
FLAGS,
"application" },
380 {
"voip",
"Favor improved speech intelligibility", 0,
AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_VOIP }, 0, 0,
FLAGS,
"application" },
381 {
"audio",
"Favor faithfulness to the input", 0,
AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_AUDIO }, 0, 0,
FLAGS,
"application" },
382 {
"lowdelay",
"Restrict to only the lowest delay modes", 0,
AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_RESTRICTED_LOWDELAY }, 0, 0,
FLAGS,
"application" },
383 {
"frame_duration",
"Duration of a frame in milliseconds",
OFFSET(frame_duration),
AV_OPT_TYPE_FLOAT, { .dbl = 10.0 }, 2.5, 60.0,
FLAGS },
401 {
"compression_level",
"10" },
406 48000, 24000, 16000, 12000, 8000, 0,