FFmpeg
Loading...
Searching...
No Matches
libopusenc.c
Go to the documentation of this file.
1/*
2 * Opus encoder using libopus
3 * Copyright (c) 2012 Nathan Caldwell
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <opus.h>
23#include <opus_multistream.h>
24
26#include "libavutil/mem.h"
27#include "libavutil/opt.h"
28#include "avcodec.h"
29#include "bytestream.h"
30#include "codec_internal.h"
31#include "encode.h"
32#include "libopus.h"
33#include "opus/tab.h"
34#include "audio_frame_queue.h"
35#include "vorbis_data.h"
36
37typedef struct LibopusEncOpts {
38 int vbr;
41 int fec;
47 int dtx;
48#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
49 int apply_phase_inv;
50#endif
52
62
63static const uint8_t opus_coupled_streams[8] = {
64 0, 1, 1, 2, 2, 2, 2, 3
65};
66
67/* Opus internal to Vorbis channel order mapping written in the header */
68static const uint8_t opus_vorbis_channel_map[8][8] = {
69 { 0 },
70 { 0, 1 },
71 { 0, 2, 1 },
72 { 0, 1, 2, 3 },
73 { 0, 4, 1, 2, 3 },
74 { 0, 4, 1, 2, 3, 5 },
75 { 0, 4, 1, 2, 3, 5, 6 },
76 { 0, 6, 1, 2, 3, 4, 5, 7 },
77};
78
79/* libavcodec to libopus channel order mapping, passed to libopus */
80static const uint8_t libavcodec_libopus_channel_map[8][8] = {
81 { 0 },
82 { 0, 1 },
83 { 0, 1, 2 },
84 { 0, 1, 2, 3 },
85 { 0, 1, 3, 4, 2 },
86 { 0, 1, 4, 5, 2, 3 },
87 { 0, 1, 5, 6, 2, 4, 3 },
88 { 0, 1, 6, 7, 4, 5, 2, 3 },
89};
90
91static void libopus_write_header(AVCodecContext *avctx, int stream_count,
92 int coupled_stream_count,
93 int mapping_family,
94 const uint8_t *channel_mapping)
95{
96 uint8_t *p = avctx->extradata;
97 int channels = avctx->ch_layout.nb_channels;
98
99 bytestream_put_buffer(&p, "OpusHead", 8);
100 bytestream_put_byte(&p, 1); /* Version */
101 bytestream_put_byte(&p, channels);
102 bytestream_put_le16(&p, avctx->initial_padding * OPUS_TIMESTAMP_RATE /
103 avctx->sample_rate); /* Lookahead */
104 bytestream_put_le32(&p, avctx->sample_rate); /* Original sample rate */
105 bytestream_put_le16(&p, 0); /* Gain of 0dB is recommended. */
106
107 /* Channel mapping */
108 bytestream_put_byte(&p, mapping_family);
109 if (mapping_family != 0) {
110 bytestream_put_byte(&p, stream_count);
111 bytestream_put_byte(&p, coupled_stream_count);
112 bytestream_put_buffer(&p, channel_mapping, channels);
113 }
114}
115
116static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,
118{
119 int ret;
120
121 if (avctx->global_quality) {
122 av_log(avctx, AV_LOG_ERROR,
123 "Quality-based encoding not supported, "
124 "please specify a bitrate and VBR setting.\n");
125 return AVERROR(EINVAL);
126 }
127
128 ret = opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(avctx->bit_rate));
129 if (ret != OPUS_OK) {
130 av_log(avctx, AV_LOG_ERROR,
131 "Failed to set bitrate: %s\n", opus_strerror(ret));
132 return ret;
133 }
134
135 ret = opus_multistream_encoder_ctl(enc,
136 OPUS_SET_COMPLEXITY(opts->complexity));
137 if (ret != OPUS_OK)
138 av_log(avctx, AV_LOG_WARNING,
139 "Unable to set complexity: %s\n", opus_strerror(ret));
140
141 ret = opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(!!opts->vbr));
142 if (ret != OPUS_OK)
143 av_log(avctx, AV_LOG_WARNING,
144 "Unable to set VBR: %s\n", opus_strerror(ret));
145
146 ret = opus_multistream_encoder_ctl(enc,
147 OPUS_SET_VBR_CONSTRAINT(opts->vbr == 2));
148 if (ret != OPUS_OK)
149 av_log(avctx, AV_LOG_WARNING,
150 "Unable to set constrained VBR: %s\n", opus_strerror(ret));
151
152 ret = opus_multistream_encoder_ctl(enc,
153 OPUS_SET_PACKET_LOSS_PERC(opts->packet_loss));
154 if (ret != OPUS_OK)
155 av_log(avctx, AV_LOG_WARNING,
156 "Unable to set expected packet loss percentage: %s\n",
157 opus_strerror(ret));
158
159 ret = opus_multistream_encoder_ctl(enc,
160 OPUS_SET_INBAND_FEC(opts->fec));
161 if (ret != OPUS_OK)
162 av_log(avctx, AV_LOG_WARNING,
163 "Unable to set inband FEC: %s\n",
164 opus_strerror(ret));
165
166 ret = opus_multistream_encoder_ctl(enc,
167 OPUS_SET_DTX(opts->dtx));
168 if (ret != OPUS_OK)
169 av_log(avctx, AV_LOG_WARNING,
170 "Unable to set DTX: %s\n",
171 opus_strerror(ret));
172
173 if (avctx->cutoff) {
174 ret = opus_multistream_encoder_ctl(enc,
175 OPUS_SET_MAX_BANDWIDTH(opts->max_bandwidth));
176 if (ret != OPUS_OK)
177 av_log(avctx, AV_LOG_WARNING,
178 "Unable to set maximum bandwidth: %s\n", opus_strerror(ret));
179 }
180
181#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
182 ret = opus_multistream_encoder_ctl(enc,
183 OPUS_SET_PHASE_INVERSION_DISABLED(!opts->apply_phase_inv));
184 if (ret != OPUS_OK)
185 av_log(avctx, AV_LOG_WARNING,
186 "Unable to set phase inversion: %s\n",
187 opus_strerror(ret));
188#endif
189 return OPUS_OK;
190}
191
193 int max_channels) {
194 if (avctx->ch_layout.nb_channels > max_channels) {
195 av_log(avctx, AV_LOG_ERROR, "Opus mapping family undefined for %d channels.\n",
196 avctx->ch_layout.nb_channels);
197 return AVERROR(EINVAL);
198 }
199
200 return 0;
201}
202
203static int libopus_check_vorbis_layout(AVCodecContext *avctx, int mapping_family) {
205
207 av_log(avctx, AV_LOG_WARNING,
208 "No channel layout specified. Opus encoder will use Vorbis "
209 "channel layout for %d channels.\n", avctx->ch_layout.nb_channels);
211 char name[32];
212
214 av_log(avctx, AV_LOG_ERROR,
215 "Invalid channel layout %s for specified mapping family %d.\n",
216 name, mapping_family);
217
218 return AVERROR(EINVAL);
219 }
220
221 return 0;
222}
223
225 AVCodecContext *avctx,
226 int mapping_family,
227 const uint8_t ** channel_map_result)
228{
229 const uint8_t * channel_map = NULL;
230 int ret;
231
232 switch (mapping_family) {
233 case -1:
235 if (ret == 0) {
236 ret = libopus_check_vorbis_layout(avctx, mapping_family);
237 /* Channels do not need to be reordered. */
238 }
239
240 break;
241 case 0:
243 if (ret == 0) {
244 ret = libopus_check_vorbis_layout(avctx, mapping_family);
245 }
246 break;
247 case 1:
248 /* Opus expects channels to be in Vorbis order. */
250 if (ret == 0) {
251 ret = libopus_check_vorbis_layout(avctx, mapping_family);
253 }
254 break;
255 case 255:
256 ret = libopus_check_max_channels(avctx, 254);
257 break;
258 default:
259 av_log(avctx, AV_LOG_WARNING,
260 "Unknown channel mapping family %d. Output channel layout may be invalid.\n",
261 mapping_family);
262 ret = 0;
263 }
264
265 *channel_map_result = channel_map;
266 return ret;
267}
268
270{
271 LibopusEncContext *opus = avctx->priv_data;
272 OpusMSEncoder *enc;
273 uint8_t libopus_channel_mapping[255];
274 int ret = OPUS_OK;
275 int channels = avctx->ch_layout.nb_channels;
276 int av_ret;
277 int coupled_stream_count, header_size, frame_size;
278 int mapping_family;
279
281 switch (frame_size) {
282 case 120:
283 case 240:
284 if (opus->opts.application != OPUS_APPLICATION_RESTRICTED_LOWDELAY)
285 av_log(avctx, AV_LOG_WARNING,
286 "LPC mode cannot be used with a frame duration of less "
287 "than 10ms. Enabling restricted low-delay mode.\n"
288 "Use a longer frame duration if this is not what you want.\n");
289 /* Frame sizes less than 10 ms can only use MDCT mode, so switching to
290 * RESTRICTED_LOWDELAY avoids an unnecessary extra 2.5ms lookahead. */
291 opus->opts.application = OPUS_APPLICATION_RESTRICTED_LOWDELAY;
293 case 480:
294 case 960:
295 case 1920:
296 case 2880:
297#ifdef OPUS_FRAMESIZE_120_MS
298 case 3840:
299 case 4800:
300 case 5760:
301#endif
302 opus->opts.packet_size =
303 avctx->frame_size = frame_size * avctx->sample_rate /
305 break;
306 default:
307 av_log(avctx, AV_LOG_ERROR, "Invalid frame duration: %g.\n"
308 "Frame duration must be exactly one of: 2.5, 5, 10, 20, 40"
309#ifdef OPUS_FRAMESIZE_120_MS
310 ", 60, 80, 100 or 120.\n",
311#else
312 " or 60.\n",
313#endif
314 opus->opts.frame_duration);
315 return AVERROR(EINVAL);
316 }
317
318 if (avctx->compression_level < 0 || avctx->compression_level > 10) {
319 av_log(avctx, AV_LOG_WARNING,
320 "Compression level must be in the range 0 to 10. "
321 "Defaulting to 10.\n");
322 opus->opts.complexity = 10;
323 } else {
324 opus->opts.complexity = avctx->compression_level;
325 }
326
327 if (avctx->cutoff) {
328 switch (avctx->cutoff) {
329 case 4000:
331 break;
332 case 6000:
334 break;
335 case 8000:
337 break;
338 case 12000:
340 break;
341 case 20000:
343 break;
344 default:
345 av_log(avctx, AV_LOG_WARNING,
346 "Invalid frequency cutoff: %d. Using default maximum bandwidth.\n"
347 "Cutoff frequency must be exactly one of: 4000, 6000, 8000, 12000 or 20000.\n",
348 avctx->cutoff);
349 avctx->cutoff = 0;
350 }
351 }
352
353 /* Channels may need to be reordered to match opus mapping. */
355 &opus->encoder_channel_map);
356 if (av_ret) {
357 return av_ret;
358 }
359
360 if (opus->opts.mapping_family == -1) {
361 /* By default, use mapping family 1 for the header but use the older
362 * libopus multistream API to avoid surround masking. */
363
364 /* Set the mapping family so that the value is correct in the header */
365 mapping_family = channels > 2 ? 1 : 0;
366 coupled_stream_count = opus_coupled_streams[channels - 1];
367 opus->stream_count = channels - coupled_stream_count;
368 memcpy(libopus_channel_mapping,
370 channels * sizeof(*libopus_channel_mapping));
371
372 enc = opus_multistream_encoder_create(
373 avctx->sample_rate, channels, opus->stream_count,
374 coupled_stream_count,
376 opus->opts.application, &ret);
377 } else {
378 /* Use the newer multistream API. The encoder will set the channel
379 * mapping and coupled stream counts to its internal defaults and will
380 * use surround masking analysis to save bits. */
381 mapping_family = opus->opts.mapping_family;
382 enc = opus_multistream_surround_encoder_create(
383 avctx->sample_rate, channels, mapping_family,
384 &opus->stream_count, &coupled_stream_count, libopus_channel_mapping,
385 opus->opts.application, &ret);
386 }
387
388 if (ret != OPUS_OK) {
389 av_log(avctx, AV_LOG_ERROR,
390 "Failed to create encoder: %s\n", opus_strerror(ret));
392 }
393
394 if (!avctx->bit_rate) {
395 /* Sane default copied from opusenc */
396 avctx->bit_rate = 64000 * opus->stream_count +
397 32000 * coupled_stream_count;
398 av_log(avctx, AV_LOG_WARNING,
399 "No bit rate set. Defaulting to %"PRId64" bps.\n", avctx->bit_rate);
400 }
401
402 if (avctx->bit_rate < 500 || avctx->bit_rate > 256000 * channels) {
403 av_log(avctx, AV_LOG_ERROR, "The bit rate %"PRId64" bps is unsupported. "
404 "Please choose a value between 500 and %d.\n", avctx->bit_rate,
405 256000 * channels);
406 ret = AVERROR(EINVAL);
407 goto fail;
408 }
409
410 ret = libopus_configure_encoder(avctx, enc, &opus->opts);
411 if (ret != OPUS_OK) {
413 goto fail;
414 }
415
416 /* Header includes channel mapping table if and only if mapping family is NOT 0 */
417 header_size = 19 + (mapping_family == 0 ? 0 : 2 + channels);
418 avctx->extradata = av_malloc(header_size + AV_INPUT_BUFFER_PADDING_SIZE);
419 if (!avctx->extradata) {
420 av_log(avctx, AV_LOG_ERROR, "Failed to allocate extradata.\n");
421 ret = AVERROR(ENOMEM);
422 goto fail;
423 }
424 avctx->extradata_size = header_size;
425
428 if (!opus->samples) {
429 av_log(avctx, AV_LOG_ERROR, "Failed to allocate samples buffer.\n");
430 ret = AVERROR(ENOMEM);
431 goto fail;
432 }
433
434 ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->initial_padding));
435 if (ret != OPUS_OK)
436 av_log(avctx, AV_LOG_WARNING,
437 "Unable to get number of lookahead samples: %s\n",
438 opus_strerror(ret));
439
440 libopus_write_header(avctx, opus->stream_count, coupled_stream_count,
441 mapping_family, libopus_channel_mapping);
442
443 ff_af_queue_init(avctx, &opus->afq);
444
445 opus->enc = enc;
446
447 return 0;
448
449fail:
450 opus_multistream_encoder_destroy(enc);
451 return ret;
452}
453
455 uint8_t *dst, const uint8_t *src, const uint8_t *channel_map,
456 int nb_channels, int nb_samples, int bytes_per_sample) {
457 int sample, channel;
458 for (sample = 0; sample < nb_samples; ++sample) {
459 for (channel = 0; channel < nb_channels; ++channel) {
460 const size_t src_pos = bytes_per_sample * (nb_channels * sample + channel);
461 const size_t dst_pos = bytes_per_sample * (nb_channels * sample + channel_map[channel]);
462
463 memcpy(&dst[dst_pos], &src[src_pos], bytes_per_sample);
464 }
465 }
466}
467
468static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
469 const AVFrame *frame, int *got_packet_ptr)
470{
471 LibopusEncContext *opus = avctx->priv_data;
472 const int bytes_per_sample = av_get_bytes_per_sample(avctx->sample_fmt);
473 const int channels = avctx->ch_layout.nb_channels;
474 const int sample_size = channels * bytes_per_sample;
475 const uint8_t *audio;
476 int ret;
477
478 if (frame) {
479 ret = ff_af_queue_add(&opus->afq, frame);
480 if (ret < 0)
481 return ret;
482 if (opus->encoder_channel_map != NULL) {
483 audio = opus->samples;
485 opus->samples, frame->data[0], opus->encoder_channel_map,
486 channels, frame->nb_samples, bytes_per_sample);
487 } else if (frame->nb_samples < opus->opts.packet_size) {
488 audio = opus->samples;
489 memcpy(opus->samples, frame->data[0], frame->nb_samples * sample_size);
490 } else
491 audio = frame->data[0];
492 } else {
493 if (!opus->afq.remaining_samples || (!opus->afq.frame_alloc && !opus->afq.frame_count))
494 return 0;
495 audio = opus->samples;
496 memset(opus->samples, 0, opus->opts.packet_size * sample_size);
497 }
498
499 /* Maximum packet size taken from opusenc in opus-tools. 120ms packets
500 * consist of 6 frames in one packet. The maximum frame size is 1275
501 * bytes along with the largest possible packet header of 7 bytes. */
502 if ((ret = ff_alloc_packet(avctx, avpkt, (1275 * 6 + 7) * opus->stream_count)) < 0)
503 return ret;
504
505 if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT)
506 ret = opus_multistream_encode_float(opus->enc, (const float *)audio,
507 opus->opts.packet_size,
508 avpkt->data, avpkt->size);
509 else
510 ret = opus_multistream_encode(opus->enc, (const opus_int16 *)audio,
511 opus->opts.packet_size,
512 avpkt->data, avpkt->size);
513
514 if (ret < 0) {
515 av_log(avctx, AV_LOG_ERROR,
516 "Error encoding frame: %s\n", opus_strerror(ret));
518 }
519
520 av_shrink_packet(avpkt, ret);
521
522 ret = ff_af_queue_remove(&opus->afq, opus->opts.packet_size, avpkt);
523 if (ret < 0)
524 return ret;
525
526 *got_packet_ptr = 1;
527
528 return 0;
529}
530
532{
533 LibopusEncContext *opus = avctx->priv_data;
534
535 opus_multistream_encoder_destroy(opus->enc);
536
537 ff_af_queue_close(&opus->afq);
538
539 av_freep(&opus->samples);
540
541 return 0;
542}
543
544#define OFFSET(x) offsetof(LibopusEncContext, opts.x)
545#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
546static const AVOption libopus_options[] = {
547 { "application", "Intended application type", OFFSET(application), AV_OPT_TYPE_INT, { .i64 = OPUS_APPLICATION_AUDIO }, OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY, FLAGS, .unit = "application" },
548 { "voip", "Favor improved speech intelligibility", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_VOIP }, 0, 0, FLAGS, .unit = "application" },
549 { "audio", "Favor faithfulness to the input", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_AUDIO }, 0, 0, FLAGS, .unit = "application" },
550 { "lowdelay", "Restrict to only the lowest delay modes, disable voice-optimized modes", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_RESTRICTED_LOWDELAY }, 0, 0, FLAGS, .unit = "application" },
551 { "frame_duration", "Duration of a frame in milliseconds", OFFSET(frame_duration), AV_OPT_TYPE_FLOAT, { .dbl = 20.0 }, 2.5, 120.0, FLAGS },
552 { "packet_loss", "Expected packet loss percentage", OFFSET(packet_loss), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, FLAGS },
553 { "fec", "Enable inband FEC. Expected packet loss must be non-zero", OFFSET(fec), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
554 { "vbr", "Variable bit rate mode", OFFSET(vbr), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 2, FLAGS, .unit = "vbr" },
555 { "off", "Use constant bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, .unit = "vbr" },
556 { "on", "Use variable bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, .unit = "vbr" },
557 { "constrained", "Use constrained VBR", 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, .unit = "vbr" },
558 { "mapping_family", "Channel Mapping Family", OFFSET(mapping_family), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, FLAGS, .unit = "mapping_family" },
559 { "dtx", "Enable DTX (Discontinuous transmission)", OFFSET(dtx), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
560#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
561 { "apply_phase_inv", "Apply intensity stereo phase inversion", OFFSET(apply_phase_inv), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
562#endif
563 { NULL },
564};
565
566static const AVClass libopus_class = {
567 .class_name = "libopus",
568 .item_name = av_default_item_name,
569 .option = libopus_options,
570 .version = LIBAVUTIL_VERSION_INT,
571};
572
574 { "b", "0" },
575 { "compression_level", "10" },
576 { NULL },
577};
578
579static const int libopus_sample_rates[] = {
580 48000, 24000, 16000, 12000, 8000, 0,
581};
582
584 .p.name = "libopus",
585 CODEC_LONG_NAME("libopus Opus"),
586 .p.type = AVMEDIA_TYPE_AUDIO,
587 .p.id = AV_CODEC_ID_OPUS,
588 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
590 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
591 .priv_data_size = sizeof(LibopusEncContext),
594 .close = libopus_encode_close,
597 .p.priv_class = &libopus_class,
598 .defaults = libopus_defaults,
599 .p.wrapper_name = "libopus",
600};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
const FFCodec ff_libopus_encoder
Definition libopusenc.c:583
static AVDictionary * opts
channels
Definition aptx.h:31
static const uint8_t channel_map[8][8]
av_cold void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
int ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, AVPacket *pkt)
Remove frame(s) from the queue.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
Libavcodec external API header.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition bytestream.h:372
Public libavutil channel layout APIs header.
#define FLAGS
Definition cmdutils.c:596
#define CODEC_SAMPLERATES_ARRAY(array)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
#define NULL
Definition coverity.c:32
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
channel
Use these values when setting the channel map with ebur128_set_channel().
Definition ebur128.h:39
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition encode.c:63
int ret
Definition ffplay.c:391
#define sample
static const uint8_t frame_size[4]
Definition g723_1.h:222
#define fail
Definition test.h:479
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition codec.h:84
@ AV_CODEC_ID_OPUS
Definition codec_id.h:519
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition packet.c:113
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition samplefmt.c:109
@ AV_SAMPLE_FMT_FLT
float
Definition samplefmt.h:60
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition samplefmt.h:58
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
#define av_fallthrough
Definition attributes.h:67
#define av_cold
Definition attributes.h:117
int ff_opus_error_to_averror(int err)
Definition libopus.c:27
static const uint8_t libavcodec_libopus_channel_map[8][8]
Definition libopusenc.c:80
static av_cold int libopus_encode_init(AVCodecContext *avctx)
Definition libopusenc.c:269
static void libopus_copy_samples_with_channel_map(uint8_t *dst, const uint8_t *src, const uint8_t *channel_map, int nb_channels, int nb_samples, int bytes_per_sample)
Definition libopusenc.c:454
static const int libopus_sample_rates[]
Definition libopusenc.c:579
static int libopus_check_vorbis_layout(AVCodecContext *avctx, int mapping_family)
Definition libopusenc.c:203
static av_cold int libopus_encode_close(AVCodecContext *avctx)
Definition libopusenc.c:531
static const uint8_t opus_vorbis_channel_map[8][8]
Definition libopusenc.c:68
static const FFCodecDefault libopus_defaults[]
Definition libopusenc.c:573
static int libopus_validate_layout_and_get_channel_map(AVCodecContext *avctx, int mapping_family, const uint8_t **channel_map_result)
Definition libopusenc.c:224
static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition libopusenc.c:468
static const AVOption libopus_options[]
Definition libopusenc.c:546
static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc, LibopusEncOpts *opts)
Definition libopusenc.c:116
static const AVClass libopus_class
Definition libopusenc.c:566
#define OFFSET(x)
Definition libopusenc.c:544
static const uint8_t opus_coupled_streams[8]
Definition libopusenc.c:63
static void libopus_write_header(AVCodecContext *avctx, int stream_count, int coupled_stream_count, int mapping_family, const uint8_t *channel_mapping)
Definition libopusenc.c:91
static int libopus_check_max_channels(AVCodecContext *avctx, int max_channels)
Definition libopusenc.c:192
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
@ OPUS_BANDWIDTH_NARROWBAND
Definition opus.h:50
@ OPUS_BANDWIDTH_MEDIUMBAND
Definition opus.h:51
@ OPUS_BANDWIDTH_FULLBAND
Definition opus.h:54
@ OPUS_BANDWIDTH_SUPERWIDEBAND
Definition opus.h:53
@ OPUS_BANDWIDTH_WIDEBAND
Definition opus.h:52
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1059
enum AVSampleFormat sample_fmt
audio sample format
Definition avcodec.h:1051
int global_quality
Global quality for codecs which cannot change it per frame.
Definition avcodec.h:1240
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
int initial_padding
Audio only.
Definition avcodec.h:1118
int sample_rate
samples per second
Definition avcodec.h:1044
int compression_level
Definition avcodec.h:1246
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
int extradata_size
Definition avcodec.h:527
int cutoff
Audio cutoff bandwidth (0 means "automatic")
Definition avcodec.h:1086
int frame_size
Number of samples per channel in an audio frame.
Definition avcodec.h:1072
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
int size
Definition packet.h:611
uint8_t * data
Definition packet.h:610
AudioFrameQueue afq
Definition libopusenc.c:59
const uint8_t * encoder_channel_map
Definition libopusenc.c:60
uint8_t * samples
Definition libopusenc.c:57
LibopusEncOpts opts
Definition libopusenc.c:58
OpusMSEncoder * enc
Definition libopusenc.c:55
float frame_duration
Definition libopusenc.c:43
#define OPUS_TIMESTAMP_RATE
The clock of Opus: packet lengths, pre-skip and trimming count samples at 48 kHz whatever the sample ...
Definition tab.h:35
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
const AVChannelLayout ff_vorbis_ch_layouts[9]
Definition vorbis_data.c:37
const uint8_t ff_vorbis_channel_layout_offsets[8][8]
Definition vorbis_data.c:26