[FFmpeg-devel] [PATCH] opus encoder using libopus

Lou Logan lou at lrcd.com
Thu Sep 20 05:14:56 CEST 2012


Hi,

Thanks for the contribution. Three incredibly trivial nits. Ignore
unless you're updating the patch anyway.

On Thu, 20 Sep 2012 10:07:43 +0800, Sin-ta Hsiea wrote:
[...]
> +++ b/libavcodec/libopus_enc.c
[...]
> +    ret = opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(opts->packet_loss));
> +    if (ret != OPUS_OK)
> +        av_log(avctx, AV_LOG_WARNING, "Unable to set expect packet loss percentage: %s\n", opus_strerror(ret));

"expected", I assume.

> +
> +    if (avctx->cutoff) {
> +        ret = opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(avctx->cutoff));
> +        if (ret != OPUS_OK)
> +            av_log(avctx, AV_LOG_WARNING, "Unable to set maximum bandwidth: %s\n", opus_strerror(ret));
> +    }
> +
> +    return OPUS_OK;
> +}
> +
> +static int av_cold libopus_encode_init(AVCodecContext *avctx)
> +{
> +    LibOpusEncContext *opus = avctx->priv_data;
> +    OpusMSEncoder *enc;
> +    int ret = OPUS_OK;
> +    int coupled_stream_count, header_size;
> +
> +    /* FIXME: Opus can handle up to 255 channels. However, the mapping for anything
> +     * greater than 8 is undefined.
> +     */
> +    if (avctx->channels > 8) {
> +        av_log(avctx, AV_LOG_WARNING, "Unsupported number of channels (%d).\n",
> +               avctx->channels);
> +        return AVERROR(EINVAL);
> +    }
> +
> +    /* libopus officially supports 8kHz, 12kHz, 16kHz, 24kHz and 48kHz sample
> +     * rates. Except for 48kHz, everything is resampled up to 48kHz internally by libopus.
> +     * Additionally, libopus dynamically adjusts it's bandwidth depending on the requested bitrate.

s/it's/its

[...]
> +#define OFFSET(x) offsetof(LibOpusEncContext, opts.x)
> +#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> +static const AVOption libopus_options[] = {
> +    { "vbr",         "Variable bit rate mode",            OFFSET(vbr),         AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 2,   FLAGS, "vbr" },
> +    { "off",         "Use constant bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, "vbr" },
> +    { "on",          "Use variable bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "vbr" },
> +    { "constrained", "Use constrained VBR",   0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, "vbr" },
> +    { "packet_loss", "Expected packet loss percentage",   OFFSET(packet_loss), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, FLAGS },
> +    { "application", "Intended application type",         OFFSET(application), AV_OPT_TYPE_INT, { .i64 = OPUS_APPLICATION_AUDIO }, OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY, FLAGS, "application" },
> +    { "voip",     "Favor improved speech intelligibility", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_VOIP },                0, 0, FLAGS, "application" },
> +    { "audio",    "Favor faithfulness to the input",       0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_AUDIO }, 0, 0, FLAGS, "application" },
> +    { "lowdelay", "Favor minimum possible coding delay",   0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_RESTRICTED_LOWDELAY }, 0, 0, FLAGS, "application" },

Maybe this can be vertically aligned.


More information about the ffmpeg-devel mailing list