]> git.sesse.net Git - ffmpeg/blob - libavcodec/libopusenc.c
mpegvideo: add deprecated flags to the rc_strategy option
[ffmpeg] / libavcodec / libopusenc.c
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
25 #include "libavutil/opt.h"
26 #include "avcodec.h"
27 #include "bytestream.h"
28 #include "internal.h"
29 #include "libopus.h"
30 #include "vorbis.h"
31 #include "audio_frame_queue.h"
32
33 typedef struct LibopusEncOpts {
34     int vbr;
35     int application;
36     int packet_loss;
37     int complexity;
38     float frame_duration;
39     int packet_size;
40     int max_bandwidth;
41     int mapping_family;
42 #ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
43     int apply_phase_inv;
44 #endif
45 } LibopusEncOpts;
46
47 typedef struct LibopusEncContext {
48     AVClass *class;
49     OpusMSEncoder *enc;
50     int stream_count;
51     uint8_t *samples;
52     LibopusEncOpts opts;
53     AudioFrameQueue afq;
54     const uint8_t *encoder_channel_map;
55 } LibopusEncContext;
56
57 static const uint8_t opus_coupled_streams[8] = {
58     0, 1, 1, 2, 2, 2, 2, 3
59 };
60
61 /* Opus internal to Vorbis channel order mapping written in the header */
62 static const uint8_t opus_vorbis_channel_map[8][8] = {
63     { 0 },
64     { 0, 1 },
65     { 0, 2, 1 },
66     { 0, 1, 2, 3 },
67     { 0, 4, 1, 2, 3 },
68     { 0, 4, 1, 2, 3, 5 },
69     { 0, 4, 1, 2, 3, 5, 6 },
70     { 0, 6, 1, 2, 3, 4, 5, 7 },
71 };
72
73 /* libavcodec to libopus channel order mapping, passed to libopus */
74 static const uint8_t libavcodec_libopus_channel_map[8][8] = {
75     { 0 },
76     { 0, 1 },
77     { 0, 1, 2 },
78     { 0, 1, 2, 3 },
79     { 0, 1, 3, 4, 2 },
80     { 0, 1, 4, 5, 2, 3 },
81     { 0, 1, 5, 6, 2, 4, 3 },
82     { 0, 1, 6, 7, 4, 5, 2, 3 },
83 };
84
85 static void libopus_write_header(AVCodecContext *avctx, int stream_count,
86                                  int coupled_stream_count,
87                                  int mapping_family,
88                                  const uint8_t *channel_mapping)
89 {
90     uint8_t *p   = avctx->extradata;
91     int channels = avctx->channels;
92
93     bytestream_put_buffer(&p, "OpusHead", 8);
94     bytestream_put_byte(&p, 1); /* Version */
95     bytestream_put_byte(&p, channels);
96     bytestream_put_le16(&p, avctx->initial_padding); /* Lookahead samples at 48kHz */
97     bytestream_put_le32(&p, avctx->sample_rate); /* Original sample rate */
98     bytestream_put_le16(&p, 0); /* Gain of 0dB is recommended. */
99
100     /* Channel mapping */
101     bytestream_put_byte(&p, mapping_family);
102     if (mapping_family != 0) {
103         bytestream_put_byte(&p, stream_count);
104         bytestream_put_byte(&p, coupled_stream_count);
105         bytestream_put_buffer(&p, channel_mapping, channels);
106     }
107 }
108
109 static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,
110                                      LibopusEncOpts *opts)
111 {
112     int ret;
113
114     if (avctx->global_quality) {
115         av_log(avctx, AV_LOG_ERROR,
116                "Quality-based encoding not supported, "
117                "please specify a bitrate and VBR setting.\n");
118         return AVERROR(EINVAL);
119     }
120
121     ret = opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(avctx->bit_rate));
122     if (ret != OPUS_OK) {
123         av_log(avctx, AV_LOG_ERROR,
124                "Failed to set bitrate: %s\n", opus_strerror(ret));
125         return ret;
126     }
127
128     ret = opus_multistream_encoder_ctl(enc,
129                                        OPUS_SET_COMPLEXITY(opts->complexity));
130     if (ret != OPUS_OK)
131         av_log(avctx, AV_LOG_WARNING,
132                "Unable to set complexity: %s\n", opus_strerror(ret));
133
134     ret = opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(!!opts->vbr));
135     if (ret != OPUS_OK)
136         av_log(avctx, AV_LOG_WARNING,
137                "Unable to set VBR: %s\n", opus_strerror(ret));
138
139     ret = opus_multistream_encoder_ctl(enc,
140                                        OPUS_SET_VBR_CONSTRAINT(opts->vbr == 2));
141     if (ret != OPUS_OK)
142         av_log(avctx, AV_LOG_WARNING,
143                "Unable to set constrained VBR: %s\n", opus_strerror(ret));
144
145     ret = opus_multistream_encoder_ctl(enc,
146                                        OPUS_SET_PACKET_LOSS_PERC(opts->packet_loss));
147     if (ret != OPUS_OK)
148         av_log(avctx, AV_LOG_WARNING,
149                "Unable to set expected packet loss percentage: %s\n",
150                opus_strerror(ret));
151
152     if (avctx->cutoff) {
153         ret = opus_multistream_encoder_ctl(enc,
154                                            OPUS_SET_MAX_BANDWIDTH(opts->max_bandwidth));
155         if (ret != OPUS_OK)
156             av_log(avctx, AV_LOG_WARNING,
157                    "Unable to set maximum bandwidth: %s\n", opus_strerror(ret));
158     }
159
160 #ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
161     ret = opus_multistream_encoder_ctl(enc,
162                                        OPUS_SET_PHASE_INVERSION_DISABLED(!opts->apply_phase_inv));
163     if (ret != OPUS_OK)
164         av_log(avctx, AV_LOG_WARNING,
165                "Unable to set phase inversion: %s\n",
166                opus_strerror(ret));
167 #endif
168     return OPUS_OK;
169 }
170
171 static int libopus_check_max_channels(AVCodecContext *avctx,
172                                       int max_channels) {
173     if (avctx->channels > max_channels) {
174         av_log(avctx, AV_LOG_ERROR, "Opus mapping family undefined for %d channels.\n",
175                avctx->channels);
176         return AVERROR(EINVAL);
177     }
178
179     return 0;
180 }
181
182 static int libopus_check_vorbis_layout(AVCodecContext *avctx, int mapping_family) {
183     av_assert2(avctx->channels < FF_ARRAY_ELEMS(ff_vorbis_channel_layouts));
184
185     if (!avctx->channel_layout) {
186         av_log(avctx, AV_LOG_WARNING,
187                "No channel layout specified. Opus encoder will use Vorbis "
188                "channel layout for %d channels.\n", avctx->channels);
189     } else if (avctx->channel_layout != ff_vorbis_channel_layouts[avctx->channels - 1]) {
190         char name[32];
191         av_get_channel_layout_string(name, sizeof(name), avctx->channels,
192                                      avctx->channel_layout);
193         av_log(avctx, AV_LOG_ERROR,
194                "Invalid channel layout %s for specified mapping family %d.\n",
195                name, mapping_family);
196
197         return AVERROR(EINVAL);
198     }
199
200     return 0;
201 }
202
203 static int libopus_validate_layout_and_get_channel_map(
204         AVCodecContext *avctx,
205         int mapping_family,
206         const uint8_t ** channel_map_result)
207 {
208     const uint8_t * channel_map = NULL;
209     int ret;
210
211     switch (mapping_family) {
212     case -1:
213         ret = libopus_check_max_channels(avctx, 8);
214         if (ret == 0) {
215             ret = libopus_check_vorbis_layout(avctx, mapping_family);
216             /* Channels do not need to be reordered. */
217         }
218
219         break;
220     case 0:
221         ret = libopus_check_max_channels(avctx, 2);
222         if (ret == 0) {
223             ret = libopus_check_vorbis_layout(avctx, mapping_family);
224         }
225         break;
226     case 1:
227         /* Opus expects channels to be in Vorbis order. */
228         ret = libopus_check_max_channels(avctx, 8);
229         if (ret == 0) {
230             ret = libopus_check_vorbis_layout(avctx, mapping_family);
231             channel_map = ff_vorbis_channel_layout_offsets[avctx->channels - 1];
232         }
233         break;
234     case 255:
235         ret = libopus_check_max_channels(avctx, 254);
236         break;
237     default:
238         av_log(avctx, AV_LOG_WARNING,
239                "Unknown channel mapping family %d. Output channel layout may be invalid.\n",
240                mapping_family);
241         ret = 0;
242     }
243
244     *channel_map_result = channel_map;
245     return ret;
246 }
247
248 static av_cold int libopus_encode_init(AVCodecContext *avctx)
249 {
250     LibopusEncContext *opus = avctx->priv_data;
251     OpusMSEncoder *enc;
252     uint8_t libopus_channel_mapping[255];
253     int ret = OPUS_OK;
254     int av_ret;
255     int coupled_stream_count, header_size, frame_size;
256     int mapping_family;
257
258     frame_size = opus->opts.frame_duration * 48000 / 1000;
259     switch (frame_size) {
260     case 120:
261     case 240:
262         if (opus->opts.application != OPUS_APPLICATION_RESTRICTED_LOWDELAY)
263             av_log(avctx, AV_LOG_WARNING,
264                    "LPC mode cannot be used with a frame duration of less "
265                    "than 10ms. Enabling restricted low-delay mode.\n"
266                    "Use a longer frame duration if this is not what you want.\n");
267         /* Frame sizes less than 10 ms can only use MDCT mode, so switching to
268          * RESTRICTED_LOWDELAY avoids an unnecessary extra 2.5ms lookahead. */
269         opus->opts.application = OPUS_APPLICATION_RESTRICTED_LOWDELAY;
270     case 480:
271     case 960:
272     case 1920:
273     case 2880:
274         opus->opts.packet_size =
275         avctx->frame_size      = frame_size * avctx->sample_rate / 48000;
276         break;
277     default:
278         av_log(avctx, AV_LOG_ERROR, "Invalid frame duration: %g.\n"
279                "Frame duration must be exactly one of: 2.5, 5, 10, 20, 40 or 60.\n",
280                opus->opts.frame_duration);
281         return AVERROR(EINVAL);
282     }
283
284     if (avctx->compression_level < 0 || avctx->compression_level > 10) {
285         av_log(avctx, AV_LOG_WARNING,
286                "Compression level must be in the range 0 to 10. "
287                "Defaulting to 10.\n");
288         opus->opts.complexity = 10;
289     } else {
290         opus->opts.complexity = avctx->compression_level;
291     }
292
293     if (avctx->cutoff) {
294         switch (avctx->cutoff) {
295         case  4000:
296             opus->opts.max_bandwidth = OPUS_BANDWIDTH_NARROWBAND;
297             break;
298         case  6000:
299             opus->opts.max_bandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
300             break;
301         case  8000:
302             opus->opts.max_bandwidth = OPUS_BANDWIDTH_WIDEBAND;
303             break;
304         case 12000:
305             opus->opts.max_bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
306             break;
307         case 20000:
308             opus->opts.max_bandwidth = OPUS_BANDWIDTH_FULLBAND;
309             break;
310         default:
311             av_log(avctx, AV_LOG_WARNING,
312                    "Invalid frequency cutoff: %d. Using default maximum bandwidth.\n"
313                    "Cutoff frequency must be exactly one of: 4000, 6000, 8000, 12000 or 20000.\n",
314                    avctx->cutoff);
315             avctx->cutoff = 0;
316         }
317     }
318
319     /* Channels may need to be reordered to match opus mapping. */
320     av_ret = libopus_validate_layout_and_get_channel_map(avctx, opus->opts.mapping_family,
321                                                          &opus->encoder_channel_map);
322     if (av_ret) {
323         return av_ret;
324     }
325
326     if (opus->opts.mapping_family == -1) {
327         /* By default, use mapping family 1 for the header but use the older
328          * libopus multistream API to avoid surround masking. */
329
330         /* Set the mapping family so that the value is correct in the header */
331         mapping_family = avctx->channels > 2 ? 1 : 0;
332         coupled_stream_count = opus_coupled_streams[avctx->channels - 1];
333         opus->stream_count   = avctx->channels - coupled_stream_count;
334         memcpy(libopus_channel_mapping,
335                opus_vorbis_channel_map[avctx->channels - 1],
336                avctx->channels * sizeof(*libopus_channel_mapping));
337
338         enc = opus_multistream_encoder_create(
339             avctx->sample_rate, avctx->channels, opus->stream_count,
340             coupled_stream_count,
341             libavcodec_libopus_channel_map[avctx->channels - 1],
342             opus->opts.application, &ret);
343     } else {
344         /* Use the newer multistream API. The encoder will set the channel
345          * mapping and coupled stream counts to its internal defaults and will
346          * use surround masking analysis to save bits. */
347         mapping_family = opus->opts.mapping_family;
348         enc = opus_multistream_surround_encoder_create(
349             avctx->sample_rate, avctx->channels, mapping_family,
350             &opus->stream_count, &coupled_stream_count, libopus_channel_mapping,
351             opus->opts.application, &ret);
352     }
353
354     if (ret != OPUS_OK) {
355         av_log(avctx, AV_LOG_ERROR,
356                "Failed to create encoder: %s\n", opus_strerror(ret));
357         return ff_opus_error_to_averror(ret);
358     }
359
360     if (!avctx->bit_rate) {
361         /* Sane default copied from opusenc */
362         avctx->bit_rate = 64000 * opus->stream_count +
363                           32000 * coupled_stream_count;
364         av_log(avctx, AV_LOG_WARNING,
365                "No bit rate set. Defaulting to %"PRId64" bps.\n", avctx->bit_rate);
366     }
367
368     if (avctx->bit_rate < 500 || avctx->bit_rate > 256000 * avctx->channels) {
369         av_log(avctx, AV_LOG_ERROR, "The bit rate %"PRId64" bps is unsupported. "
370                "Please choose a value between 500 and %d.\n", avctx->bit_rate,
371                256000 * avctx->channels);
372         ret = AVERROR(EINVAL);
373         goto fail;
374     }
375
376     ret = libopus_configure_encoder(avctx, enc, &opus->opts);
377     if (ret != OPUS_OK) {
378         ret = ff_opus_error_to_averror(ret);
379         goto fail;
380     }
381
382     /* Header includes channel mapping table if and only if mapping family is NOT 0 */
383     header_size = 19 + (mapping_family == 0 ? 0 : 2 + avctx->channels);
384     avctx->extradata = av_malloc(header_size + AV_INPUT_BUFFER_PADDING_SIZE);
385     if (!avctx->extradata) {
386         av_log(avctx, AV_LOG_ERROR, "Failed to allocate extradata.\n");
387         ret = AVERROR(ENOMEM);
388         goto fail;
389     }
390     avctx->extradata_size = header_size;
391
392     opus->samples = av_mallocz_array(frame_size, avctx->channels *
393                                av_get_bytes_per_sample(avctx->sample_fmt));
394     if (!opus->samples) {
395         av_log(avctx, AV_LOG_ERROR, "Failed to allocate samples buffer.\n");
396         ret = AVERROR(ENOMEM);
397         goto fail;
398     }
399
400     ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->initial_padding));
401     if (ret != OPUS_OK)
402         av_log(avctx, AV_LOG_WARNING,
403                "Unable to get number of lookahead samples: %s\n",
404                opus_strerror(ret));
405
406     libopus_write_header(avctx, opus->stream_count, coupled_stream_count,
407                          mapping_family, libopus_channel_mapping);
408
409     ff_af_queue_init(avctx, &opus->afq);
410
411     opus->enc = enc;
412
413     return 0;
414
415 fail:
416     opus_multistream_encoder_destroy(enc);
417     av_freep(&avctx->extradata);
418     return ret;
419 }
420
421 static void libopus_copy_samples_with_channel_map(
422     uint8_t *dst, const uint8_t *src, const uint8_t *channel_map,
423     int nb_channels, int nb_samples, int bytes_per_sample) {
424     int sample, channel;
425     for (sample = 0; sample < nb_samples; ++sample) {
426         for (channel = 0; channel < nb_channels; ++channel) {
427             const size_t src_pos = bytes_per_sample * (nb_channels * sample + channel);
428             const size_t dst_pos = bytes_per_sample * (nb_channels * sample + channel_map[channel]);
429
430             memcpy(&dst[dst_pos], &src[src_pos], bytes_per_sample);
431         }
432     }
433 }
434
435 static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
436                           const AVFrame *frame, int *got_packet_ptr)
437 {
438     LibopusEncContext *opus = avctx->priv_data;
439     const int bytes_per_sample = av_get_bytes_per_sample(avctx->sample_fmt);
440     const int sample_size      = avctx->channels * bytes_per_sample;
441     uint8_t *audio;
442     int ret;
443     int discard_padding;
444
445     if (frame) {
446         ret = ff_af_queue_add(&opus->afq, frame);
447         if (ret < 0)
448             return ret;
449         if (opus->encoder_channel_map != NULL) {
450             audio = opus->samples;
451             libopus_copy_samples_with_channel_map(
452                 audio, frame->data[0], opus->encoder_channel_map,
453                 avctx->channels, frame->nb_samples, bytes_per_sample);
454         } else if (frame->nb_samples < opus->opts.packet_size) {
455             audio = opus->samples;
456             memcpy(audio, frame->data[0], frame->nb_samples * sample_size);
457         } else
458             audio = frame->data[0];
459     } else {
460         if (!opus->afq.remaining_samples || (!opus->afq.frame_alloc && !opus->afq.frame_count))
461             return 0;
462         audio = opus->samples;
463         memset(audio, 0, opus->opts.packet_size * sample_size);
464     }
465
466     /* Maximum packet size taken from opusenc in opus-tools. 60ms packets
467      * consist of 3 frames in one packet. The maximum frame size is 1275
468      * bytes along with the largest possible packet header of 7 bytes. */
469     if ((ret = ff_alloc_packet2(avctx, avpkt, (1275 * 3 + 7) * opus->stream_count, 0)) < 0)
470         return ret;
471
472     if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT)
473         ret = opus_multistream_encode_float(opus->enc, (float *)audio,
474                                             opus->opts.packet_size,
475                                             avpkt->data, avpkt->size);
476     else
477         ret = opus_multistream_encode(opus->enc, (opus_int16 *)audio,
478                                       opus->opts.packet_size,
479                                       avpkt->data, avpkt->size);
480
481     if (ret < 0) {
482         av_log(avctx, AV_LOG_ERROR,
483                "Error encoding frame: %s\n", opus_strerror(ret));
484         return ff_opus_error_to_averror(ret);
485     }
486
487     av_shrink_packet(avpkt, ret);
488
489     ff_af_queue_remove(&opus->afq, opus->opts.packet_size,
490                        &avpkt->pts, &avpkt->duration);
491
492     discard_padding = opus->opts.packet_size - avpkt->duration;
493     // Check if subtraction resulted in an overflow
494     if ((discard_padding < opus->opts.packet_size) != (avpkt->duration > 0)) {
495         av_packet_unref(avpkt);
496         av_free(avpkt);
497         return AVERROR(EINVAL);
498     }
499     if (discard_padding > 0) {
500         uint8_t* side_data = av_packet_new_side_data(avpkt,
501                                                      AV_PKT_DATA_SKIP_SAMPLES,
502                                                      10);
503         if(!side_data) {
504             av_packet_unref(avpkt);
505             av_free(avpkt);
506             return AVERROR(ENOMEM);
507         }
508         AV_WL32(side_data + 4, discard_padding);
509     }
510
511     *got_packet_ptr = 1;
512
513     return 0;
514 }
515
516 static av_cold int libopus_encode_close(AVCodecContext *avctx)
517 {
518     LibopusEncContext *opus = avctx->priv_data;
519
520     opus_multistream_encoder_destroy(opus->enc);
521
522     ff_af_queue_close(&opus->afq);
523
524     av_freep(&opus->samples);
525     av_freep(&avctx->extradata);
526
527     return 0;
528 }
529
530 #define OFFSET(x) offsetof(LibopusEncContext, opts.x)
531 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
532 static const AVOption libopus_options[] = {
533     { "application",    "Intended application type",           OFFSET(application),    AV_OPT_TYPE_INT,   { .i64 = OPUS_APPLICATION_AUDIO }, OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY, FLAGS, "application" },
534         { "voip",           "Favor improved speech intelligibility",   0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_VOIP },                0, 0, FLAGS, "application" },
535         { "audio",          "Favor faithfulness to the input",         0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_AUDIO },               0, 0, FLAGS, "application" },
536         { "lowdelay",       "Restrict to only the lowest delay modes", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_RESTRICTED_LOWDELAY }, 0, 0, FLAGS, "application" },
537     { "frame_duration", "Duration of a frame in milliseconds", OFFSET(frame_duration), AV_OPT_TYPE_FLOAT, { .dbl = 20.0 }, 2.5, 60.0, FLAGS },
538     { "packet_loss",    "Expected packet loss percentage",     OFFSET(packet_loss),    AV_OPT_TYPE_INT,   { .i64 = 0 },    0,   100,  FLAGS },
539     { "vbr",            "Variable bit rate mode",              OFFSET(vbr),            AV_OPT_TYPE_INT,   { .i64 = 1 },    0,   2,    FLAGS, "vbr" },
540         { "off",            "Use constant bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, "vbr" },
541         { "on",             "Use variable bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "vbr" },
542         { "constrained",    "Use constrained VBR",   0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, "vbr" },
543     { "mapping_family", "Channel Mapping Family",              OFFSET(mapping_family), AV_OPT_TYPE_INT,   { .i64 = -1 },   -1,  255,  FLAGS, "mapping_family" },
544 #ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
545     { "apply_phase_inv", "Apply intensity stereo phase inversion", OFFSET(apply_phase_inv), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
546 #endif
547     { NULL },
548 };
549
550 static const AVClass libopus_class = {
551     .class_name = "libopus",
552     .item_name  = av_default_item_name,
553     .option     = libopus_options,
554     .version    = LIBAVUTIL_VERSION_INT,
555 };
556
557 static const AVCodecDefault libopus_defaults[] = {
558     { "b",                 "0" },
559     { "compression_level", "10" },
560     { NULL },
561 };
562
563 static const int libopus_sample_rates[] = {
564     48000, 24000, 16000, 12000, 8000, 0,
565 };
566
567 AVCodec ff_libopus_encoder = {
568     .name            = "libopus",
569     .long_name       = NULL_IF_CONFIG_SMALL("libopus Opus"),
570     .type            = AVMEDIA_TYPE_AUDIO,
571     .id              = AV_CODEC_ID_OPUS,
572     .priv_data_size  = sizeof(LibopusEncContext),
573     .init            = libopus_encode_init,
574     .encode2         = libopus_encode,
575     .close           = libopus_encode_close,
576     .capabilities    = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SMALL_LAST_FRAME,
577     .sample_fmts     = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
578                                                       AV_SAMPLE_FMT_FLT,
579                                                       AV_SAMPLE_FMT_NONE },
580     .supported_samplerates = libopus_sample_rates,
581     .priv_class      = &libopus_class,
582     .defaults        = libopus_defaults,
583     .wrapper_name    = "libopus",
584 };