* [FFmpeg-devel] [PATCH] avcodec/libjxlenc: Additional AVOptions (PR #21051)
@ 2025-11-30 1:51 Leo Izen via ffmpeg-devel
0 siblings, 0 replies; only message in thread
From: Leo Izen via ffmpeg-devel @ 2025-11-30 1:51 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Leo Izen
PR #21051 opened by Leo Izen (Traneptora)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21051
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21051.patch
This PR adds several new AVOptions to libavcodec's libjxlenc wrapper which are exposed by libjxl and cjxl.
>From 3ad6faa95dd0891e5774e6811f1d5baa455c1fa4 Mon Sep 17 00:00:00 2001
From: Leo Izen <leo.izen@gmail.com>
Date: Thu, 27 Nov 2025 14:00:32 -0500
Subject: [PATCH 1/3] avcodec/libjxlenc: add decoding_speed AVOption
This adds the decoding_speed AVOption which corresponds with the
faster_decoding option on cjxl, and the library's frame setting
JXL_FRAME_SETTING_DECODING_SPEED.
Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
libavcodec/libjxlenc.c | 9 +++++++++
libavcodec/version.h | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index a2fec89560..a1b872d156 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -56,6 +56,7 @@ typedef struct LibJxlEncodeContext {
float distance;
int modular;
int xyb;
+ int decoding_speed;
uint8_t *buffer;
size_t buffer_size;
JxlPixelFormat jxl_fmt;
@@ -528,6 +529,12 @@ static int libjxl_preprocess_frame(AVCodecContext *avctx, const AVFrame *frame,
return AVERROR_EXTERNAL;
}
+ if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_DECODING_SPEED, ctx->decoding_speed)
+ != JXL_ENC_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set faster decoding option: %d\n", ctx->decoding_speed);
+ return AVERROR_EXTERNAL;
+ }
+
jxl_fmt->endianness = JXL_NATIVE_ENDIAN;
if (frame->linesize[0] >= 0) {
jxl_fmt->align = frame->linesize[0];
@@ -757,6 +764,8 @@ static const AVOption libjxl_encode_options[] = {
{ "modular", "Force modular mode", OFFSET(modular), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "xyb", "Use XYB-encoding for lossy images", OFFSET(xyb),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
+ { "decoding_speed", "Enable faster decoding at cost of density", OFFSET(decoding_speed),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 4, VE },
{ NULL },
};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index da6f3a84ac..9411511e04 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#include "version_major.h"
-#define LIBAVCODEC_VERSION_MINOR 21
+#define LIBAVCODEC_VERSION_MINOR 22
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
--
2.49.1
>From c9acedd7deeb7e21f65e4fbecf5dc9f124c7e3e9 Mon Sep 17 00:00:00 2001
From: Leo Izen <leo.izen@gmail.com>
Date: Thu, 27 Nov 2025 14:21:55 -0500
Subject: [PATCH 2/3] avcodec/libjxlenc: add lf_frames AVOption
This commit adds the AVOption lf_frames to the libjxl encoder wrapper
which lets the user set how many LF Frames they want the resulting
JPEG XL file to have.
This maps to --progressive_dc in cjxl, and the libjxl frame setting
JXL_FRAME_SETTING_PROGRESSIVE_DC.
Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
libavcodec/libjxlenc.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index a1b872d156..bcf325b88f 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -57,6 +57,7 @@ typedef struct LibJxlEncodeContext {
int modular;
int xyb;
int decoding_speed;
+ int lf_frames;
uint8_t *buffer;
size_t buffer_size;
JxlPixelFormat jxl_fmt;
@@ -535,6 +536,12 @@ static int libjxl_preprocess_frame(AVCodecContext *avctx, const AVFrame *frame,
return AVERROR_EXTERNAL;
}
+ if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_PROGRESSIVE_DC, ctx->lf_frames)
+ != JXL_ENC_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set lf frames: %d\n", ctx->lf_frames);
+ return AVERROR_EXTERNAL;
+ }
+
jxl_fmt->endianness = JXL_NATIVE_ENDIAN;
if (frame->linesize[0] >= 0) {
jxl_fmt->align = frame->linesize[0];
@@ -766,6 +773,9 @@ static const AVOption libjxl_encode_options[] = {
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
{ "decoding_speed", "Enable faster decoding at cost of density", OFFSET(decoding_speed),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 4, VE },
+ { "lf_frames", "The number of progressive LF Frames. "
+ "(-1 for encoder chooses)", OFFSET(lf_frames),
+ AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE },
{ NULL },
};
--
2.49.1
>From fa9f9d254b250fee5fca791d01abb285a74dece9 Mon Sep 17 00:00:00 2001
From: Leo Izen <leo.izen@gmail.com>
Date: Sat, 29 Nov 2025 20:47:24 -0500
Subject: [PATCH 3/3] avcodec/libjxlenc: add photon_noise AVOption
This commit adds the AVOption photon_noise to the libjxl encoder wrapper
which lets the user set how much photon noise to add upon decoding.
This maps to --photon_noise in cjxl, and the libjxl frame setting
JXL_FRAME_SETTING_PHOTON_NOISE.
Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
libavcodec/libjxlenc.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index bcf325b88f..e786a55f28 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -58,6 +58,7 @@ typedef struct LibJxlEncodeContext {
int xyb;
int decoding_speed;
int lf_frames;
+ int photon_noise;
uint8_t *buffer;
size_t buffer_size;
JxlPixelFormat jxl_fmt;
@@ -542,6 +543,12 @@ static int libjxl_preprocess_frame(AVCodecContext *avctx, const AVFrame *frame,
return AVERROR_EXTERNAL;
}
+ if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_PHOTON_NOISE, ctx->photon_noise)
+ != JXL_ENC_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set photon noise: %d\n", ctx->photon_noise);
+ return AVERROR_EXTERNAL;
+ }
+
jxl_fmt->endianness = JXL_NATIVE_ENDIAN;
if (frame->linesize[0] >= 0) {
jxl_fmt->align = frame->linesize[0];
@@ -776,6 +783,10 @@ static const AVOption libjxl_encode_options[] = {
{ "lf_frames", "The number of progressive LF Frames. "
"(-1 for encoder chooses)", OFFSET(lf_frames),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE },
+ { "photon_noise", "Add photon noise, in ISO film units. Mimics film "
+ "of the given value, e.g. ISO800. (default = 0, "
+ "i.e. no noise)", OFFSET(photon_noise),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 16000, VE },
{ NULL },
};
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-11-30 1:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-30 1:51 [FFmpeg-devel] [PATCH] avcodec/libjxlenc: Additional AVOptions (PR #21051) Leo Izen via ffmpeg-devel
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git