summaryrefslogtreecommitdiffstats
path: root/video/image_writer.c
diff options
context:
space:
mode:
authorLeo Izen <leo.izen@gmail.com>2022-04-23 14:24:09 -0400
committerJan Ekström <jeebjp@gmail.com>2022-04-26 16:48:00 +0300
commit1345977f997611799c121dda9dee3870a6751421 (patch)
tree012ebaf65a35e2325b70d24545ac0c074da00c86 /video/image_writer.c
parentbb5b4b1ba61b67da40c85c34376aced9383fc366 (diff)
downloadmpv-1345977f997611799c121dda9dee3870a6751421.tar.bz2
mpv-1345977f997611799c121dda9dee3870a6751421.tar.xz
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.
Diffstat (limited to 'video/image_writer.c')
-rw-r--r--video/image_writer.c18
1 files changed, 18 insertions, 0 deletions
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 <string.h>
#include <libavcodec/avcodec.h>
+#include <libavcodec/version.h>
#include <libavutil/mem.h>
#include <libavutil/opt.h>
+#include <libavutil/version.h>
#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) {