diff mbox series

[FFmpeg-devel,v2,2/2] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

Message ID 20200306020916.58366-1-wangcao@google.com
State Superseded
Headers show
Series [FFmpeg-devel,v2,1/2] avcodec/libaomenc.c: Add a libaom command-line option 'tune'
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Wang Cao March 6, 2020, 2:09 a.m. UTC
Signed-off-by: Wang Cao <wangcao@google.com>
---
The changes are made according to the code review
- Bump the MICRO version
- Use enum for Super resolution mode consts. The original enum in libaom
  is not public so a enum is defined and matched the original enum
 doc/encoders.texi      | 39 +++++++++++++++++++++++++++++++++++
 libavcodec/libaomenc.c | 47 ++++++++++++++++++++++++++++++++++++++++++
 libavcodec/version.h   |  2 +-
 3 files changed, 87 insertions(+), 1 deletion(-)

Comments

James Zern March 18, 2020, 2:38 a.m. UTC | #1
Hi,

On Thu, Mar 5, 2020 at 6:20 PM Wang Cao <doubleecao@gmail.com> wrote:
>
> Signed-off-by: Wang Cao <wangcao@google.com>
> ---
> The changes are made according to the code review
> - Bump the MICRO version
> - Use enum for Super resolution mode consts. The original enum in libaom
>   is not public so a enum is defined and matched the original enum
>  doc/encoders.texi      | 39 +++++++++++++++++++++++++++++++++++
>  libavcodec/libaomenc.c | 47 ++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/version.h   |  2 +-
>  3 files changed, 87 insertions(+), 1 deletion(-)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 0a74ecce9b..04f05e7c9b 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -1608,6 +1608,45 @@ Enable the use of global motion for block prediction. Default is true.
>  Enable block copy mode for intra block prediction. This mode is
>  useful for screen content. Default is true.
>
> +@item enable-superres (@emph{boolean})
> +Enable super-resolution during the encoding process.
> +

Funny aomenc in libaom doesn't have this option. It must assume the
library defaults will take care of it, seems like a bug.

> +@item superres-mode (@emph{mode})
> +Select super-resultion mode.
> +

resolution
Wang Cao April 3, 2020, 8:23 p.m. UTC | #2
On Wed, Mar 18, 2020 at 6:38 AM James Zern <jzern@google.com> wrote:

> Hi,
>
> On Thu, Mar 5, 2020 at 6:20 PM Wang Cao <doubleecao@gmail.com> wrote:
> >
> > Signed-off-by: Wang Cao <wangcao@google.com>
> > ---
> > The changes are made according to the code review
> > - Bump the MICRO version
> > - Use enum for Super resolution mode consts. The original enum in libaom
> >   is not public so a enum is defined and matched the original enum
> >  doc/encoders.texi      | 39 +++++++++++++++++++++++++++++++++++
> >  libavcodec/libaomenc.c | 47 ++++++++++++++++++++++++++++++++++++++++++
> >  libavcodec/version.h   |  2 +-
> >  3 files changed, 87 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 0a74ecce9b..04f05e7c9b 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -1608,6 +1608,45 @@ Enable the use of global motion for block
> prediction. Default is true.
> >  Enable block copy mode for intra block prediction. This mode is
> >  useful for screen content. Default is true.
> >
> > +@item enable-superres (@emph{boolean})
> > +Enable super-resolution during the encoding process.
> > +
>
> Funny aomenc in libaom doesn't have this option. It must assume the
> library defaults will take care of it, seems like a bug.
>
> Yes they use a default value "1" for this internally (
https://aomedia.googlesource.com/aom/+/master/av1/av1_cx_iface.c).

> > +@item superres-mode (@emph{mode})
> > +Select super-resultion mode.
> > +
>
> resolution
>
I will send a new patch to apply the changes you mentioned.
James Zern April 13, 2020, 10:17 p.m. UTC | #3
On Tue, Mar 17, 2020 at 7:38 PM James Zern <jzern@google.com> wrote:
>
> Hi,
>
> On Thu, Mar 5, 2020 at 6:20 PM Wang Cao <doubleecao@gmail.com> wrote:
> >
> > Signed-off-by: Wang Cao <wangcao@google.com>
> > ---
> > The changes are made according to the code review
> > - Bump the MICRO version
> > - Use enum for Super resolution mode consts. The original enum in libaom
> >   is not public so a enum is defined and matched the original enum
> >  doc/encoders.texi      | 39 +++++++++++++++++++++++++++++++++++
> >  libavcodec/libaomenc.c | 47 ++++++++++++++++++++++++++++++++++++++++++
> >  libavcodec/version.h   |  2 +-
> >  3 files changed, 87 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 0a74ecce9b..04f05e7c9b 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -1608,6 +1608,45 @@ Enable the use of global motion for block prediction. Default is true.
> >  Enable block copy mode for intra block prediction. This mode is
> >  useful for screen content. Default is true.
> >
> > +@item enable-superres (@emph{boolean})
> > +Enable super-resolution during the encoding process.
> > +
>
> Funny aomenc in libaom doesn't have this option. It must assume the
> library defaults will take care of it, seems like a bug.
>

Looking at it a little more closely, there's a 'none' superres-mode,
so that will work on its own.

> > +@item superres-mode (@emph{mode})
> > +Select super-resultion mode.
> > +
>
> resolution
diff mbox series

Patch

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 0a74ecce9b..04f05e7c9b 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1608,6 +1608,45 @@  Enable the use of global motion for block prediction. Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item enable-superres (@emph{boolean})
+Enable super-resolution during the encoding process.
+
+@item superres-mode (@emph{mode})
+Select super-resultion mode.
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed.
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved.
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index.
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames.
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is @option{fixed}. Valid value 
+ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames when 
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode} is 
+@option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when 
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index df7819b429..0f4c0377cc 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -95,6 +95,12 @@  typedef struct AOMEncoderContext {
     int enable_restoration;
     int usage;
     int tune;
+    int enable_superres;
+    int superres_mode;
+    int superres_denominator;
+    int superres_qthresh;
+    int superres_kf_denominator;
+    int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -134,6 +140,16 @@  static const char *const ctlidstr[] = {
 #endif
     [AV1E_SET_ENABLE_CDEF]      = "AV1E_SET_ENABLE_CDEF",
     [AOME_SET_TUNING]           = "AOME_SET_TUNING",
+    [AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
+};
+
+enum AOMSuperresModes {
+    AOM_SUPERRES_MODE_NONE    = 0,
+    AOM_SUPERRES_MODE_FIXED   = 1,
+    AOM_SUPERRES_MODE_RANDOM  = 2,
+    AOM_SUPERRES_MODE_QTHRESH = 3,
+    AOM_SUPERRES_MODE_AUTO    = 4,
+    AOM_SUPERRES_MODE_NB
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -203,6 +219,13 @@  static av_cold void dump_enc_cfg(AVCodecContext *avctx,
            width, "tile_width_count:",  cfg->tile_width_count,
            width, "tile_height_count:", cfg->tile_height_count);
     av_log(avctx, level, "\n");
+    av_log(avctx, level, "super resolution settings\n"
+                         "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+           width, "rc_superres_mode:",           cfg->rc_superres_mode,
+           width, "rc_superres_denominator:",    cfg->rc_superres_denominator,
+           width, "rc_superres_qthresh:",        cfg->rc_superres_qthresh,
+           width, "rc_superres_kf_denominator:", cfg->rc_superres_kf_denominator,
+           width, "rc_superres_kf_qthresh:",     cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -545,6 +568,17 @@  static av_cold int aom_init(AVCodecContext *avctx,
             return AVERROR(EINVAL);
         }
 
+    if (ctx->superres_mode >= 0)
+        enccfg.rc_superres_mode = ctx->superres_mode;
+    if (ctx->superres_qthresh > 0)
+        enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+    if (ctx->superres_kf_qthresh > 0)
+        enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+    if (ctx->superres_denominator >= 0)
+        enccfg.rc_superres_denominator = ctx->superres_denominator;
+    if (ctx->superres_kf_denominator >= 0)
+        enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
     dump_enc_cfg(avctx, &enccfg);
 
     enccfg.g_w            = avctx->width;
@@ -687,6 +721,8 @@  static av_cold int aom_init(AVCodecContext *avctx,
     // codec control failures are currently treated only as warnings
     av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
     codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+    if (ctx->enable_superres >= 0)
+        codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, ctx->enable_superres);
     if (ctx->auto_alt_ref >= 0)
         codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
     if (ctx->arnr_max_frames >= 0)
@@ -1103,6 +1139,17 @@  static const AVOption options[] = {
     { "tune",            "The metric that encoder tunes for. Automatically choosen by encoder by default", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, AOM_TUNE_SSIM, VE, "tune"},
     { "psnr",            "PSNR as distortion metric",         0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
     { "ssim",            "SSIM as distortion metric",         0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
+    { "enable-superres", "Enable super-resolution mode", OFFSET(enable_superres), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+    { "superres-mode",   "Select super-resultion mode", OFFSET(superres_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, AOM_SUPERRES_MODE_NB-1, VE, "superres_mode"},
+    { "none",            "No frame superres allowed",                                      0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_MODE_NONE},    0, 0, VE, "superres_mode"},
+    { "fixed",           "All frames are coded at the specified scale and super-resolved", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_MODE_FIXED},   0, 0, VE, "superres_mode"},
+    { "random",          "All frames are coded at a random scale and super-resolved.",     0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_MODE_RANDOM},  0, 0, VE, "superres_mode"},
+    { "qthresh",         "Superres scale for a frame is determined based on q_index",      0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_MODE_QTHRESH}, 0, 0, VE, "superres_mode"},
+    { "auto",            "Automatically select superres for appropriate frames",           0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_MODE_AUTO},    0, 0, VE, "superres_mode"},
+    { "superres-denominator",    "The denominator for superres to use.",                               OFFSET(superres_denominator),    AV_OPT_TYPE_INT, {.i64 = 8}, 8, 16, VE},
+    { "superres-qthresh",        "The q level threshold after which superres is used",                 OFFSET(superres_qthresh),        AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE},
+    { "superres-kf-denominator", "The denominator for superres to use on key frames.",                 OFFSET(superres_kf_denominator), AV_OPT_TYPE_INT, {.i64 = 8}, 8, 16, VE},
+    { "superres-kf-qthresh",     "The q level threshold after which superres is used for key frames.", OFFSET(superres_kf_qthresh),     AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE},
     { NULL },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 03d7f32f1c..f9b0ae3533 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@ 
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  73
-#define LIBAVCODEC_VERSION_MICRO 103
+#define LIBAVCODEC_VERSION_MICRO 104
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \