From 1345977f997611799c121dda9dee3870a6751421 Mon Sep 17 00:00:00 2001 From: Leo Izen Date: Sat, 23 Apr 2022 14:24:09 -0400 Subject: video/image_writer: add Jpeg XL screenshots Add Jpeg XL as a possible output format for screenshots, which should make it possible to take fast screenshots with much better quality than JPEG, or take lossless high-bit-depth screenshots with lower file sizes than PNG. --- video/image_writer.c | 18 ++++++++++++++++++ video/image_writer.h | 2 ++ 2 files changed, 20 insertions(+) (limited to 'video') diff --git a/video/image_writer.c b/video/image_writer.c index d294a4dc32..d12394a5a9 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -20,8 +20,10 @@ #include #include +#include #include #include +#include #include "config.h" @@ -51,6 +53,8 @@ const struct image_writer_opts image_writer_opts_defaults = { .webp_lossless = 0, .webp_quality = 75, .webp_compression = 4, + .jxl_distance = 1.0, + .jxl_effort = 3, .tag_csp = 0, }; @@ -59,6 +63,9 @@ const struct m_opt_choice_alternatives mp_image_writer_formats[] = { {"jpeg", AV_CODEC_ID_MJPEG}, {"png", AV_CODEC_ID_PNG}, {"webp", AV_CODEC_ID_WEBP}, +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 27, 100) + {"jxl", AV_CODEC_ID_JPEGXL}, +#endif {0} }; @@ -73,6 +80,10 @@ const struct m_option image_writer_opts[] = { {"webp-lossless", OPT_FLAG(webp_lossless)}, {"webp-quality", OPT_INT(webp_quality), M_RANGE(0, 100)}, {"webp-compression", OPT_INT(webp_compression), M_RANGE(0, 6)}, +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 27, 100) + {"jxl-distance", OPT_DOUBLE(jxl_distance), M_RANGE(0.0, 15.0)}, + {"jxl-effort", OPT_INT(jxl_effort), M_RANGE(1, 9)}, +#endif {"high-bit-depth", OPT_FLAG(high_bit_depth)}, {"tag-colorspace", OPT_FLAG(tag_csp)}, {0}, @@ -139,6 +150,13 @@ static bool write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp AV_OPT_SEARCH_CHILDREN); av_opt_set_int(avctx, "quality", ctx->opts->webp_quality, AV_OPT_SEARCH_CHILDREN); +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 27, 100) + } else if (codec->id == AV_CODEC_ID_JPEGXL) { + av_opt_set_double(avctx, "distance", ctx->opts->jxl_distance, + AV_OPT_SEARCH_CHILDREN); + av_opt_set_int(avctx, "effort", ctx->opts->jxl_effort, + AV_OPT_SEARCH_CHILDREN); +#endif } if (avcodec_open2(avctx, codec, NULL) < 0) { diff --git a/video/image_writer.h b/video/image_writer.h index f6d3b58f87..54871bacf0 100644 --- a/video/image_writer.h +++ b/video/image_writer.h @@ -35,6 +35,8 @@ struct image_writer_opts { int webp_lossless; int webp_quality; int webp_compression; + double jxl_distance; + int jxl_effort; int tag_csp; }; -- cgit v1.2.3