From 51572ff08abe44bc042a6004459bd1326d31bbce Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 23 Jul 2025 15:29:41 +0200 Subject: [PATCH] avcodec/libjxlenc: also attach extra channel info Works around a bug where older versions of libjxl don't correctly forward the alpha channel information to the extra channel info. --- libavcodec/libjxlenc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c index 9ad55ae3fa..da538518a5 100644 --- a/libavcodec/libjxlenc.c +++ b/libavcodec/libjxlenc.c @@ -445,6 +445,19 @@ static int libjxl_preprocess_stream(AVCodecContext *avctx, const AVFrame *frame, goto end; } + if (info.alpha_bits) { + JxlExtraChannelInfo extra_info; + JxlEncoderInitExtraChannelInfo(JXL_CHANNEL_ALPHA, &extra_info); + extra_info.bits_per_sample = info.alpha_bits; + extra_info.exponent_bits_per_sample = info.alpha_exponent_bits; + extra_info.alpha_premultiplied = info.alpha_premultiplied; + + if (JxlEncoderSetExtraChannelInfo(ctx->encoder, 0, &extra_info) != JXL_ENC_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to set JxlExtraChannelInfo for alpha!\n"); + return AVERROR_EXTERNAL; + } + } + sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE); if (sd && sd->size && JxlEncoderSetICCProfile(ctx->encoder, sd->data, sd->size) != JXL_ENC_SUCCESS) { av_log(avctx, AV_LOG_WARNING, "Could not set ICC Profile\n");