Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Leo Izen <leo.izen@gmail.com>
Subject: Re: [FFmpeg-devel] [PATCH v13 3/4] avcodec/libjxl: add Jpeg XL encoding via libjxl
Date: Sat, 09 Apr 2022 15:17:32 +0200
Message-ID: <164951025246.21047.6570158843618793411@lain.red.khirnov.net> (raw)
In-Reply-To: <20220405165504.29261-4-leo.izen@gmail.com>

Quoting Leo Izen (2022-04-05 18:55:03)
> +static int libjxl_init_jxl_encoder(AVCodecContext *avctx)
> +{
> +    LibJxlEncodeContext *ctx = avctx->priv_data;
> +
> +    /* reset the encoder every frame for image2 muxer */
> +    JxlEncoderReset(ctx->encoder);
> +
> +    ctx->options = JxlEncoderFrameSettingsCreate(ctx->encoder, NULL);
> +    if (!ctx->options) {
> +        av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoderOptions\n");
> +        return AVERROR_EXTERNAL;
> +    }
> +
> +    /* This needs to be set each time the decoder is reset */
> +    if (JxlEncoderSetParallelRunner(ctx->encoder, JxlThreadParallelRunner, ctx->runner)
> +            != JXL_ENC_SUCCESS) {
> +        av_log(avctx, AV_LOG_ERROR, "Failed to set JxlThreadParallelRunner\n");
> +        return AVERROR_EXTERNAL;
> +    }
> +
> +    /* these shouldn't fail, libjxl bug notwithstanding */
> +    if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_EFFORT, ctx->effort)
> +            != JXL_ENC_SUCCESS) {
> +        av_log(avctx, AV_LOG_ERROR, "Failed to set effort to: %d\n", ctx->effort);
> +        return AVERROR_EXTERNAL;
> +    }
> +
> +    /* check for negative zero, our default */
> +    if (1.0f / ctx->distance == 1.0f / -0.0f) {

IIRC division by zero is UB. Why not make the default -1.0 and then just
check whether the number is negative?

> +    /*
> +     * This buffer will be copied when the generic
> +     * code makes this packet refcounted,
> +     * so we can use the buffer again.
> +     */
> +    pkt->data = ctx->buffer;
> +    pkt->size = bytes_written;

This is very evil. Encoders should return refcounted packets and not
rely on the generic code fixing stuff up for them.

Also, pointers from av_malloc() cannot be passed to av_realloc(). You
need to allocate it with av_realloc() in the first place.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2022-04-09 13:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-05 16:55 [FFmpeg-devel] [PATCH v13 0/4] Jpeg XL Patch Set Leo Izen
2022-04-05 16:55 ` [FFmpeg-devel] [PATCH v13 1/4] avcodec/jpegxl: add Jpeg XL image codec Leo Izen
2022-04-05 16:55 ` [FFmpeg-devel] [PATCH v13 2/4] avcodec/libjxl: add Jpeg XL decoding via libjxl Leo Izen
2022-04-05 16:55 ` [FFmpeg-devel] [PATCH v13 3/4] avcodec/libjxl: add Jpeg XL encoding " Leo Izen
2022-04-09 13:17   ` Anton Khirnov [this message]
2022-04-09 15:37     ` James Almer
2022-04-09 15:44       ` Hendrik Leppkes
2022-04-11 12:54         ` Anton Khirnov
2022-04-11 11:16     ` Leo Izen
2022-04-11 12:52       ` Anton Khirnov
2022-04-05 16:55 ` [FFmpeg-devel] [PATCH v13 4/4] avformat/image2: add Jpeg XL as image2 format Leo Izen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=164951025246.21047.6570158843618793411@lain.red.khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=leo.izen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git