[FFmpeg-devel,v2] libopus: support disabling phase inversion.

Submitted by mrdegier@gmail.com on Jan. 23, 2018, 12:50 p.m.

Details

Message ID 20180123125041.98428-1-mrdegier@gmail.com
State New
Headers show

Commit Message

mrdegier@gmail.com Jan. 23, 2018, 12:50 p.m.
Renamed the option. I looked into adding support on the decoder side but things
look a bit different there (e.g. there aren't any cli params set up yet.)

Is it OK to merge this first and I can work on the decoder later?


Signed-off-by: Menno <mrdegier@gmail.com>
---
 doc/encoders.texi       |  5 +++++
 libavcodec/libopusenc.c | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

Comments

Moritz Barsnick Jan. 23, 2018, 2:50 p.m.
On Tue, Jan 23, 2018 at 13:50:41 +0100, Menno wrote:
> +@item apply_phase_inv (N.A.) (requires libopus >= 1.2)

What does the "N.A." stand for? Does it have a technical meaning?

Thanks,
Moritz
mrdegier@gmail.com Jan. 23, 2018, 3:07 p.m.
On Tue, Jan 23, 2018 at 3:50 PM, Moritz Barsnick <barsnick@gmx.net> wrote:

> On Tue, Jan 23, 2018 at 13:50:41 +0100, Menno wrote:
> > +@item apply_phase_inv (N.A.) (requires libopus >= 1.2)
>
> What does the "N.A." stand for? Does it have a technical meaning?


It's the `opusenc` equivalent option, but in this case (and a few others)
it's Not Applicable.

Patch hide | download patch | download mbox

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 6a410a8cb6..c5dfc646d9 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -981,6 +981,11 @@  Other values include 0 for mono and stereo, 1 for surround sound with masking
 and LFE bandwidth optimizations, and 255 for independent streams with an
 unspecified channel layout.
 
+@item apply_phase_inv (N.A.) (requires libopus >= 1.2)
+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).
+
 @end table
 
 @anchor{libshine}
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index b449497d15..4ae81b0bb2 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -39,6 +39,9 @@  typedef struct LibopusEncOpts {
     int packet_size;
     int max_bandwidth;
     int mapping_family;
+#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
+    int apply_phase_inv;
+#endif
 } LibopusEncOpts;
 
 typedef struct LibopusEncContext {
@@ -154,6 +157,14 @@  static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,
                    "Unable to set maximum bandwidth: %s\n", opus_strerror(ret));
     }
 
+#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
+    ret = opus_multistream_encoder_ctl(enc,
+                                       OPUS_SET_PHASE_INVERSION_DISABLED(!opts->apply_phase_inv));
+    if (ret != OPUS_OK)
+        av_log(avctx, AV_LOG_WARNING,
+               "Unable to set phase inversion: %s\n",
+               opus_strerror(ret));
+#endif
     return OPUS_OK;
 }
 
@@ -530,6 +541,9 @@  static const AVOption libopus_options[] = {
         { "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" },
     { "mapping_family", "Channel Mapping Family",              OFFSET(mapping_family), AV_OPT_TYPE_INT,   { .i64 = -1 },   -1,  255,  FLAGS, "mapping_family" },
+#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
     { NULL },
 };