FFmpeg
libjxlenc.c
Go to the documentation of this file.
1 /*
2  * JPEG XL encoding support via libjxl
3  * Copyright (c) 2021 Leo Izen <leo.izen@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * JPEG XL encoder using libjxl
25  */
26 
27 #include <string.h>
28 
29 #include "libavutil/avutil.h"
30 #include "libavutil/csp.h"
31 #include "libavutil/error.h"
32 #include "libavutil/frame.h"
33 #include "libavutil/libm.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/pixdesc.h"
36 #include "libavutil/pixfmt.h"
37 #include "libavutil/version.h"
38 
39 #include "avcodec.h"
40 #include "encode.h"
41 #include "codec_internal.h"
42 
43 #include <jxl/encode.h>
44 #include <jxl/thread_parallel_runner.h>
45 #include "libjxl.h"
46 
47 typedef struct LibJxlEncodeContext {
48  AVClass *class;
49  void *runner;
50  JxlEncoder *encoder;
51  JxlEncoderFrameSettings *options;
52  int effort;
53  float distance;
54  int modular;
55  uint8_t *buffer;
56  size_t buffer_size;
58 
59 /**
60  * Map a quality setting for -qscale roughly from libjpeg
61  * quality numbers to libjxl's butteraugli distance for
62  * photographic content.
63  *
64  * Setting distance explicitly is preferred, but this will
65  * allow qscale to be used as a fallback.
66  *
67  * This function is continuous and injective on [0, 100] which
68  * makes it monotonic.
69  *
70  * @param quality 0.0 to 100.0 quality setting, libjpeg quality
71  * @return Butteraugli distance between 0.0 and 15.0
72  */
73 static float quality_to_distance(float quality)
74 {
75  if (quality >= 100.0)
76  return 0.0;
77  else if (quality >= 90.0)
78  return (100.0 - quality) * 0.10;
79  else if (quality >= 30.0)
80  return 0.1 + (100.0 - quality) * 0.09;
81  else if (quality > 0.0)
82  return 15.0 + (59.0 * quality - 4350.0) * quality / 9000.0;
83  else
84  return 15.0;
85 }
86 
87 /**
88  * Initalize the decoder on a per-frame basis. All of these need to be set
89  * once each time the decoder is reset, which it must be each frame to make
90  * the image2 muxer work.
91  *
92  * @return 0 upon success, negative on failure.
93  */
95 {
97 
98  /* reset the encoder every frame for image2 muxer */
99  JxlEncoderReset(ctx->encoder);
100 
101  ctx->options = JxlEncoderFrameSettingsCreate(ctx->encoder, NULL);
102  if (!ctx->options) {
103  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoderOptions\n");
104  return AVERROR_EXTERNAL;
105  }
106 
107  /* This needs to be set each time the decoder is reset */
108  if (JxlEncoderSetParallelRunner(ctx->encoder, JxlThreadParallelRunner, ctx->runner)
109  != JXL_ENC_SUCCESS) {
110  av_log(avctx, AV_LOG_ERROR, "Failed to set JxlThreadParallelRunner\n");
111  return AVERROR_EXTERNAL;
112  }
113 
114  /* these shouldn't fail, libjxl bug notwithstanding */
115  if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_EFFORT, ctx->effort)
116  != JXL_ENC_SUCCESS) {
117  av_log(avctx, AV_LOG_ERROR, "Failed to set effort to: %d\n", ctx->effort);
118  return AVERROR_EXTERNAL;
119  }
120 
121  /* check for negative, our default */
122  if (ctx->distance < 0.0) {
123  /* use ffmpeg.c -q option if passed */
124  if (avctx->flags & AV_CODEC_FLAG_QSCALE)
125  ctx->distance = quality_to_distance((float)avctx->global_quality / FF_QP2LAMBDA);
126  else
127  /* default 1.0 matches cjxl */
128  ctx->distance = 1.0;
129  }
130 
131  /*
132  * 0.01 is the minimum distance accepted for lossy
133  * interpreting any positive value less than this as minimum
134  */
135  if (ctx->distance > 0.0 && ctx->distance < 0.01)
136  ctx->distance = 0.01;
137  if (JxlEncoderSetFrameDistance(ctx->options, ctx->distance) != JXL_ENC_SUCCESS) {
138  av_log(avctx, AV_LOG_ERROR, "Failed to set distance: %f\n", ctx->distance);
139  return AVERROR_EXTERNAL;
140  }
141 
142  /*
143  * In theory the library should automatically enable modular if necessary,
144  * but it appears it won't at the moment due to a bug. This will still
145  * work even if that is patched.
146  */
147  if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_MODULAR,
148  ctx->modular || ctx->distance <= 0.0 ? 1 : -1) != JXL_ENC_SUCCESS) {
149  av_log(avctx, AV_LOG_ERROR, "Failed to set modular\n");
150  return AVERROR_EXTERNAL;
151  }
152 
153  return 0;
154 }
155 
156 /**
157  * Global encoder initialization. This only needs to be run once,
158  * not every frame.
159  */
161 {
163  JxlMemoryManager manager;
164 
166  ctx->encoder = JxlEncoderCreate(&manager);
167  if (!ctx->encoder) {
168  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoder\n");
169  return AVERROR_EXTERNAL;
170  }
171 
172  ctx->runner = JxlThreadParallelRunnerCreate(&manager, ff_libjxl_get_threadcount(avctx->thread_count));
173  if (!ctx->runner) {
174  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlThreadParallelRunner\n");
175  return AVERROR_EXTERNAL;
176  }
177 
178  ctx->buffer_size = 4096;
179  ctx->buffer = av_realloc(NULL, ctx->buffer_size);
180 
181  if (!ctx->buffer) {
182  av_log(avctx, AV_LOG_ERROR, "Could not allocate encoding buffer\n");
183  return AVERROR(ENOMEM);
184  }
185 
186  return 0;
187 }
188 
189 /**
190  * Populate a JxlColorEncoding with the given enum AVColorPrimaries.
191  * @return < 0 upon failure, >= 0 upon success
192  */
193 static int libjxl_populate_primaries(void *avctx, JxlColorEncoding *jxl_color, enum AVColorPrimaries prm)
194 {
195  const AVColorPrimariesDesc *desc;
196 
197  switch (prm) {
198  case AVCOL_PRI_BT709:
199  jxl_color->primaries = JXL_PRIMARIES_SRGB;
200  jxl_color->white_point = JXL_WHITE_POINT_D65;
201  return 0;
202  case AVCOL_PRI_BT2020:
203  jxl_color->primaries = JXL_PRIMARIES_2100;
204  jxl_color->white_point = JXL_WHITE_POINT_D65;
205  return 0;
206  case AVCOL_PRI_SMPTE431:
207  jxl_color->primaries = JXL_PRIMARIES_P3;
208  jxl_color->white_point = JXL_WHITE_POINT_DCI;
209  return 0;
210  case AVCOL_PRI_SMPTE432:
211  jxl_color->primaries = JXL_PRIMARIES_P3;
212  jxl_color->white_point = JXL_WHITE_POINT_D65;
213  return 0;
215  av_log(avctx, AV_LOG_WARNING, "Unknown primaries, assuming BT.709/sRGB. Colors may be wrong.\n");
216  jxl_color->primaries = JXL_PRIMARIES_SRGB;
217  jxl_color->white_point = JXL_WHITE_POINT_D65;
218  return 0;
219  }
220 
222  if (!desc)
223  return AVERROR(EINVAL);
224 
225  jxl_color->primaries = JXL_PRIMARIES_CUSTOM;
226  jxl_color->white_point = JXL_WHITE_POINT_CUSTOM;
227 
228  jxl_color->primaries_red_xy[0] = av_q2d(desc->prim.r.x);
229  jxl_color->primaries_red_xy[1] = av_q2d(desc->prim.r.y);
230  jxl_color->primaries_green_xy[0] = av_q2d(desc->prim.g.x);
231  jxl_color->primaries_green_xy[1] = av_q2d(desc->prim.g.y);
232  jxl_color->primaries_blue_xy[0] = av_q2d(desc->prim.b.x);
233  jxl_color->primaries_blue_xy[1] = av_q2d(desc->prim.b.y);
234  jxl_color->white_point_xy[0] = av_q2d(desc->wp.x);
235  jxl_color->white_point_xy[1] = av_q2d(desc->wp.y);
236 
237  return 0;
238 }
239 
240 /**
241  * Encode an entire frame. Currently animation, is not supported by
242  * this encoder, so this will always reinitialize a new still image
243  * and encode a one-frame image (for image2 and image2pipe).
244  */
245 static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
246 {
248  AVFrameSideData *sd;
250  JxlBasicInfo info;
251  JxlColorEncoding jxl_color;
252  JxlPixelFormat jxl_fmt;
253  int bits_per_sample;
254 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
255  JxlBitDepth jxl_bit_depth;
256 #endif
257  JxlEncoderStatus jret;
258  int ret;
259  size_t available = ctx->buffer_size;
260  size_t bytes_written = 0;
261  uint8_t *next_out = ctx->buffer;
262 
263  ret = libjxl_init_jxl_encoder(avctx);
264  if (ret) {
265  av_log(avctx, AV_LOG_ERROR, "Error frame-initializing JxlEncoder\n");
266  return ret;
267  }
268 
269  /* populate the basic info settings */
270  JxlEncoderInitBasicInfo(&info);
271  jxl_fmt.num_channels = pix_desc->nb_components;
272  info.xsize = frame->width;
273  info.ysize = frame->height;
274  info.num_extra_channels = (jxl_fmt.num_channels + 1) % 2;
275  info.num_color_channels = jxl_fmt.num_channels - info.num_extra_channels;
276  bits_per_sample = av_get_bits_per_pixel(pix_desc) / jxl_fmt.num_channels;
277  info.bits_per_sample = avctx->bits_per_raw_sample > 0 && !(pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT)
278  ? avctx->bits_per_raw_sample : bits_per_sample;
279  info.alpha_bits = (info.num_extra_channels > 0) * info.bits_per_sample;
280  if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
281  info.exponent_bits_per_sample = info.bits_per_sample > 16 ? 8 : 5;
282  info.alpha_exponent_bits = info.alpha_bits ? info.exponent_bits_per_sample : 0;
283  jxl_fmt.data_type = info.bits_per_sample > 16 ? JXL_TYPE_FLOAT : JXL_TYPE_FLOAT16;
284  } else {
285  info.exponent_bits_per_sample = 0;
286  info.alpha_exponent_bits = 0;
287  jxl_fmt.data_type = info.bits_per_sample <= 8 ? JXL_TYPE_UINT8 : JXL_TYPE_UINT16;
288  }
289 
290 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
291  jxl_bit_depth.bits_per_sample = bits_per_sample;
292  jxl_bit_depth.type = JXL_BIT_DEPTH_FROM_PIXEL_FORMAT;
293  jxl_bit_depth.exponent_bits_per_sample = pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT ?
294  info.exponent_bits_per_sample : 0;
295 #endif
296 
297  /* JPEG XL format itself does not support limited range */
298  if (avctx->color_range == AVCOL_RANGE_MPEG ||
300  av_log(avctx, AV_LOG_WARNING, "This encoder does not support limited (tv) range, colors will be wrong!\n");
302  av_log(avctx, AV_LOG_WARNING, "Unknown color range, assuming full (pc)\n");
303 
304  /* bitexact lossless requires there to be no XYB transform */
305  info.uses_original_profile = ctx->distance == 0.0;
306 
307  if (JxlEncoderSetBasicInfo(ctx->encoder, &info) != JXL_ENC_SUCCESS) {
308  av_log(avctx, AV_LOG_ERROR, "Failed to set JxlBasicInfo\n");
309  return AVERROR_EXTERNAL;
310  }
311 
312  /* rendering intent doesn't matter here
313  * but libjxl will whine if we don't set it */
314  jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
315 
317  ? frame->color_trc : avctx->color_trc) {
318  case AVCOL_TRC_BT709:
319  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_709;
320  break;
321  case AVCOL_TRC_LINEAR:
322  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
323  break;
325  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
326  break;
327  case AVCOL_TRC_SMPTE428:
328  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_DCI;
329  break;
330  case AVCOL_TRC_SMPTE2084:
331  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_PQ;
332  break;
334  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_HLG;
335  break;
336  case AVCOL_TRC_GAMMA22:
337  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
338  jxl_color.gamma = 1/2.2f;
339  break;
340  case AVCOL_TRC_GAMMA28:
341  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
342  jxl_color.gamma = 1/2.8f;
343  break;
344  default:
345  if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
346  av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming Linear Light. Colors may be wrong.\n");
347  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
348  } else {
349  av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming IEC61966-2-1/sRGB. Colors may be wrong.\n");
350  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
351  }
352  }
353 
354  /* This should be implied to be honest
355  * but a libjxl bug makes it fail otherwise */
356  if (info.num_color_channels == 1)
357  jxl_color.color_space = JXL_COLOR_SPACE_GRAY;
358  else
359  jxl_color.color_space = JXL_COLOR_SPACE_RGB;
360 
361  ret = libjxl_populate_primaries(avctx, &jxl_color,
364  if (ret < 0)
365  return ret;
366 
368  if (sd && sd->size && JxlEncoderSetICCProfile(ctx->encoder, sd->data, sd->size) != JXL_ENC_SUCCESS)
369  av_log(avctx, AV_LOG_WARNING, "Could not set ICC Profile\n");
370  if (JxlEncoderSetColorEncoding(ctx->encoder, &jxl_color) != JXL_ENC_SUCCESS)
371  av_log(avctx, AV_LOG_WARNING, "Failed to set JxlColorEncoding\n");
372 
373 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
374  if (JxlEncoderSetFrameBitDepth(ctx->options, &jxl_bit_depth) != JXL_ENC_SUCCESS)
375  av_log(avctx, AV_LOG_WARNING, "Failed to set JxlBitDepth\n");
376 #endif
377 
378  /* depending on basic info, level 10 might
379  * be required instead of level 5 */
380  if (JxlEncoderGetRequiredCodestreamLevel(ctx->encoder) > 5) {
381  if (JxlEncoderSetCodestreamLevel(ctx->encoder, 10) != JXL_ENC_SUCCESS)
382  av_log(avctx, AV_LOG_WARNING, "Could not increase codestream level\n");
383  }
384 
385  jxl_fmt.endianness = JXL_NATIVE_ENDIAN;
386  jxl_fmt.align = frame->linesize[0];
387 
388  if (JxlEncoderAddImageFrame(ctx->options, &jxl_fmt, frame->data[0], jxl_fmt.align * info.ysize) != JXL_ENC_SUCCESS) {
389  av_log(avctx, AV_LOG_ERROR, "Failed to add Image Frame\n");
390  return AVERROR_EXTERNAL;
391  }
392 
393  /*
394  * Run this after the last frame in the image has been passed.
395  * TODO support animation
396  */
397  JxlEncoderCloseInput(ctx->encoder);
398 
399  while (1) {
400  jret = JxlEncoderProcessOutput(ctx->encoder, &next_out, &available);
401  if (jret == JXL_ENC_ERROR) {
402  av_log(avctx, AV_LOG_ERROR, "Unspecified libjxl error occurred\n");
403  return AVERROR_EXTERNAL;
404  }
405  bytes_written = ctx->buffer_size - available;
406  /* all data passed has been encoded */
407  if (jret == JXL_ENC_SUCCESS)
408  break;
409  if (jret == JXL_ENC_NEED_MORE_OUTPUT) {
410  /*
411  * at the moment, libjxl has no way to
412  * tell us how much space it actually needs
413  * so we need to malloc loop
414  */
415  uint8_t *temp;
416  size_t new_size = ctx->buffer_size * 2;
417  temp = av_realloc(ctx->buffer, new_size);
418  if (!temp)
419  return AVERROR(ENOMEM);
420  ctx->buffer = temp;
421  ctx->buffer_size = new_size;
422  next_out = ctx->buffer + bytes_written;
423  available = new_size - bytes_written;
424  continue;
425  }
426  av_log(avctx, AV_LOG_ERROR, "Bad libjxl event: %d\n", jret);
427  return AVERROR_EXTERNAL;
428  }
429 
430  ret = ff_get_encode_buffer(avctx, pkt, bytes_written, 0);
431  if (ret < 0)
432  return ret;
433 
434  memcpy(pkt->data, ctx->buffer, bytes_written);
435  *got_packet = 1;
436 
437  return 0;
438 }
439 
441 {
443 
444  if (ctx->runner)
445  JxlThreadParallelRunnerDestroy(ctx->runner);
446  ctx->runner = NULL;
447 
448  /*
449  * destroying the decoder also frees
450  * ctx->options so we don't need to
451  */
452  if (ctx->encoder)
453  JxlEncoderDestroy(ctx->encoder);
454  ctx->encoder = NULL;
455 
456  av_freep(&ctx->buffer);
457 
458  return 0;
459 }
460 
461 #define OFFSET(x) offsetof(LibJxlEncodeContext, x)
462 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
463 
464 static const AVOption libjxl_encode_options[] = {
465  { "effort", "Encoding effort", OFFSET(effort), AV_OPT_TYPE_INT, { .i64 = 7 }, 1, 9, VE },
466  { "distance", "Maximum Butteraugli distance (quality setting, "
467  "lower = better, zero = lossless, default 1.0)", OFFSET(distance), AV_OPT_TYPE_FLOAT, { .dbl = -1.0 }, -1.0, 15.0, VE },
468  { "modular", "Force modular mode", OFFSET(modular), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
469  { NULL },
470 };
471 
472 static const AVClass libjxl_encode_class = {
473  .class_name = "libjxl",
474  .item_name = av_default_item_name,
475  .option = libjxl_encode_options,
476  .version = LIBAVUTIL_VERSION_INT,
477 };
478 
480  .p.name = "libjxl",
481  CODEC_LONG_NAME("libjxl JPEG XL"),
482  .p.type = AVMEDIA_TYPE_VIDEO,
483  .p.id = AV_CODEC_ID_JPEGXL,
484  .priv_data_size = sizeof(LibJxlEncodeContext),
487  .close = libjxl_encode_close,
488  .p.capabilities = AV_CODEC_CAP_OTHER_THREADS |
490  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
493  .p.pix_fmts = (const enum AVPixelFormat[]) {
500  },
501  .p.priv_class = &libjxl_encode_class,
502  .p.wrapper_name = "libjxl",
503 };
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:660
LibJxlEncodeContext::effort
int effort
Definition: libjxlenc.c:52
LibJxlEncodeContext::options
JxlEncoderFrameSettings * options
Definition: libjxlenc.c:51
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:656
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
LibJxlEncodeContext::buffer_size
size_t buffer_size
Definition: libjxlenc.c:56
ff_libjxl_get_threadcount
size_t ff_libjxl_get_threadcount(int threads)
Transform threadcount in ffmpeg to one used by libjxl.
Definition: libjxl.c:33
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:133
libm.h
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:824
VE
#define VE
Definition: libjxlenc.c:462
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:78
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2964
LibJxlEncodeContext::runner
void * runner
Definition: libjxlenc.c:49
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:579
AV_CODEC_FLAG_QSCALE
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:220
AV_PIX_FMT_FLAG_FLOAT
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:158
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:658
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1022
AVFrame::width
int width
Definition: frame.h:412
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:673
AVPacket::data
uint8_t * data
Definition: packet.h:491
AVOption
AVOption.
Definition: opt.h:251
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:573
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:34
FFCodec
Definition: codec_internal.h:127
libjxl.h
av_get_bits_per_pixel
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:2916
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:545
quality
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
Definition: rate_distortion.txt:12
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:584
OFFSET
#define OFFSET(x)
Definition: libjxlenc.c:461
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1532
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:576
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:452
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
LibJxlEncodeContext::modular
int modular
Definition: libjxlenc.c:54
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:575
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1015
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVFrameSideData::size
size_t size
Definition: frame.h:249
av_cold
#define av_cold
Definition: attributes.h:90
AVCodecContext::global_quality
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:507
av_csp_primaries_desc_from_id
const AVColorPrimariesDesc * av_csp_primaries_desc_from_id(enum AVColorPrimaries prm)
Retrieves a complete gamut description from an enum constant describing the color primaries.
Definition: csp.c:90
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
AV_CODEC_CAP_OTHER_THREADS
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:124
info
MIPS optimizations info
Definition: mips.txt:2
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1517
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:501
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:548
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
frame
static AVFrame * frame
Definition: demux_decode.c:54
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:458
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1039
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
LibJxlEncodeContext::buffer
uint8_t * buffer
Definition: libjxlenc.c:55
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:547
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_FRAME_DATA_ICC_PROFILE
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:144
libjxl_init_jxl_encoder
static int libjxl_init_jxl_encoder(AVCodecContext *avctx)
Initalize the decoder on a per-frame basis.
Definition: libjxlenc.c:94
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:639
LibJxlEncodeContext
Definition: libjxlenc.c:47
error.h
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:556
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:587
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:559
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
codec_internal.h
libjxl_encode_frame
static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Encode an entire frame.
Definition: libjxlenc.c:245
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:454
AVFrameSideData::data
uint8_t * data
Definition: frame.h:248
ff_libjxl_encoder
const FFCodec ff_libjxl_encoder
Definition: libjxlenc.c:479
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
frame.h
csp.h
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
quality_to_distance
static float quality_to_distance(float quality)
Map a quality setting for -qscale roughly from libjpeg quality numbers to libjxl's butteraugli distan...
Definition: libjxlenc.c:73
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:572
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
LibJxlEncodeContext::distance
float distance
Definition: libjxlenc.c:53
libjxl_populate_primaries
static int libjxl_populate_primaries(void *avctx, JxlColorEncoding *jxl_color, enum AVColorPrimaries prm)
Populate a JxlColorEncoding with the given enum AVColorPrimaries.
Definition: libjxlenc.c:193
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:453
libjxl_encode_init
static av_cold int libjxl_encode_init(AVCodecContext *avctx)
Global encoder initialization.
Definition: libjxlenc.c:160
available
if no frame is available
Definition: filter_design.txt:166
AV_CODEC_ID_JPEGXL
@ AV_CODEC_ID_JPEGXL
Definition: codec_id.h:316
libjxl_encode_close
static av_cold int libjxl_encode_close(AVCodecContext *avctx)
Definition: libjxlenc.c:440
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:656
FF_CODEC_CAP_ICC_PROFILES
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
Definition: codec_internal.h:82
libjxl_encode_class
static const AVClass libjxl_encode_class
Definition: libjxlenc.c:472
avcodec.h
version.h
ret
ret
Definition: filter_design.txt:187
pixfmt.h
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
AVCodecContext
main external API structure.
Definition: avcodec.h:441
AVFrame::height
int height
Definition: frame.h:412
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:591
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:105
libjxl_encode_options
static const AVOption libjxl_encode_options[]
Definition: libjxlenc.c:464
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
temp
else temp
Definition: vf_mcdeint.c:263
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avutil.h
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:73
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:246
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVCOL_PRI_SMPTE432
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:560
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
ff_libjxl_init_memory_manager
void ff_libjxl_init_memory_manager(JxlMemoryManager *manager)
Initialize and populate a JxlMemoryManager with av_malloc() and av_free() so libjxl will use these fu...
Definition: libjxl.c:65
distance
static float distance(float x, float y, int band)
Definition: nellymoserenc.c:230
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVCOL_TRC_SMPTE428
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
Definition: pixfmt.h:589
LibJxlEncodeContext::encoder
JxlEncoder * encoder
Definition: libjxlenc.c:50
FF_QP2LAMBDA
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:153