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

Submitted by Takayuki 'January June' Suwa on June 15, 2018, 10:03 p.m.

Details

Message ID 20180615220332.16433-1-jjsuwa.sys3175@gmail.com
State New
Headers show

Commit Message

Takayuki 'January June' Suwa June 15, 2018, 10:03 p.m.
---
 doc/encoders.texi       | 14 ++++++++++++++
 libavcodec/libopusenc.c | 11 +++++++++++
 2 files changed, 25 insertions(+)

Patch hide | download patch | download mbox

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).
 
+@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:
+
+@table @samp
+@item auto (N.A.)
+No bias, automatic signal type detection (the default).
+
+@item voice (@emph{speech})
+Bias thresholds towards choosing LPC or Hybrid modes.
+
+@item music (@emph{music})
+Bias thresholds towards choosing MDCT modes.
+@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 },
 };