From 6f0ecbabf3d4bc501339f533de785bbfed5d1a22 Mon Sep 17 00:00:00 2001 From: Wyatt Date: Wed, 7 Feb 2024 14:57:52 -0500 Subject: [PATCH] fix: limit maxThreads to 64 for AOM encodes Fixes #23 Co-authored-by: Frankie Dintino --------- Co-authored-by: Wyatt Borsos Co-authored-by: Wyatt Co-authored-by: Frankie Dintino --- src/pillow_avif/_avif.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pillow_avif/_avif.c b/src/pillow_avif/_avif.c index 3b2970d..68c4d01 100644 --- a/src/pillow_avif/_avif.c +++ b/src/pillow_avif/_avif.c @@ -448,7 +448,11 @@ AvifEncoderNew(PyObject *self_, PyObject *args) { init_max_threads(); } - encoder->maxThreads = max_threads; + int is_aom_encode = strcmp(codec, "aom") == 0 || + (strcmp(codec, "auto") == 0 && + _codec_available("aom", AVIF_CODEC_FLAG_CAN_ENCODE)); + + encoder->maxThreads = is_aom_encode && max_threads > 64 ? 64 : max_threads; #if AVIF_VERSION >= 1000000 if (enc_options.qmin != -1 && enc_options.qmax != -1) { encoder->minQuantizer = enc_options.qmin;