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/mem.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/pixdesc.h"
37 #include "libavutil/pixfmt.h"
38 #include "libavutil/version.h"
39 
40 #include "avcodec.h"
41 #include "encode.h"
42 #include "codec_internal.h"
43 
44 #include <jxl/encode.h>
45 #include <jxl/thread_parallel_runner.h>
46 #include "libjxl.h"
47 
48 typedef struct LibJxlEncodeContext {
49  AVClass *class;
50  void *runner;
51  JxlEncoder *encoder;
52  JxlEncoderFrameSettings *options;
53  int effort;
54  float distance;
55  int modular;
56  int xyb;
57  uint8_t *buffer;
58  size_t buffer_size;
60 
61 /**
62  * Map a quality setting for -qscale roughly from libjpeg
63  * quality numbers to libjxl's butteraugli distance for
64  * photographic content.
65  *
66  * Setting distance explicitly is preferred, but this will
67  * allow qscale to be used as a fallback.
68  *
69  * This function is continuous and injective on [0, 100] which
70  * makes it monotonic.
71  *
72  * @param quality 0.0 to 100.0 quality setting, libjpeg quality
73  * @return Butteraugli distance between 0.0 and 15.0
74  */
75 static float quality_to_distance(float quality)
76 {
77  if (quality >= 100.0)
78  return 0.0;
79  else if (quality >= 90.0)
80  return (100.0 - quality) * 0.10;
81  else if (quality >= 30.0)
82  return 0.1 + (100.0 - quality) * 0.09;
83  else if (quality > 0.0)
84  return 15.0 + (59.0 * quality - 4350.0) * quality / 9000.0;
85  else
86  return 15.0;
87 }
88 
89 /**
90  * Initalize the encoder on a per-frame basis. All of these need to be set
91  * once each time the encoder is reset, which it must be each frame to make
92  * the image2 muxer work.
93  *
94  * @return 0 upon success, negative on failure.
95  */
97 {
99 
100  /* reset the encoder every frame for image2 muxer */
101  JxlEncoderReset(ctx->encoder);
102 
103  ctx->options = JxlEncoderFrameSettingsCreate(ctx->encoder, NULL);
104  if (!ctx->options) {
105  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoderOptions\n");
106  return AVERROR_EXTERNAL;
107  }
108 
109  /* This needs to be set each time the encoder is reset */
110  if (JxlEncoderSetParallelRunner(ctx->encoder, JxlThreadParallelRunner, ctx->runner)
111  != JXL_ENC_SUCCESS) {
112  av_log(avctx, AV_LOG_ERROR, "Failed to set JxlThreadParallelRunner\n");
113  return AVERROR_EXTERNAL;
114  }
115 
116  /* these shouldn't fail, libjxl bug notwithstanding */
117  if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_EFFORT, ctx->effort)
118  != JXL_ENC_SUCCESS) {
119  av_log(avctx, AV_LOG_ERROR, "Failed to set effort to: %d\n", ctx->effort);
120  return AVERROR_EXTERNAL;
121  }
122 
123  /* check for negative, our default */
124  if (ctx->distance < 0.0) {
125  /* use ffmpeg.c -q option if passed */
126  if (avctx->flags & AV_CODEC_FLAG_QSCALE)
127  ctx->distance = quality_to_distance((float)avctx->global_quality / FF_QP2LAMBDA);
128  else
129  /* default 1.0 matches cjxl */
130  ctx->distance = 1.0;
131  }
132 
133  /*
134  * 0.01 is the minimum distance accepted for lossy
135  * interpreting any positive value less than this as minimum
136  */
137  if (ctx->distance > 0.0 && ctx->distance < 0.01)
138  ctx->distance = 0.01;
139  if (JxlEncoderSetFrameDistance(ctx->options, ctx->distance) != JXL_ENC_SUCCESS) {
140  av_log(avctx, AV_LOG_ERROR, "Failed to set distance: %f\n", ctx->distance);
141  return AVERROR_EXTERNAL;
142  }
143 
144  /*
145  * In theory the library should automatically enable modular if necessary,
146  * but it appears it won't at the moment due to a bug. This will still
147  * work even if that is patched.
148  */
149  if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_MODULAR,
150  ctx->modular || ctx->distance <= 0.0 ? 1 : -1) != JXL_ENC_SUCCESS) {
151  av_log(avctx, AV_LOG_ERROR, "Failed to set modular\n");
152  return AVERROR_EXTERNAL;
153  }
154 
155  return 0;
156 }
157 
158 /**
159  * Global encoder initialization. This only needs to be run once,
160  * not every frame.
161  */
163 {
165  JxlMemoryManager manager;
166 
168  ctx->encoder = JxlEncoderCreate(&manager);
169  if (!ctx->encoder) {
170  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoder\n");
171  return AVERROR_EXTERNAL;
172  }
173 
174  ctx->runner = JxlThreadParallelRunnerCreate(&manager, ff_libjxl_get_threadcount(avctx->thread_count));
175  if (!ctx->runner) {
176  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlThreadParallelRunner\n");
177  return AVERROR_EXTERNAL;
178  }
179 
180  ctx->buffer_size = 4096;
181  ctx->buffer = av_realloc(NULL, ctx->buffer_size);
182 
183  if (!ctx->buffer) {
184  av_log(avctx, AV_LOG_ERROR, "Could not allocate encoding buffer\n");
185  return AVERROR(ENOMEM);
186  }
187 
188  return 0;
189 }
190 
191 /**
192  * Populate a JxlColorEncoding with the given enum AVColorPrimaries.
193  * @return < 0 upon failure, >= 0 upon success
194  */
195 static int libjxl_populate_primaries(void *avctx, JxlColorEncoding *jxl_color, enum AVColorPrimaries prm)
196 {
197  const AVColorPrimariesDesc *desc;
198 
199  switch (prm) {
200  case AVCOL_PRI_BT709:
201  jxl_color->primaries = JXL_PRIMARIES_SRGB;
202  jxl_color->white_point = JXL_WHITE_POINT_D65;
203  return 0;
204  case AVCOL_PRI_BT2020:
205  jxl_color->primaries = JXL_PRIMARIES_2100;
206  jxl_color->white_point = JXL_WHITE_POINT_D65;
207  return 0;
208  case AVCOL_PRI_SMPTE431:
209  jxl_color->primaries = JXL_PRIMARIES_P3;
210  jxl_color->white_point = JXL_WHITE_POINT_DCI;
211  return 0;
212  case AVCOL_PRI_SMPTE432:
213  jxl_color->primaries = JXL_PRIMARIES_P3;
214  jxl_color->white_point = JXL_WHITE_POINT_D65;
215  return 0;
217  av_log(avctx, AV_LOG_WARNING, "Unknown primaries, assuming BT.709/sRGB. Colors may be wrong.\n");
218  jxl_color->primaries = JXL_PRIMARIES_SRGB;
219  jxl_color->white_point = JXL_WHITE_POINT_D65;
220  return 0;
221  }
222 
224  if (!desc)
225  return AVERROR(EINVAL);
226 
227  jxl_color->primaries = JXL_PRIMARIES_CUSTOM;
228  jxl_color->white_point = JXL_WHITE_POINT_CUSTOM;
229 
230  jxl_color->primaries_red_xy[0] = av_q2d(desc->prim.r.x);
231  jxl_color->primaries_red_xy[1] = av_q2d(desc->prim.r.y);
232  jxl_color->primaries_green_xy[0] = av_q2d(desc->prim.g.x);
233  jxl_color->primaries_green_xy[1] = av_q2d(desc->prim.g.y);
234  jxl_color->primaries_blue_xy[0] = av_q2d(desc->prim.b.x);
235  jxl_color->primaries_blue_xy[1] = av_q2d(desc->prim.b.y);
236  jxl_color->white_point_xy[0] = av_q2d(desc->wp.x);
237  jxl_color->white_point_xy[1] = av_q2d(desc->wp.y);
238 
239  return 0;
240 }
241 
242 /**
243  * Encode an entire frame. Currently animation, is not supported by
244  * this encoder, so this will always reinitialize a new still image
245  * and encode a one-frame image (for image2 and image2pipe).
246  */
247 static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
248 {
250  AVFrameSideData *sd;
251  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(frame->format);
252  JxlBasicInfo info;
253  JxlColorEncoding jxl_color;
254  JxlPixelFormat jxl_fmt;
255  int bits_per_sample;
256 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
257  JxlBitDepth jxl_bit_depth;
258 #endif
259  JxlEncoderStatus jret;
260  int ret;
261  size_t available = ctx->buffer_size;
262  size_t bytes_written = 0;
263  uint8_t *next_out = ctx->buffer;
264  const uint8_t *data;
265 
266  ret = libjxl_init_jxl_encoder(avctx);
267  if (ret) {
268  av_log(avctx, AV_LOG_ERROR, "Error frame-initializing JxlEncoder\n");
269  return ret;
270  }
271 
272  /* populate the basic info settings */
273  JxlEncoderInitBasicInfo(&info);
274  jxl_fmt.num_channels = pix_desc->nb_components;
275  info.xsize = frame->width;
276  info.ysize = frame->height;
277  info.num_extra_channels = (jxl_fmt.num_channels + 1) % 2;
278  info.num_color_channels = jxl_fmt.num_channels - info.num_extra_channels;
279  bits_per_sample = av_get_bits_per_pixel(pix_desc) / jxl_fmt.num_channels;
280  info.bits_per_sample = avctx->bits_per_raw_sample > 0 && !(pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT)
281  ? avctx->bits_per_raw_sample : bits_per_sample;
282  info.alpha_bits = (info.num_extra_channels > 0) * info.bits_per_sample;
283  if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
284  info.exponent_bits_per_sample = info.bits_per_sample > 16 ? 8 : 5;
285  info.alpha_exponent_bits = info.alpha_bits ? info.exponent_bits_per_sample : 0;
286  jxl_fmt.data_type = info.bits_per_sample > 16 ? JXL_TYPE_FLOAT : JXL_TYPE_FLOAT16;
287  } else {
288  info.exponent_bits_per_sample = 0;
289  info.alpha_exponent_bits = 0;
290  jxl_fmt.data_type = info.bits_per_sample <= 8 ? JXL_TYPE_UINT8 : JXL_TYPE_UINT16;
291  }
292 
293 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
294  jxl_bit_depth.bits_per_sample = bits_per_sample;
295  jxl_bit_depth.type = JXL_BIT_DEPTH_FROM_PIXEL_FORMAT;
296  jxl_bit_depth.exponent_bits_per_sample = pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT ?
297  info.exponent_bits_per_sample : 0;
298 #endif
299 
300  /* JPEG XL format itself does not support limited range */
301  if (avctx->color_range == AVCOL_RANGE_MPEG ||
302  avctx->color_range == AVCOL_RANGE_UNSPECIFIED && frame->color_range == AVCOL_RANGE_MPEG)
303  av_log(avctx, AV_LOG_WARNING, "This encoder does not support limited (tv) range, colors will be wrong!\n");
304  else if (avctx->color_range != AVCOL_RANGE_JPEG && frame->color_range != AVCOL_RANGE_JPEG)
305  av_log(avctx, AV_LOG_WARNING, "Unknown color range, assuming full (pc)\n");
306 
307  /* bitexact lossless requires there to be no XYB transform */
308  info.uses_original_profile = ctx->distance == 0.0 || !ctx->xyb;
309  info.orientation = frame->linesize[0] >= 0 ? JXL_ORIENT_IDENTITY : JXL_ORIENT_FLIP_VERTICAL;
310 
311  if (JxlEncoderSetBasicInfo(ctx->encoder, &info) != JXL_ENC_SUCCESS) {
312  av_log(avctx, AV_LOG_ERROR, "Failed to set JxlBasicInfo\n");
313  return AVERROR_EXTERNAL;
314  }
315 
316  /* rendering intent doesn't matter here
317  * but libjxl will whine if we don't set it */
318  jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
319 
320  switch (frame->color_trc && frame->color_trc != AVCOL_TRC_UNSPECIFIED
321  ? frame->color_trc : avctx->color_trc) {
322  case AVCOL_TRC_BT709:
323  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_709;
324  break;
325  case AVCOL_TRC_LINEAR:
326  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
327  break;
329  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
330  break;
331  case AVCOL_TRC_SMPTE428:
332  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_DCI;
333  break;
334  case AVCOL_TRC_SMPTE2084:
335  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_PQ;
336  break;
338  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_HLG;
339  break;
340  case AVCOL_TRC_GAMMA22:
341  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
342  jxl_color.gamma = 1/2.2f;
343  break;
344  case AVCOL_TRC_GAMMA28:
345  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
346  jxl_color.gamma = 1/2.8f;
347  break;
348  default:
349  if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
350  av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming Linear Light. Colors may be wrong.\n");
351  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
352  } else {
353  av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming IEC61966-2-1/sRGB. Colors may be wrong.\n");
354  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
355  }
356  }
357 
358  /* This should be implied to be honest
359  * but a libjxl bug makes it fail otherwise */
360  if (info.num_color_channels == 1)
361  jxl_color.color_space = JXL_COLOR_SPACE_GRAY;
362  else
363  jxl_color.color_space = JXL_COLOR_SPACE_RGB;
364 
365  ret = libjxl_populate_primaries(avctx, &jxl_color,
366  frame->color_primaries && frame->color_primaries != AVCOL_PRI_UNSPECIFIED
367  ? frame->color_primaries : avctx->color_primaries);
368  if (ret < 0)
369  return ret;
370 
372  if (sd && sd->size && JxlEncoderSetICCProfile(ctx->encoder, sd->data, sd->size) != JXL_ENC_SUCCESS)
373  av_log(avctx, AV_LOG_WARNING, "Could not set ICC Profile\n");
374  if (JxlEncoderSetColorEncoding(ctx->encoder, &jxl_color) != JXL_ENC_SUCCESS)
375  av_log(avctx, AV_LOG_WARNING, "Failed to set JxlColorEncoding\n");
376 
377 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
378  if (JxlEncoderSetFrameBitDepth(ctx->options, &jxl_bit_depth) != JXL_ENC_SUCCESS)
379  av_log(avctx, AV_LOG_WARNING, "Failed to set JxlBitDepth\n");
380 #endif
381 
382  /* depending on basic info, level 10 might
383  * be required instead of level 5 */
384  if (JxlEncoderGetRequiredCodestreamLevel(ctx->encoder) > 5) {
385  if (JxlEncoderSetCodestreamLevel(ctx->encoder, 10) != JXL_ENC_SUCCESS)
386  av_log(avctx, AV_LOG_WARNING, "Could not increase codestream level\n");
387  }
388 
389  jxl_fmt.endianness = JXL_NATIVE_ENDIAN;
390  if (frame->linesize[0] >= 0) {
391  jxl_fmt.align = frame->linesize[0];
392  data = frame->data[0];
393  } else {
394  jxl_fmt.align = -frame->linesize[0];
395  data = frame->data[0] + frame->linesize[0] * (info.ysize - 1);
396  }
397 
398  if (JxlEncoderAddImageFrame(ctx->options, &jxl_fmt, data, jxl_fmt.align * info.ysize) != JXL_ENC_SUCCESS) {
399  av_log(avctx, AV_LOG_ERROR, "Failed to add Image Frame\n");
400  return AVERROR_EXTERNAL;
401  }
402 
403  /*
404  * Run this after the last frame in the image has been passed.
405  * TODO support animation
406  */
407  JxlEncoderCloseInput(ctx->encoder);
408 
409  while (1) {
410  jret = JxlEncoderProcessOutput(ctx->encoder, &next_out, &available);
411  if (jret == JXL_ENC_ERROR) {
412  av_log(avctx, AV_LOG_ERROR, "Unspecified libjxl error occurred\n");
413  return AVERROR_EXTERNAL;
414  }
415  bytes_written = ctx->buffer_size - available;
416  /* all data passed has been encoded */
417  if (jret == JXL_ENC_SUCCESS)
418  break;
419  if (jret == JXL_ENC_NEED_MORE_OUTPUT) {
420  /*
421  * at the moment, libjxl has no way to
422  * tell us how much space it actually needs
423  * so we need to malloc loop
424  */
425  uint8_t *temp;
426  size_t new_size = ctx->buffer_size * 2;
427  temp = av_realloc(ctx->buffer, new_size);
428  if (!temp)
429  return AVERROR(ENOMEM);
430  ctx->buffer = temp;
431  ctx->buffer_size = new_size;
432  next_out = ctx->buffer + bytes_written;
433  available = new_size - bytes_written;
434  continue;
435  }
436  av_log(avctx, AV_LOG_ERROR, "Bad libjxl event: %d\n", jret);
437  return AVERROR_EXTERNAL;
438  }
439 
440  ret = ff_get_encode_buffer(avctx, pkt, bytes_written, 0);
441  if (ret < 0)
442  return ret;
443 
444  memcpy(pkt->data, ctx->buffer, bytes_written);
445  *got_packet = 1;
446 
447  return 0;
448 }
449 
451 {
453 
454  if (ctx->runner)
455  JxlThreadParallelRunnerDestroy(ctx->runner);
456  ctx->runner = NULL;
457 
458  /*
459  * destroying the encoder also frees
460  * ctx->options so we don't need to
461  */
462  if (ctx->encoder)
463  JxlEncoderDestroy(ctx->encoder);
464  ctx->encoder = NULL;
465 
466  av_freep(&ctx->buffer);
467 
468  return 0;
469 }
470 
471 #define OFFSET(x) offsetof(LibJxlEncodeContext, x)
472 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
473 
474 static const AVOption libjxl_encode_options[] = {
475  { "effort", "Encoding effort", OFFSET(effort), AV_OPT_TYPE_INT, { .i64 = 7 }, 1, 9, VE },
476  { "distance", "Maximum Butteraugli distance (quality setting, "
477  "lower = better, zero = lossless, default 1.0)", OFFSET(distance), AV_OPT_TYPE_FLOAT, { .dbl = -1.0 }, -1.0, 15.0, VE },
478  { "modular", "Force modular mode", OFFSET(modular), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
479  { "xyb", "Use XYB-encoding for lossy images", OFFSET(xyb),
480  AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
481  { NULL },
482 };
483 
484 static const AVClass libjxl_encode_class = {
485  .class_name = "libjxl",
486  .item_name = av_default_item_name,
487  .option = libjxl_encode_options,
488  .version = LIBAVUTIL_VERSION_INT,
489 };
490 
492  .p.name = "libjxl",
493  CODEC_LONG_NAME("libjxl JPEG XL"),
494  .p.type = AVMEDIA_TYPE_VIDEO,
495  .p.id = AV_CODEC_ID_JPEGXL,
496  .priv_data_size = sizeof(LibJxlEncodeContext),
499  .close = libjxl_encode_close,
500  .p.capabilities = AV_CODEC_CAP_OTHER_THREADS |
503  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
506  .p.pix_fmts = (const enum AVPixelFormat[]) {
514  },
515  .p.priv_class = &libjxl_encode_class,
516  .p.wrapper_name = "libjxl",
517 };
LibJxlEncodeContext::effort
int effort
Definition: libjxlenc.c:53
LibJxlEncodeContext::options
JxlEncoderFrameSettings * options
Definition: libjxlenc.c:52
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
LibJxlEncodeContext::buffer_size
size_t buffer_size
Definition: libjxlenc.c:58
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:43
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:140
libm.h
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:963
VE
#define VE
Definition: libjxlenc.c:472
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:3170
LibJxlEncodeContext::runner
void * runner
Definition: libjxlenc.c:50
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:620
AV_CODEC_FLAG_QSCALE
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:224
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
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:684
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:717
AVPacket::data
uint8_t * data
Definition: packet.h:539
AVOption
AVOption.
Definition: opt.h:429
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:614
data
const char data[16]
Definition: mxf.c:149
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:35
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:3122
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:586
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
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:625
OFFSET
#define OFFSET(x)
Definition: libjxlenc.c:471
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1593
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:617
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:508
LibJxlEncodeContext::xyb
int xyb
Definition: libjxlenc.c:56
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:486
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
LibJxlEncodeContext::modular
int modular
Definition: libjxlenc.c:55
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:616
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:677
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
AVFrameSideData::size
size_t size
Definition: frame.h:268
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:1249
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
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:1585
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_RGBF32
#define AV_PIX_FMT_RGBF32
Definition: pixfmt.h:576
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:535
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:589
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:492
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:701
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:57
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:588
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 encoder on a per-frame basis.
Definition: libjxlenc.c:96
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:683
LibJxlEncodeContext
Definition: libjxlenc.c:48
error.h
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:597
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:628
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:600
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
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:247
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:488
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
ff_libjxl_encoder
const FFCodec ff_libjxl_encoder
Definition: libjxlenc.c:491
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:75
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:613
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
LibJxlEncodeContext::distance
float distance
Definition: libjxlenc.c:54
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:195
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:487
libjxl_encode_init
static av_cold int libjxl_encode_init(AVCodecContext *avctx)
Global encoder initialization.
Definition: libjxlenc.c:162
available
if no frame is available
Definition: filter_design.txt:166
AV_CODEC_ID_JPEGXL
@ AV_CODEC_ID_JPEGXL
Definition: codec_id.h:317
libjxl_encode_close
static av_cold int libjxl_encode_close(AVCodecContext *avctx)
Definition: libjxlenc.c:450
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:700
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:484
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:80
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:632
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:106
libjxl_encode_options
static const AVOption libjxl_encode_options[]
Definition: libjxlenc.c:474
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
temp
else temp
Definition: vf_mcdeint.c:263
AV_PIX_FMT_RGBAF32
#define AV_PIX_FMT_RGBAF32
Definition: pixfmt.h:577
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avutil.h
mem.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:265
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:601
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
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:231
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVCOL_TRC_SMPTE428
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
Definition: pixfmt.h:630
LibJxlEncodeContext::encoder
JxlEncoder * encoder
Definition: libjxlenc.c:51
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:155