diff mbox series

[FFmpeg-devel,1/2] libavcodec/libaomenc.c: Add a libaom command-line opton 'tune'

Message ID 20200303214321.39335-1-wangcao@google.com
State Superseded
Headers show
Series [FFmpeg-devel,1/2] libavcodec/libaomenc.c: Add a libaom command-line opton '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 3, 2020, 9:43 p.m. UTC
Signed-off-by: Wang Cao <wangcao@google.com>
---
 doc/encoders.texi      | 11 +++++++++++
 libavcodec/libaomenc.c |  7 +++++++
 2 files changed, 18 insertions(+)

Comments

Carl Eugen Hoyos March 3, 2020, 9:57 p.m. UTC | #1
Am Di., 3. März 2020 um 22:43 Uhr schrieb Wang Cao <doubleecao@gmail.com>:

> +@item tune (@emph{tune})
> +Set the distortion metric tuned with for encoder. Default is PSNR.
> +
> +@table @samp
> +@item psnr (@emph{0})
> +PSNR as distortion metric
> +
> +@item ssim (@emph{1})
> +SSIM as distortion metric
> +@end table

My knowledge of video encoding is limited but I would have
expected (actually I was sure) that the default would be
"visual" or similar and not an artificial metric.

Does this mean libaom is only made to please automatic
comparison tests?

Carl Eugen
Wang Cao March 3, 2020, 11:50 p.m. UTC | #2
It would be ideal to have the encoder optimizes visual quality. However,
the ideal of "visual" metric is subjective and the related research is
ongoing. Actually libaom has support for VMAF and other metrics but they
probably require a different config while compiling libaom. PSNR and SSIM
are two metrics that the library definitely has default support with.

On Tue, Mar 3, 2020 at 2:50 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Am Di., 3. März 2020 um 22:43 Uhr schrieb Wang Cao <doubleecao@gmail.com>:
>
> > +@item tune (@emph{tune})
> > +Set the distortion metric tuned with for encoder. Default is PSNR.
> > +
> > +@table @samp
> > +@item psnr (@emph{0})
> > +PSNR as distortion metric
> > +
> > +@item ssim (@emph{1})
> > +SSIM as distortion metric
> > +@end table
>
> My knowledge of video encoding is limited but I would have
> expected (actually I was sure) that the default would be
> "visual" or similar and not an artificial metric.
>
> Does this mean libaom is only made to please automatic
> comparison tests?
>
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Carl Eugen Hoyos March 3, 2020, 11:52 p.m. UTC | #3
Am Mi., 4. März 2020 um 00:51 Uhr schrieb Wang Cao
<wangcao-at-google.com@ffmpeg.org>:

[...]

Please find out what "top-posting" means and avoid it here.

Carl Eugen
Wang Cao March 4, 2020, 12:04 a.m. UTC | #4
On Tue, Mar 3, 2020 at 3:53 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Am Mi., 4. März 2020 um 00:51 Uhr schrieb Wang Cao
> <wangcao-at-google.com@ffmpeg.org>:
>
> [...]
>
> Please find out what "top-posting" means and avoid it here.
>
> Carl Eugen
>
I am very sorry about this my "top-posting" there. As soon as I hit "send"
I realized my mistake of being top-posting. I really apologize for replying
in this way.
Wang Cao March 4, 2020, 12:18 a.m. UTC | #5
Let me reply again with the correct posting form.
On Tue, Mar 3, 2020 at 2:50 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Am Di., 3. März 2020 um 22:43 Uhr schrieb Wang Cao <doubleecao@gmail.com>:
>
> > +@item tune (@emph{tune})
> > +Set the distortion metric tuned with for encoder. Default is PSNR.
> > +
> > +@table @samp
> > +@item psnr (@emph{0})
> > +PSNR as distortion metric
> > +
> > +@item ssim (@emph{1})
> > +SSIM as distortion metric
> > +@end table
>
> My knowledge of video encoding is limited but I would have
> expected (actually I was sure) that the default would be
> "visual" or similar and not an artificial metric.
>
 Yes. I share the share hope as you do. The default should be a metric that
reflects actual human perception of a video. As far as I understand the
current status for now, PSNR and SSIM is the metric that libaom is by
default compiled with. Other metrics are being added support. For example,
VMAF and other metrics are also supported now as you can find them in
https://aomedia.googlesource.com/aom/+/refs/heads/master/aom/aomcx.h. I
added those two metrics trying to be conservative here because I don't know
if some require special configs.

> Does this mean libaom is only made to please automatic
> comparison tests?
>
> Carl Eugen
>
> As I mentioned above, libaom continues to add support for optimizing for
different metrics. I personally do not know if there is a perfect visual
quality metric for now. I will continue to add more options to ffmpeg if I
can make sure those metrics can be used in ffmpeg command-line easily.
diff mbox series

Patch

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e23b6b32fe..4215f237bd 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1508,6 +1508,17 @@  Complexity-based.
 Cyclic refresh.
 @end table
 
+@item tune (@emph{tune})
+Set the distortion metric tuned with for encoder. Default is PSNR.
+
+@table @samp
+@item psnr (@emph{0})
+PSNR as distortion metric
+
+@item ssim (@emph{1})
+SSIM as distortion metric
+@end table
+
 @item lag-in-frames
 Set the maximum number of frames which the encoder may keep in flight
 at any one time for lookahead purposes.  Defaults to the internal
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..7fd624c470 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -94,6 +94,7 @@  typedef struct AOMEncoderContext {
     int enable_intrabc;
     int enable_restoration;
     int usage;
+    int tune;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -132,6 +133,7 @@  static const char *const ctlidstr[] = {
     [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
     [AV1E_SET_ENABLE_CDEF]      = "AV1E_SET_ENABLE_CDEF",
+    [AOME_SET_TUNING]           = "AOME_SET_TUNING",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -699,6 +701,8 @@  static av_cold int aom_init(AVCodecContext *avctx,
     codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
     if (ctx->crf >= 0)
         codecctl_int(avctx, AOME_SET_CQ_LEVEL,          ctx->crf);
+    if (ctx->tune >= 0)
+        codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
     codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
     codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
@@ -1096,6 +1100,9 @@  static const AVOption options[] = {
     { "usage",           "Quality and compression efficiency vs speed tradeof", OFFSET(usage), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "usage"},
     { "good",            "Good quality",      0, AV_OPT_TYPE_CONST, {.i64 = 0 /* AOM_USAGE_GOOD_QUALITY */}, 0, 0, VE, "usage"},
     { "realtime",        "Realtime encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 1 /* AOM_USAGE_REALTIME */},     0, 0, VE, "usage"},
+    { "tune",            "The metric that encoder tunes for", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE, "tune"},
+    { "psnr",            "PSNR as distortion metric",         0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "tune"},
+    { "ssim",            "SSIM as distortion metric",         0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune"},
     { NULL },
 };