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;
59  JxlPixelFormat jxl_fmt;
60 
61  /* animation stuff */
66 
67 /**
68  * Map a quality setting for -qscale roughly from libjpeg
69  * quality numbers to libjxl's butteraugli distance for
70  * photographic content.
71  *
72  * Setting distance explicitly is preferred, but this will
73  * allow qscale to be used as a fallback.
74  *
75  * This function is continuous and injective on [0, 100] which
76  * makes it monotonic.
77  *
78  * @param quality 0.0 to 100.0 quality setting, libjpeg quality
79  * @return Butteraugli distance between 0.0 and 15.0
80  */
81 static float quality_to_distance(float quality)
82 {
83  if (quality >= 100.0)
84  return 0.0;
85  else if (quality >= 90.0)
86  return (100.0 - quality) * 0.10;
87  else if (quality >= 30.0)
88  return 0.1 + (100.0 - quality) * 0.09;
89  else if (quality > 0.0)
90  return 15.0 + (59.0 * quality - 4350.0) * quality / 9000.0;
91  else
92  return 15.0;
93 }
94 
95 /**
96  * Initalize the encoder on a per-file basis. All of these need to be set
97  * once each time the encoder is reset, which is each frame for still
98  * images, to make the image2 muxer work. For animation this is run once.
99  *
100  * @return 0 upon success, negative on failure.
101  */
103 {
105 
106  /* reset the encoder every frame for image2 muxer */
107  JxlEncoderReset(ctx->encoder);
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  ctx->options = JxlEncoderFrameSettingsCreate(ctx->encoder, NULL);
117  if (!ctx->options) {
118  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoderOptions\n");
119  return AVERROR_EXTERNAL;
120  }
121 
122  return 0;
123 }
124 
125 /**
126  * Global encoder initialization. This only needs to be run once,
127  * not every frame.
128  */
130 {
132  JxlMemoryManager manager;
133 
135  ctx->encoder = JxlEncoderCreate(&manager);
136  if (!ctx->encoder) {
137  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoder\n");
138  return AVERROR_EXTERNAL;
139  }
140 
141  ctx->runner = JxlThreadParallelRunnerCreate(&manager, ff_libjxl_get_threadcount(avctx->thread_count));
142  if (!ctx->runner) {
143  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlThreadParallelRunner\n");
144  return AVERROR_EXTERNAL;
145  }
146 
147  ctx->buffer_size = 4096;
148  ctx->buffer = av_realloc(NULL, ctx->buffer_size);
149 
150  if (!ctx->buffer) {
151  av_log(avctx, AV_LOG_ERROR, "Could not allocate encoding buffer\n");
152  return AVERROR(ENOMEM);
153  }
154 
155  /* check for negative, our default */
156  if (ctx->distance < 0.0) {
157  /* use ffmpeg.c -q option if passed */
158  if (avctx->flags & AV_CODEC_FLAG_QSCALE)
159  ctx->distance = quality_to_distance((float)avctx->global_quality / FF_QP2LAMBDA);
160  else
161  /* default 1.0 matches cjxl */
162  ctx->distance = 1.0;
163  }
164  /*
165  * 0.01 is the minimum distance accepted for lossy
166  * interpreting any positive value less than this as minimum
167  */
168  if (ctx->distance > 0.0 && ctx->distance < 0.01)
169  ctx->distance = 0.01;
170 
171  return 0;
172 }
173 
174 /**
175  * Initializer for the animation encoder. This calls the other initializers
176  * to prevent code duplication and also allocates the prev-frame used in the
177  * encoder.
178  */
180 {
181  int ret;
183 
184  ret = libjxl_encode_init(avctx);
185  if (ret < 0)
186  return ret;
187 
188  ret = libjxl_init_jxl_encoder(avctx);
189  if (ret < 0)
190  return ret;
191 
192  ctx->frame = av_frame_alloc();
193  if (!ctx->frame)
194  return AVERROR(ENOMEM);
195 
196  return 0;
197 }
198 
199 /**
200  * Populate a JxlColorEncoding with the given enum AVColorPrimaries.
201  * @return < 0 upon failure, >= 0 upon success
202  */
203 static int libjxl_populate_primaries(void *avctx, JxlColorEncoding *jxl_color, enum AVColorPrimaries prm)
204 {
205  const AVColorPrimariesDesc *desc;
206 
207  switch (prm) {
208  case AVCOL_PRI_BT709:
209  jxl_color->primaries = JXL_PRIMARIES_SRGB;
210  jxl_color->white_point = JXL_WHITE_POINT_D65;
211  return 0;
212  case AVCOL_PRI_BT2020:
213  jxl_color->primaries = JXL_PRIMARIES_2100;
214  jxl_color->white_point = JXL_WHITE_POINT_D65;
215  return 0;
216  case AVCOL_PRI_SMPTE431:
217  jxl_color->primaries = JXL_PRIMARIES_P3;
218  jxl_color->white_point = JXL_WHITE_POINT_DCI;
219  return 0;
220  case AVCOL_PRI_SMPTE432:
221  jxl_color->primaries = JXL_PRIMARIES_P3;
222  jxl_color->white_point = JXL_WHITE_POINT_D65;
223  return 0;
225  av_log(avctx, AV_LOG_WARNING, "Unknown primaries, assuming BT.709/sRGB. Colors may be wrong.\n");
226  jxl_color->primaries = JXL_PRIMARIES_SRGB;
227  jxl_color->white_point = JXL_WHITE_POINT_D65;
228  return 0;
229  }
230 
232  if (!desc)
233  return AVERROR(EINVAL);
234 
235  jxl_color->primaries = JXL_PRIMARIES_CUSTOM;
236  jxl_color->white_point = JXL_WHITE_POINT_CUSTOM;
237 
238  jxl_color->primaries_red_xy[0] = av_q2d(desc->prim.r.x);
239  jxl_color->primaries_red_xy[1] = av_q2d(desc->prim.r.y);
240  jxl_color->primaries_green_xy[0] = av_q2d(desc->prim.g.x);
241  jxl_color->primaries_green_xy[1] = av_q2d(desc->prim.g.y);
242  jxl_color->primaries_blue_xy[0] = av_q2d(desc->prim.b.x);
243  jxl_color->primaries_blue_xy[1] = av_q2d(desc->prim.b.y);
244  jxl_color->white_point_xy[0] = av_q2d(desc->wp.x);
245  jxl_color->white_point_xy[1] = av_q2d(desc->wp.y);
246 
247  return 0;
248 }
249 
250 /**
251  * Sends metadata to libjxl based on the first frame of the stream, such as pixel format,
252  * orientation, bit depth, and that sort of thing.
253  */
254 static int libjxl_preprocess_stream(AVCodecContext *avctx, const AVFrame *frame, int animated)
255 {
257  int ret;
258  AVFrameSideData *sd;
259  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(frame->format);
260  JxlBasicInfo info;
261  JxlColorEncoding jxl_color;
262  JxlPixelFormat *jxl_fmt = &ctx->jxl_fmt;
263  int bits_per_sample;
264 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
265  JxlBitDepth jxl_bit_depth;
266 #endif
267 
268  /* populate the basic info settings */
269  JxlEncoderInitBasicInfo(&info);
270  jxl_fmt->num_channels = pix_desc->nb_components;
271  info.xsize = frame->width;
272  info.ysize = frame->height;
273  info.num_extra_channels = (jxl_fmt->num_channels + 1) & 0x1;
274  info.num_color_channels = jxl_fmt->num_channels - info.num_extra_channels;
275  bits_per_sample = av_get_bits_per_pixel(pix_desc) / jxl_fmt->num_channels;
276  info.bits_per_sample = avctx->bits_per_raw_sample > 0 && !(pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT)
277  ? avctx->bits_per_raw_sample : bits_per_sample;
278  info.alpha_bits = (info.num_extra_channels > 0) * info.bits_per_sample;
279  if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
280  info.exponent_bits_per_sample = info.bits_per_sample > 16 ? 8 : 5;
281  info.alpha_exponent_bits = info.alpha_bits ? info.exponent_bits_per_sample : 0;
282  jxl_fmt->data_type = info.bits_per_sample > 16 ? JXL_TYPE_FLOAT : JXL_TYPE_FLOAT16;
283  } else {
284  info.exponent_bits_per_sample = 0;
285  info.alpha_exponent_bits = 0;
286  jxl_fmt->data_type = info.bits_per_sample <= 8 ? JXL_TYPE_UINT8 : JXL_TYPE_UINT16;
287  }
288 
289 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
290  jxl_bit_depth.bits_per_sample = bits_per_sample;
291  jxl_bit_depth.type = JXL_BIT_DEPTH_FROM_PIXEL_FORMAT;
292  jxl_bit_depth.exponent_bits_per_sample = pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT ?
293  info.exponent_bits_per_sample : 0;
294 #endif
295 
296  /* JPEG XL format itself does not support limited range */
297  if (avctx->color_range == AVCOL_RANGE_MPEG ||
298  avctx->color_range == AVCOL_RANGE_UNSPECIFIED && frame->color_range == AVCOL_RANGE_MPEG)
299  av_log(avctx, AV_LOG_WARNING, "This encoder does not support limited (tv) range, colors will be wrong!\n");
300  else if (avctx->color_range != AVCOL_RANGE_JPEG && frame->color_range != AVCOL_RANGE_JPEG)
301  av_log(avctx, AV_LOG_WARNING, "Unknown color range, assuming full (pc)\n");
302 
303  /* bitexact lossless requires there to be no XYB transform */
304  info.uses_original_profile = ctx->distance == 0.0 || !ctx->xyb;
305 
306  /* libjxl doesn't support negative linesizes so we use orientation to work around this */
307  info.orientation = frame->linesize[0] >= 0 ? JXL_ORIENT_IDENTITY : JXL_ORIENT_FLIP_VERTICAL;
308 
309  if (animated) {
310  info.have_animation = 1;
311  info.animation.have_timecodes = 0;
312  info.animation.num_loops = 0;
313  /* avctx->timebase is in seconds per tick, so we take the reciprocol */
314  info.animation.tps_numerator = avctx->time_base.den;
315  info.animation.tps_denominator = avctx->time_base.num;
316  }
317 
318  if (JxlEncoderSetBasicInfo(ctx->encoder, &info) != JXL_ENC_SUCCESS) {
319  av_log(avctx, AV_LOG_ERROR, "Failed to set JxlBasicInfo\n");
320  return AVERROR_EXTERNAL;
321  }
322 
323  /* rendering intent doesn't matter here
324  * but libjxl will whine if we don't set it */
325  jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
326 
327  switch (frame->color_trc && frame->color_trc != AVCOL_TRC_UNSPECIFIED
328  ? frame->color_trc : avctx->color_trc) {
329  case AVCOL_TRC_BT709:
330  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_709;
331  break;
332  case AVCOL_TRC_LINEAR:
333  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
334  break;
336  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
337  break;
338  case AVCOL_TRC_SMPTE428:
339  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_DCI;
340  break;
341  case AVCOL_TRC_SMPTE2084:
342  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_PQ;
343  break;
345  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_HLG;
346  break;
347  case AVCOL_TRC_GAMMA22:
348  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
349  jxl_color.gamma = 1/2.2f;
350  break;
351  case AVCOL_TRC_GAMMA28:
352  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
353  jxl_color.gamma = 1/2.8f;
354  break;
355  default:
356  if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
357  av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming Linear Light. Colors may be wrong.\n");
358  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
359  } else {
360  av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming IEC61966-2-1/sRGB. Colors may be wrong.\n");
361  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
362  }
363  }
364 
365  /* This should be implied to be honest
366  * but a libjxl bug makes it fail otherwise */
367  if (info.num_color_channels == 1)
368  jxl_color.color_space = JXL_COLOR_SPACE_GRAY;
369  else
370  jxl_color.color_space = JXL_COLOR_SPACE_RGB;
371 
372  ret = libjxl_populate_primaries(avctx, &jxl_color,
373  frame->color_primaries && frame->color_primaries != AVCOL_PRI_UNSPECIFIED
374  ? frame->color_primaries : avctx->color_primaries);
375  if (ret < 0)
376  return ret;
377 
379  if (sd && sd->size && JxlEncoderSetICCProfile(ctx->encoder, sd->data, sd->size) != JXL_ENC_SUCCESS)
380  av_log(avctx, AV_LOG_WARNING, "Could not set ICC Profile\n");
381  if (JxlEncoderSetColorEncoding(ctx->encoder, &jxl_color) != JXL_ENC_SUCCESS)
382  av_log(avctx, AV_LOG_WARNING, "Failed to set JxlColorEncoding\n");
383 
384 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
385  if (JxlEncoderSetFrameBitDepth(ctx->options, &jxl_bit_depth) != JXL_ENC_SUCCESS)
386  av_log(avctx, AV_LOG_WARNING, "Failed to set JxlBitDepth\n");
387 #endif
388 
389  /* depending on basic info, level 10 might
390  * be required instead of level 5 */
391  if (JxlEncoderGetRequiredCodestreamLevel(ctx->encoder) > 5) {
392  if (JxlEncoderSetCodestreamLevel(ctx->encoder, 10) != JXL_ENC_SUCCESS)
393  av_log(avctx, AV_LOG_WARNING, "Could not increase codestream level\n");
394  }
395 
396  return 0;
397 }
398 
399 /**
400  * Sends frame information to libjxl on a per-frame basis. If this is a still image,
401  * this is evaluated once per output file. If this is an animated JPEG XL encode, it
402  * is called once per frame.
403  *
404  * This returns a buffer to the data that should be passed to libjxl (via the
405  * argument **data). If the linesize is nonnegative, this will be frame->data[0],
406  * although if the linesize is negative, it will be the start of the buffer
407  * instead. *data is just a pointer to a location in frame->data so it should not be
408  * freed directly.
409  */
410 static int libjxl_preprocess_frame(AVCodecContext *avctx, const AVFrame *frame, const uint8_t **data)
411 {
413  JxlPixelFormat *jxl_fmt = &ctx->jxl_fmt;
414 
415  /* these shouldn't fail, libjxl bug notwithstanding */
416  if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_EFFORT, ctx->effort)
417  != JXL_ENC_SUCCESS) {
418  av_log(avctx, AV_LOG_ERROR, "Failed to set effort to: %d\n", ctx->effort);
419  return AVERROR_EXTERNAL;
420  }
421 
422  if (JxlEncoderSetFrameDistance(ctx->options, ctx->distance) != JXL_ENC_SUCCESS) {
423  av_log(avctx, AV_LOG_ERROR, "Failed to set distance: %f\n", ctx->distance);
424  return AVERROR_EXTERNAL;
425  }
426 
427  /*
428  * In theory the library should automatically enable modular if necessary,
429  * but it appears it won't at the moment due to a bug. This will still
430  * work even if that is patched.
431  */
432  if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_MODULAR,
433  ctx->modular || ctx->distance <= 0.0 ? 1 : -1) != JXL_ENC_SUCCESS) {
434  av_log(avctx, AV_LOG_ERROR, "Failed to set modular\n");
435  return AVERROR_EXTERNAL;
436  }
437 
438  jxl_fmt->endianness = JXL_NATIVE_ENDIAN;
439  if (frame->linesize[0] >= 0) {
440  jxl_fmt->align = frame->linesize[0];
441  *data = frame->data[0];
442  } else {
443  jxl_fmt->align = -frame->linesize[0];
444  *data = frame->data[0] + frame->linesize[0] * (frame->height - 1);
445  }
446 
447  return 0;
448 }
449 
450 /**
451  * Run libjxl's output processing loop, reallocating the packet as necessary
452  * if libjxl needs more space to work with.
453  */
454 static int libjxl_process_output(AVCodecContext *avctx, size_t *bytes_written)
455 {
457  JxlEncoderStatus jret;
458  size_t available = ctx->buffer_size;
459  uint8_t *next_out = ctx->buffer;
460 
461  while (1) {
462  jret = JxlEncoderProcessOutput(ctx->encoder, &next_out, &available);
463  if (jret == JXL_ENC_ERROR) {
464  av_log(avctx, AV_LOG_ERROR, "Unspecified libjxl error occurred\n");
465  return AVERROR_EXTERNAL;
466  }
467  *bytes_written = ctx->buffer_size - available;
468  /* all data passed has been encoded */
469  if (jret == JXL_ENC_SUCCESS)
470  break;
471  if (jret == JXL_ENC_NEED_MORE_OUTPUT) {
472  /*
473  * at the moment, libjxl has no way to
474  * tell us how much space it actually needs
475  * so we need to malloc loop
476  */
477  uint8_t *temp;
478  size_t new_size = ctx->buffer_size * 2;
479  temp = av_realloc(ctx->buffer, new_size);
480  if (!temp)
481  return AVERROR(ENOMEM);
482  ctx->buffer = temp;
483  ctx->buffer_size = new_size;
484  next_out = ctx->buffer + *bytes_written;
485  available = new_size - *bytes_written;
486  continue;
487  }
488  av_log(avctx, AV_LOG_ERROR, "Bad libjxl event: %d\n", jret);
489  return AVERROR_EXTERNAL;
490  }
491 
492  return 0;
493 }
494 
495 /**
496  * Encode an entire frame. This will always reinitialize a new still image
497  * and encode a one-frame image (for image2 and image2pipe).
498  */
499 static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
500 {
501 
503  int ret;
504  size_t bytes_written = 0;
505  const uint8_t *data;
506 
507  ret = libjxl_init_jxl_encoder(avctx);
508  if (ret < 0) {
509  av_log(avctx, AV_LOG_ERROR, "Error frame-initializing JxlEncoder\n");
510  return ret;
511  }
512 
513  ret = libjxl_preprocess_stream(avctx, frame, 0);
514  if (ret < 0)
515  return ret;
516 
518  if (ret < 0)
519  return ret;
520 
521  if (JxlEncoderAddImageFrame(ctx->options, &ctx->jxl_fmt, data, ctx->jxl_fmt.align * frame->height)
522  != JXL_ENC_SUCCESS) {
523  av_log(avctx, AV_LOG_ERROR, "Failed to add Image Frame\n");
524  return AVERROR_EXTERNAL;
525  }
526 
527  /*
528  * Run this after the last frame in the image has been passed.
529  */
530  JxlEncoderCloseInput(ctx->encoder);
531 
532  ret = libjxl_process_output(avctx, &bytes_written);
533  if (ret < 0)
534  return ret;
535 
536  ret = ff_get_encode_buffer(avctx, pkt, bytes_written, 0);
537  if (ret < 0)
538  return ret;
539 
540  memcpy(pkt->data, ctx->buffer, bytes_written);
541  *got_packet = 1;
542 
543  return 0;
544 }
545 
546 /**
547  * Encode one frame of the animation. libjxl requires us to set duration of the frame
548  * but we're only promised the PTS, not the duration. As a result we have to buffer
549  * a frame and subtract the PTS from the last PTS. The last frame uses the previous
550  * frame's calculated duration as a fallback if its duration field is unset.
551  *
552  * We also need to tell libjxl if our frame is the last one, which we won't know upon
553  * receiving a single frame, so we have to buffer a frame as well and send the "last frame"
554  * upon receiving the special EOF frame.
555  */
557 {
559  int ret = 0;
560  JxlFrameHeader frame_header;
561  size_t bytes_written = 0;
562  const uint8_t *data;
563 
564  if (!ctx->prev) {
565  ctx->prev = av_frame_alloc();
566  if (!ctx->prev)
567  return AVERROR(ENOMEM);
568  ret = ff_encode_get_frame(avctx, ctx->prev);
569  if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
570  return ret;
571  ret = libjxl_preprocess_stream(avctx, ctx->prev, 1);
572  if (ret < 0)
573  return ret;
574  }
575 
576  ret = ff_encode_get_frame(avctx, ctx->frame);
577  if (ret == AVERROR_EOF) {
578  av_frame_free(&ctx->frame);
579  ret = 0;
580  }
581  if (ret == AVERROR(EAGAIN))
582  return ret;
583 
584  JxlEncoderInitFrameHeader(&frame_header);
585 
586  ctx->duration = ctx->prev->duration ? ctx->prev->duration :
587  ctx->frame ? ctx->frame->pts - ctx->prev->pts :
588  ctx->duration ? ctx->duration :
589  1;
590 
591  frame_header.duration = ctx->duration;
592  pkt->duration = ctx->duration;
593  pkt->pts = ctx->prev->pts;
594  pkt->dts = pkt->pts;
595 
596  if (JxlEncoderSetFrameHeader(ctx->options, &frame_header) != JXL_ENC_SUCCESS) {
597  av_log(avctx, AV_LOG_ERROR, "Failed to set JxlFrameHeader\n");
598  return AVERROR_EXTERNAL;
599  }
600 
601  ret = libjxl_preprocess_frame(avctx, ctx->prev, &data);
602  if (ret < 0)
603  return ret;
604 
605  if (JxlEncoderAddImageFrame(ctx->options, &ctx->jxl_fmt, data, ctx->jxl_fmt.align * ctx->prev->height)
606  != JXL_ENC_SUCCESS) {
607  av_log(avctx, AV_LOG_ERROR, "Failed to add Image Frame\n");
608  return AVERROR_EXTERNAL;
609  }
610 
611  if (!ctx->frame)
612  JxlEncoderCloseInput(ctx->encoder);
613 
614  ret = libjxl_process_output(avctx, &bytes_written);
615  if (ret < 0)
616  return ret;
617 
618  ret = ff_get_encode_buffer(avctx, pkt, bytes_written, 0);
619  if (ret < 0)
620  return ret;
621 
622  memcpy(pkt->data, ctx->buffer, bytes_written);
623 
624  if (ctx->frame) {
625  av_frame_unref(ctx->prev);
626  av_frame_move_ref(ctx->prev, ctx->frame);
627  } else {
628  av_frame_free(&ctx->prev);
629  }
630 
631  return ret;
632 }
633 
635 {
637 
638  if (ctx->runner)
639  JxlThreadParallelRunnerDestroy(ctx->runner);
640  ctx->runner = NULL;
641 
642  /*
643  * destroying the encoder also frees
644  * ctx->options so we don't need to
645  */
646  if (ctx->encoder)
647  JxlEncoderDestroy(ctx->encoder);
648  ctx->encoder = NULL;
649 
650  av_freep(&ctx->buffer);
651  av_frame_free(&ctx->prev);
652  av_frame_free(&ctx->frame);
653 
654  return 0;
655 }
656 
657 #define OFFSET(x) offsetof(LibJxlEncodeContext, x)
658 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
659 
660 static const AVOption libjxl_encode_options[] = {
661  { "effort", "Encoding effort", OFFSET(effort), AV_OPT_TYPE_INT, { .i64 = 7 }, 1, 9, VE },
662  { "distance", "Maximum Butteraugli distance (quality setting, "
663  "lower = better, zero = lossless, default 1.0)", OFFSET(distance), AV_OPT_TYPE_FLOAT, { .dbl = -1.0 }, -1.0, 15.0, VE },
664  { "modular", "Force modular mode", OFFSET(modular), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
665  { "xyb", "Use XYB-encoding for lossy images", OFFSET(xyb),
666  AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
667  { NULL },
668 };
669 
670 static const AVClass libjxl_encode_class = {
671  .class_name = "libjxl",
672  .item_name = av_default_item_name,
673  .option = libjxl_encode_options,
674  .version = LIBAVUTIL_VERSION_INT,
675 };
676 
685 };
686 
688  .p.name = "libjxl",
689  CODEC_LONG_NAME("libjxl JPEG XL"),
690  .p.type = AVMEDIA_TYPE_VIDEO,
691  .p.id = AV_CODEC_ID_JPEGXL,
692  .priv_data_size = sizeof(LibJxlEncodeContext),
695  .close = libjxl_encode_close,
696  .p.capabilities = AV_CODEC_CAP_OTHER_THREADS |
699  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
702  .p.pix_fmts = libjxl_supported_pixfmts,
703  .p.priv_class = &libjxl_encode_class,
704  .p.wrapper_name = "libjxl",
705 };
706 
708  .p.name = "libjxl_anim",
709  CODEC_LONG_NAME("libjxl JPEG XL animated"),
710  .p.type = AVMEDIA_TYPE_VIDEO,
711  .p.id = AV_CODEC_ID_JPEGXL_ANIM,
712  .priv_data_size = sizeof(LibJxlEncodeContext),
715  .close = libjxl_encode_close,
716  .p.capabilities = AV_CODEC_CAP_OTHER_THREADS |
719  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
722  .p.pix_fmts = libjxl_supported_pixfmts,
723  .p.priv_class = &libjxl_encode_class,
724  .p.wrapper_name = "libjxl",
725 };
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
AV_CODEC_ID_JPEGXL_ANIM
@ AV_CODEC_ID_JPEGXL_ANIM
Definition: codec_id.h:331
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:42
libjxl_process_output
static int libjxl_process_output(AVCodecContext *avctx, size_t *bytes_written)
Run libjxl's output processing loop, reallocating the packet as necessary if libjxl needs more space ...
Definition: libjxlenc.c:454
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:983
VE
#define VE
Definition: libjxlenc.c:658
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:3248
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
LibJxlEncodeContext::runner
void * runner
Definition: libjxlenc.c:50
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:636
AV_CODEC_FLAG_QSCALE
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:224
int64_t
long long int64_t
Definition: coverity.c:34
AV_PIX_FMT_FLAG_FLOAT
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:158
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:692
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:733
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:630
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: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:3200
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:557
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:602
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
libjxl_anim_encode_init
static av_cold int libjxl_anim_encode_init(AVCodecContext *avctx)
Initializer for the animation encoder.
Definition: libjxlenc.c:179
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:641
libjxl_anim_encode_frame
static int libjxl_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt)
Encode one frame of the animation.
Definition: libjxlenc.c:556
OFFSET
#define OFFSET(x)
Definition: libjxlenc.c:657
LibJxlEncodeContext::prev
AVFrame * prev
Definition: libjxlenc.c:63
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1601
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:633
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:499
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
AVRational::num
int num
Numerator.
Definition: rational.h:59
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:632
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:151
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:685
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:1257
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:1593
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_RGBF32
#define AV_PIX_FMT_RGBF32
Definition: pixfmt.h:592
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:551
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:605
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:505
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:709
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
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:326
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:604
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:239
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-file basis.
Definition: libjxlenc.c:102
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:699
LibJxlEncodeContext
Definition: libjxlenc.c:48
error.h
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:613
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:558
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:644
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:616
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
libjxl_preprocess_stream
static int libjxl_preprocess_stream(AVCodecContext *avctx, const AVFrame *frame, int animated)
Sends metadata to libjxl based on the first frame of the stream, such as pixel format,...
Definition: libjxlenc.c:254
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:499
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:501
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
libjxl_preprocess_frame
static int libjxl_preprocess_frame(AVCodecContext *avctx, const AVFrame *frame, const uint8_t **data)
Sends frame information to libjxl on a per-frame basis.
Definition: libjxlenc.c:410
ff_libjxl_encoder
const FFCodec ff_libjxl_encoder
Definition: libjxlenc.c:687
frame.h
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:538
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:81
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:629
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:203
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:500
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
libjxl_encode_init
static av_cold int libjxl_encode_init(AVCodecContext *avctx)
Global encoder initialization.
Definition: libjxlenc.c:129
ff_libjxl_anim_encoder
const FFCodec ff_libjxl_anim_encoder
Definition: libjxlenc.c:707
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:634
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:650
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:623
LibJxlEncodeContext::jxl_fmt
JxlPixelFormat jxl_fmt
Definition: libjxlenc.c:59
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
libjxl_supported_pixfmts
static enum AVPixelFormat libjxl_supported_pixfmts[]
Definition: libjxlenc.c:677
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:716
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:81
libjxl_encode_class
static const AVClass libjxl_encode_class
Definition: libjxlenc.c:670
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:648
frame_header
Definition: truemotion1.c:88
frame_header
static int FUNC() frame_header(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawFrameHeader *current)
Definition: cbs_jpeg_syntax_template.c:19
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:660
AVRational::den
int den
Denominator.
Definition: rational.h:60
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:593
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1435
LibJxlEncodeContext::frame
AVFrame * frame
Definition: libjxlenc.c:62
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avutil.h
mem.h
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:205
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:72
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:617
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:646
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
LibJxlEncodeContext::duration
int64_t duration
Definition: libjxlenc.c:64
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:155