FFmpeg
Data Structures | Macros | Functions | Variables
libjxlenc.c File Reference
#include <string.h>
#include "libavutil/avutil.h"
#include "libavutil/csp.h"
#include "libavutil/error.h"
#include "libavutil/frame.h"
#include "libavutil/libm.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
#include "libavutil/version.h"
#include "avcodec.h"
#include "encode.h"
#include "codec_internal.h"
#include <jxl/encode.h>
#include <jxl/thread_parallel_runner.h>
#include "libjxl.h"

Go to the source code of this file.

Data Structures

struct  LibJxlEncodeContext
 

Macros

#define OFFSET(x)   offsetof(LibJxlEncodeContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static float quality_to_distance (float quality)
 Map a quality setting for -qscale roughly from libjpeg quality numbers to libjxl's butteraugli distance for photographic content. More...
 
static int libjxl_init_jxl_encoder (AVCodecContext *avctx)
 Initalize the encoder on a per-frame basis. More...
 
static av_cold int libjxl_encode_init (AVCodecContext *avctx)
 Global encoder initialization. More...
 
static int libjxl_populate_primaries (void *avctx, JxlColorEncoding *jxl_color, enum AVColorPrimaries prm)
 Populate a JxlColorEncoding with the given enum AVColorPrimaries. More...
 
static int libjxl_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 Encode an entire frame. More...
 
static av_cold int libjxl_encode_close (AVCodecContext *avctx)
 

Variables

static const AVOption libjxl_encode_options []
 
static const AVClass libjxl_encode_class
 
const FFCodec ff_libjxl_encoder
 

Detailed Description

JPEG XL encoder using libjxl

Definition in file libjxlenc.c.

Macro Definition Documentation

◆ OFFSET

#define OFFSET (   x)    offsetof(LibJxlEncodeContext, x)

Definition at line 471 of file libjxlenc.c.

◆ VE

Definition at line 472 of file libjxlenc.c.

Function Documentation

◆ quality_to_distance()

static float quality_to_distance ( float  quality)
static

Map a quality setting for -qscale roughly from libjpeg quality numbers to libjxl's butteraugli distance for photographic content.

Setting distance explicitly is preferred, but this will allow qscale to be used as a fallback.

This function is continuous and injective on [0, 100] which makes it monotonic.

Parameters
quality0.0 to 100.0 quality setting, libjpeg quality
Returns
Butteraugli distance between 0.0 and 15.0

Definition at line 75 of file libjxlenc.c.

Referenced by libjxl_init_jxl_encoder().

◆ libjxl_init_jxl_encoder()

static int libjxl_init_jxl_encoder ( AVCodecContext avctx)
static

Initalize the encoder on a per-frame basis.

All of these need to be set once each time the encoder is reset, which it must be each frame to make the image2 muxer work.

Returns
0 upon success, negative on failure.

Definition at line 96 of file libjxlenc.c.

Referenced by libjxl_encode_frame().

◆ libjxl_encode_init()

static av_cold int libjxl_encode_init ( AVCodecContext avctx)
static

Global encoder initialization.

This only needs to be run once, not every frame.

Definition at line 162 of file libjxlenc.c.

◆ libjxl_populate_primaries()

static int libjxl_populate_primaries ( void *  avctx,
JxlColorEncoding *  jxl_color,
enum AVColorPrimaries  prm 
)
static

Populate a JxlColorEncoding with the given enum AVColorPrimaries.

Returns
< 0 upon failure, >= 0 upon success

Definition at line 195 of file libjxlenc.c.

Referenced by libjxl_encode_frame().

◆ libjxl_encode_frame()

static int libjxl_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame frame,
int *  got_packet 
)
static

Encode an entire frame.

Currently animation, is not supported by this encoder, so this will always reinitialize a new still image and encode a one-frame image (for image2 and image2pipe).

Definition at line 247 of file libjxlenc.c.

◆ libjxl_encode_close()

static av_cold int libjxl_encode_close ( AVCodecContext avctx)
static

Definition at line 450 of file libjxlenc.c.

Variable Documentation

◆ libjxl_encode_options

const AVOption libjxl_encode_options[]
static
Initial value:
= {
{ "effort", "Encoding effort", OFFSET(effort), AV_OPT_TYPE_INT, { .i64 = 7 }, 1, 9, VE },
{ "distance", "Maximum Butteraugli distance (quality setting, "
"lower = better, zero = lossless, default 1.0)", OFFSET(distance), AV_OPT_TYPE_FLOAT, { .dbl = -1.0 }, -1.0, 15.0, VE },
{ "modular", "Force modular mode", OFFSET(modular), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "xyb", "Use XYB-encoding for lossy images", OFFSET(xyb),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
{ NULL },
}

Definition at line 474 of file libjxlenc.c.

◆ libjxl_encode_class

const AVClass libjxl_encode_class
static
Initial value:
= {
.class_name = "libjxl",
.item_name = av_default_item_name,
}

Definition at line 484 of file libjxlenc.c.

◆ ff_libjxl_encoder

const FFCodec ff_libjxl_encoder
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:140
VE
#define VE
Definition: libjxlenc.c:472
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
OFFSET
#define OFFSET(x)
Definition: libjxlenc.c:471
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
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
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
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
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
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
LibJxlEncodeContext
Definition: libjxlenc.c:48
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_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
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
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
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
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
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
AV_PIX_FMT_RGBAF32
#define AV_PIX_FMT_RGBAF32
Definition: pixfmt.h:577
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:73
distance
static float distance(float x, float y, int band)
Definition: nellymoserenc.c:231