From ddc8e7e459749f22b6944f5bab6f79e12ff41826 Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Sun, 15 Dec 2024 14:55:51 -0500 Subject: [PATCH] Use "rav1e" if available as default ("auto") avif encoder --- docs/handbook/image-file-formats.rst | 2 +- src/_avif.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/handbook/image-file-formats.rst b/docs/handbook/image-file-formats.rst index 1e6a832c8..28cf015fd 100644 --- a/docs/handbook/image-file-formats.rst +++ b/docs/handbook/image-file-formats.rst @@ -1370,7 +1370,7 @@ The :py:meth:`~PIL.Image.Image.save` method supports the following options: YUV range, either "full" or "limited". Defaults to "full" **codec** - AV1 codec to use for encoding. Specific values are "aom", "rav1e", and + AV1 codec to use for encoding. Specific values are "rav1e", "aom", and "svt", presuming the chosen codec is available. Defaults to "auto", which will choose the first available codec in the order of the preceding list. diff --git a/src/_avif.c b/src/_avif.c index 45f014f86..5792d6d06 100644 --- a/src/_avif.c +++ b/src/_avif.c @@ -3,6 +3,8 @@ #include #include "avif/avif.h" +static int have_rav1e = 0; + typedef struct { avifPixelFormat subsampling; int qmin; @@ -369,7 +371,11 @@ AvifEncoderNew(PyObject *self_, PyObject *args) { enc_options.speed = speed; if (strcmp(codec, "auto") == 0) { - enc_options.codec = AVIF_CODEC_CHOICE_AUTO; + if (have_rav1e) { + enc_options.codec = AVIF_CODEC_CHOICE_RAV1E; + } else { + enc_options.codec = AVIF_CODEC_CHOICE_AUTO; + } } else { enc_options.codec = avifCodecChoiceFromName(codec); } @@ -1015,6 +1021,8 @@ setup_module(PyObject *m) { PyDict_SetItemString(d, "libavif_version", v ? v : Py_None); Py_XDECREF(v); + have_rav1e = _codec_available("rav1e", AVIF_CODEC_FLAG_CAN_ENCODE); + return 0; }