From d37a5a1b59063539aa8a628f0a2a1b86d246e2b7 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 10 Oct 2024 16:11:33 +0100 Subject: [PATCH] aom encoder: expose auto-tiles boolean option (since v3.10.0) Setting this option allows libaom to determine the optimum tile count for the given output dimensions and available threads. This typically reduces encoding (wall clock) time and/or peak RAM consumption at the cost of slightly increased file sizes. --- libheif/plugins/encoder_aom.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libheif/plugins/encoder_aom.cc b/libheif/plugins/encoder_aom.cc index 59fbe8d936..aeada1e9d7 100644 --- a/libheif/plugins/encoder_aom.cc +++ b/libheif/plugins/encoder_aom.cc @@ -71,6 +71,7 @@ struct encoder_struct_aom int threads; bool lossless; bool lossless_alpha; + bool auto_tiles; #if defined(HAVE_AOM_CODEC_SET_OPTION) std::vector custom_options; @@ -159,6 +160,7 @@ static const char* kParam_alpha_quality = "alpha-quality"; static const char* kParam_alpha_min_q = "alpha-min-q"; static const char* kParam_alpha_max_q = "alpha-max-q"; static const char* kParam_lossless_alpha = "lossless-alpha"; +static const char* kParam_auto_tiles = "auto-tiles"; static const char* kParam_threads = "threads"; static const char* kParam_realtime = "realtime"; static const char* kParam_speed = "speed"; @@ -197,7 +199,7 @@ static const char* aom_plugin_name() } -#define MAX_NPARAMETERS 14 +#define MAX_NPARAMETERS 15 static struct heif_encoder_parameter aom_encoder_params[MAX_NPARAMETERS]; static const struct heif_encoder_parameter* aom_encoder_parameter_ptrs[MAX_NPARAMETERS + 1]; @@ -362,6 +364,14 @@ static void aom_init_parameters() p->has_default = true; d[i++] = p++; + assert(i < MAX_NPARAMETERS); + p->version = 2; + p->name = kParam_auto_tiles; + p->type = heif_encoder_parameter_type_boolean; + p->boolean.default_value = false; + p->has_default = true; + d[i++] = p++; + assert(i < MAX_NPARAMETERS + 1); d[i++] = nullptr; } @@ -571,6 +581,9 @@ struct heif_error aom_set_parameter_boolean(void* encoder_raw, const char* name, encoder->alpha_min_q_set = true; } return heif_error_ok; + } else if (strcmp(name, kParam_auto_tiles) == 0) { + encoder->auto_tiles = value; + return heif_error_ok; } set_value(kParam_realtime, realtime_mode); @@ -980,6 +993,11 @@ struct heif_error aom_encode_image(void* encoder_raw, const struct heif_image* i #endif } +#if defined(AOM_CTRL_AV1E_SET_AUTO_TILES) + // aom 3.10.0 + aom_codec_control(&codec, AV1E_SET_AUTO_TILES, encoder->auto_tiles); +#endif + // TODO: set AV1E_SET_TILE_ROWS and AV1E_SET_TILE_COLUMNS.