Set libaom-specific option -a tune=ssim by default
Note that we have recommended setting -a tune=ssim only for high quality
levels. This pull request sets -a tune=ssim by default for all quality
levels, because we have not determined empirically the quality level
above which -a tune=ssim is better than -a tune=psnr. Also, it is easier
to understand the default value of an option if it is independent of
other options.
Part of https://github.com/AOMediaCodec/libavif/issues/955.
diff --git a/src/codec_aom.c b/src/codec_aom.c
index 3b06147..44deab9 100644
--- a/src/codec_aom.c
+++ b/src/codec_aom.c
@@ -69,6 +69,9 @@
// Whether cq-level was set with an
// avifEncoderSetCodecSpecificOption(encoder, "cq-level", value) call.
avifBool cqLevelSet;
+ // Whether 'tuning' (of the specified distortion metric) was set with an
+ // avifEncoderSetCodecSpecificOption(encoder, "tune", value) call.
+ avifBool tuningSet;
#endif
};
@@ -466,6 +469,8 @@
}
if (!strcmp(key, "cq-level")) {
codec->internal->cqLevelSet = AVIF_TRUE;
+ } else if (!strcmp(key, "tune")) {
+ codec->internal->tuningSet = AVIF_TRUE;
}
#else // !defined(HAVE_AOM_CODEC_SET_OPTION)
avifBool match = AVIF_FALSE;
@@ -500,6 +505,8 @@
}
if (aomOptionDefs[j].controlId == AOME_SET_CQ_LEVEL) {
codec->internal->cqLevelSet = AVIF_TRUE;
+ } else if (aomOptionDefs[j].controlId == AOME_SET_TUNING) {
+ codec->internal->tuningSet = AVIF_TRUE;
}
break;
}
@@ -752,6 +759,11 @@
aom_codec_control(&codec->internal->encoder, AOME_SET_CQ_LEVEL, cqLevel);
}
#endif
+ if (!codec->internal->tuningSet) {
+ if (aom_codec_control(&codec->internal->encoder, AOME_SET_TUNING, AOM_TUNE_SSIM) != AOM_CODEC_OK) {
+ return AVIF_RESULT_UNKNOWN_ERROR;
+ }
+ }
}
aom_image_t aomImage;