From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8339C43295 for ; Sun, 26 Jun 2022 06:47:39 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DCC9168B760; Sun, 26 Jun 2022 09:47:36 +0300 (EEST) Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2425B68B526 for ; Sun, 26 Jun 2022 09:47:30 +0300 (EEST) Received: by mail-qv1-f49.google.com with SMTP id 88so10630542qva.9 for ; Sat, 25 Jun 2022 23:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NM6Gr2A+Q3gLFZjPYTxxlQOZUuqc3PRc09+OhhDhxkg=; b=n+YYYu8oFlbRRGlxczP31J2XTzOXPAwoE+S6GjMl2faLbUYDQQqFLhjF/LU89mTcSr Ti8axzP6jNGo+vzySbLN4y6wZPmxwTyeibt5EdkX9qmjNUiz1WEffKBanUlUmua6VLxF MYSkwo01cXDDw4tWmQ+6MxznfKLR6H/K6o6VHDFMv1Y5JF1vrNZRx9TQk8b9aJAQrlXL fiZqVWax0nU7FgIR3g3DfPi/zmLUry2ws960Wxkx2C9DseMVCsCv7tffBdtEmTrO4xhV P+YkwrGDY+qkxS6ecKih1IWX9+nHiI4RITnBYGJ4otLyCFn85tP1S51EsEqaDU21tUYN ANTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NM6Gr2A+Q3gLFZjPYTxxlQOZUuqc3PRc09+OhhDhxkg=; b=mnblg0IEMvzz70K37XuwEVOanXy/nR2CiNFVlrJn2wmJc5wx1vEHoMvly94WCZ4Z6k nRIKJ/kiSXIhxZwMhz7bIsGi/qiHyy7v9JH/NtCrl5mK2w98XFbTYYeQoxq09J3AZ4bF ikjo+Dlrej2W/spVvi2KBv4UPtwLlao1CBUdsqAYq7oxPDli+zUnsF20pnnl3J4HeZv/ GLNrDLYjEfzUFNMZy+OS6eW3palHPKAOgHpNx0F96uaW47gx2pQZR0aqAxrkk3OTgIYy RxL1FMtpaosjnj9T43AZIVvDB2/6hFXXRci61rPtf9cbZHjcv4xuJYHAwLRwJBMadJDr JTBw== X-Gm-Message-State: AJIora/AK2c/C1MIcdYAIwpAIP0q/NrApAiBcLUFrtjH9bJKtD5l04i/ +rxSDan34lQ5kLczk+m/B14rw5X1TAE= X-Google-Smtp-Source: AGRyM1sbRFCGBhi8YoRfutYiQJxTjBeG4S9R4jj6LMnoGYIgfxROHfyFDMCR256cAYMDyLmQJQqWWg== X-Received: by 2002:ac8:7c52:0:b0:305:a14:6f77 with SMTP id o18-20020ac87c52000000b003050a146f77mr5059690qtv.441.1656226048548; Sat, 25 Jun 2022 23:47:28 -0700 (PDT) Received: from gauss.local (c-68-41-54-207.hsd1.mi.comcast.net. [68.41.54.207]) by smtp.gmail.com with ESMTPSA id bw20-20020a05622a099400b00304bc2acc25sm4653658qtb.6.2022.06.25.23.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jun 2022 23:47:26 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Jun 2022 02:47:23 -0400 Message-Id: <20220626064723.20730-1-leo.izen@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/libjxlenc: avoid failure when level 10 is required X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Leo Izen Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: If a level 10 codestream is required, JxlEncoderSetBasicInfo will fail as it verifies the codestream level restrictions. However, there's no way for the library to provide the info on what codestream level is actually required until the BasicInfo struct is already set. Thus, we work around this problem by setting the codestream level to 10 in order to prevent JxlEncoderSetBasicInfo from failing, and then we later query the required codestream level. Signed-off-by: Leo Izen --- libavcodec/libjxlenc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c index 6a948cc3ae..b427d5d1a7 100644 --- a/libavcodec/libjxlenc.c +++ b/libavcodec/libjxlenc.c @@ -257,11 +257,25 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra return ret; } + /* + * We set all codestreams to level 10 here first, because + * JxlEncoderSetBasicInfo fails if level10 is required, but there is no + * way to determine if level10 is required until after the basic info is + * already set (a catch-22). To work around this problem, we set the level + * to level10 immediately, populate the basic info, and then query the + * level that is actually required. + * + * Return value is not checked because on a fresh encoder instance this + * cannot fail. + */ + JxlEncoderSetCodestreamLevel(ctx->encoder, 10); + /* populate the basic info settings */ JxlEncoderInitBasicInfo(&info); jxl_fmt.num_channels = pix_desc->nb_components; info.xsize = frame->width; info.ysize = frame->height; + /* num_extra_channels includes the alpha channel */ info.num_extra_channels = (jxl_fmt.num_channels + 1) % 2; info.num_color_channels = jxl_fmt.num_channels - info.num_extra_channels; info.bits_per_sample = av_get_bits_per_pixel(pix_desc) / jxl_fmt.num_channels; -- 2.36.1 _______________________________________________ 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".