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/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 decoder 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 443 of file libjxlenc.c.

◆ VE

Definition at line 444 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 73 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 decoder on a per-frame basis.

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

Returns
0 upon success, negative on failure.

Definition at line 94 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 160 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 193 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 245 of file libjxlenc.c.

◆ libjxl_encode_close()

static av_cold int libjxl_encode_close ( AVCodecContext avctx)
static

Definition at line 422 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 },
{ NULL },
}

Definition at line 446 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 454 of file libjxlenc.c.

◆ ff_libjxl_encoder

const FFCodec ff_libjxl_encoder
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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:41
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:133
VE
#define VE
Definition: libjxlenc.c:444
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:33
init
static int init
Definition: av_tx.c:47
OFFSET
#define OFFSET(x)
Definition: libjxlenc.c:443
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:395
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:269
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:127
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:443
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:401
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:74
LibJxlEncodeContext
Definition: libjxlenc.c:47
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
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:397
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:396
libjxl_encode_init
static av_cold int libjxl_encode_init(AVCodecContext *avctx)
Global encoder initialization.
Definition: libjxlenc.c:160
AV_CODEC_ID_JPEGXL
@ AV_CODEC_ID_JPEGXL
Definition: codec_id.h:312
libjxl_encode_close
static av_cold int libjxl_encode_close(AVCodecContext *avctx)
Definition: libjxlenc.c:422
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:454
libjxl_encode_options
static const AVOption libjxl_encode_options[]
Definition: libjxlenc.c:446
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
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:72
distance
static float distance(float x, float y, int band)
Definition: nellymoserenc.c:228