[FFmpeg-devel] [PATCH] lavc/libopusenc: add support for specifying signal type

Takayuki 'January June' Suwa jjsuwa.sys3175 at gmail.com
Sat Jun 16 01:03:32 EEST 2018


---
 doc/encoders.texi       | 14 ++++++++++++++
 libavcodec/libopusenc.c | 11 +++++++++++
 2 files changed, 25 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7b095754d1..6d0fc8e63e 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -986,6 +986,20 @@ If set to 0, disables the use of phase inversion for intensity stereo,
 improving the quality of mono downmixes, but slightly reducing normal stereo
 quality. The default is 1 (phase inversion enabled).
 
+ at item signal (@emph{music} and @emph{speech})
+Set signal type. This option acts as a tuning bias for low bitrates encoding.
+Valid options are listed below:
+
+ at table @samp
+ at item auto (N.A.)
+No bias, automatic signal type detection (the default).
+
+ at item voice (@emph{speech})
+Bias thresholds towards choosing LPC or Hybrid modes.
+
+ at item music (@emph{music})
+Bias thresholds towards choosing MDCT modes.
+ at end table
 @end table
 
 @anchor{libshine}
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 4ae81b0bb2..21ce89d288 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -42,6 +42,7 @@ typedef struct LibopusEncOpts {
 #ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
     int apply_phase_inv;
 #endif
+    int signal_type;
 } LibopusEncOpts;
 
 typedef struct LibopusEncContext {
@@ -165,6 +166,12 @@ static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,
                "Unable to set phase inversion: %s\n",
                opus_strerror(ret));
 #endif
+    ret = opus_multistream_encoder_ctl(enc,
+                                       OPUS_SET_SIGNAL(opts->signal_type));
+    if (ret != OPUS_OK)
+        av_log(avctx, AV_LOG_WARNING,
+               "Unable to set signal type: %s\n", opus_strerror(ret));
+
     return OPUS_OK;
 }
 
@@ -544,6 +551,10 @@ static const AVOption libopus_options[] = {
 #ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
     { "apply_phase_inv", "Apply intensity stereo phase inversion", OFFSET(apply_phase_inv), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
 #endif
+    { "signal",         "Signal type",                         OFFSET(signal_type),    AV_OPT_TYPE_INT,   { .i64 = OPUS_AUTO }, OPUS_AUTO, OPUS_SIGNAL_MUSIC, FLAGS, "signal" },
+        { "auto",           "Automatic detection", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_AUTO },         0, 0, FLAGS, "signal" },
+        { "voice",          "Tune for speech",     0, AV_OPT_TYPE_CONST, { .i64 = OPUS_SIGNAL_VOICE }, 0, 0, FLAGS, "signal" },
+        { "music",          "Tune for music",      0, AV_OPT_TYPE_CONST, { .i64 = OPUS_SIGNAL_MUSIC }, 0, 0, FLAGS, "signal" },
     { NULL },
 };
 
-- 
2.11.0



More information about the ffmpeg-devel mailing list