From patchwork Fri Jul 15 17:27:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 36804 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:43a1:b0:8b:53c6:bec9 with SMTP id i33csp435050pzl; Fri, 15 Jul 2022 10:27:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1shKtKK2pS/0Dy0cLKE6LeKvaC7SjtjG7/WMNoNP3gHsb/aS1p4A7fJBw6zxs7jylijpgs4 X-Received: by 2002:a05:6402:1bda:b0:43a:55d7:9f2f with SMTP id ch26-20020a0564021bda00b0043a55d79f2fmr19937368edb.360.1657906046336; Fri, 15 Jul 2022 10:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657906046; cv=none; d=google.com; s=arc-20160816; b=EpoXjTthzD4v3ZPoWeiMamx7HWb6lGMl3H1G55FG1e2YdRuPF6YojKqtMyGM3/tw5V 1AajMKJ2LFycXvioJPNT7yg9q86CuKfSzq7CHVTkEcvZGEPXFbhw1i222VrvcsTVw0Ep NF+0wEHnziWpaOkYVsnXUuvSetMaCtRXL3wnjqlfglGjjcp3WhadyZ332cSbXkR60ZOv RUohr/5JF8M91O8rSxhpnZvN+Fq1siizKUjnqF+iVGbYUgSkMoik5K8ji87aDnL3zDDJ mALfUxoBOSuN2NEoFpg6KzRTsQeQ5jyRQ7Gucqa6bp+3sK5deE/oOBnyG4htCw0x9Hm8 iS+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=+VN/N35ATUiTa+6p1SrzrJ04sjx7yu34lNomRauqEFs=; b=pRPfppvSuv8z0UYNTG3IHEO5ETMZEA57VYJGsvIs2hT5Fp+CCDBvxSHnfk/NGV82vy CtRAn+9JBPWND/KLEa3rtgm4XBZI+6mySPNFRi8wDtNXZfVe7SYM29zbo5GI+KSLUTBU uxvJJ7lkI7DOnfUjsSpXAGT1NAVRkCtQNZ87ihMtb9/N40+CVhni/byoIa4RveS0o9bM i5F6gYH8LPpLa8fMmNAq4D4hFdBbobqUqdtYiZr7yV2eeZK26Zq6r6pyWybXTSAZirzF /EihqZst/a0o3JZt6McO3Ke0NkJwQSSgw65U5NpGJOTTLdhs9CCirChB9bEVijiYTiw3 L0ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=EgzFUnCP; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a1-20020a50c301000000b0043a6af70491si6269643edb.492.2022.07.15.10.27.24; Fri, 15 Jul 2022 10:27:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=EgzFUnCP; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A22868B992; Fri, 15 Jul 2022 20:27:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 53B1B68B965 for ; Fri, 15 Jul 2022 20:27:15 +0300 (EEST) Received: by mail-qk1-f172.google.com with SMTP id o1so4061716qkg.9 for ; Fri, 15 Jul 2022 10:27:15 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dwe9o1BeokpFlWb/jO+VPAXKxeZOdMOwUEghbajr2Uc=; b=EgzFUnCPDfSJiEQXlS8Mdi3B6oTOMf/p81xOOxI7UlOxsi0mQa2Eii/fOaw6viFc57 70w4NX/Sp19yx9068mwxutqUv0jcslJrNLIHghBUqbasyEU231mqUa8mTbtbV+iu2dD2 hoP1LwKp6sADTjYGUZ40h0tuLcxE6DU+QhZu7IZbUJXMIetV0qu2OydNfrw62o9AQNXj cImC1HX4QyPh/sY+dkfr0JzSxXGO/f1x6pp4OxDajgilcoYGWOudn81wD4aD52j9qbfW CR8otBldYOjJUr1+ln/5xBRA1cZ+FH17TNCaG9sBtM4cx7+fi3Fl2Xkco2/VhqHzk3FH adAg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dwe9o1BeokpFlWb/jO+VPAXKxeZOdMOwUEghbajr2Uc=; b=b5V/lSzuYchxsh+3IbS7IIwpFbwBBykzyjzuWYS3CM+Rj2PxkchLiHrwJOKFEHj6S1 KFs+ZT5Dz0qWIAQ81sx9rcVQxzQUnFYhxFKtsqNB/BNFmomx2w0tC2oX66+Do4CbFBjU iRbhd4xZ20Fx6HN8ycT8CnspcbbXmzKIiXg2TD0dY1sCcvkuAvbLxdjWUbAF1kswtoZq hMhHyUOeHPge6YjD2VsvQ5My+b+A4OBmJ81rAuqHeKmnynEyanGYM3CjQz+M9kTq1Wd4 4eTJXwY26+YsrBy1p0I44CwRF+inrp5GGO7USQhFq8YSe9OCsKuZZxASRgnME5qVVXcy ZreQ== X-Gm-Message-State: AJIora97ZaMIvTHo7OEGou+nbsfoL4nt+QkHl2q3HVih4YWQpADfWlYe 0lVurWFwz/fWyeRO93m0ulgGlUMSg6Q= X-Received: by 2002:a05:620a:471e:b0:6b5:a60e:7155 with SMTP id bs30-20020a05620a471e00b006b5a60e7155mr10341818qkb.748.1657906033854; Fri, 15 Jul 2022 10:27:13 -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 n64-20020a37bd43000000b006b58facde91sm4203651qkf.106.2022.07.15.10.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 10:27:13 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Fri, 15 Jul 2022 13:27:10 -0400 Message-Id: <20220715172710.25865-1-leo.izen@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220715172537.25483-1-leo.izen@gmail.com> References: <20220715172537.25483-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avcodec/libjxlenc: avoid hard failure with unspecified primaries 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: gQ/z/OUDD6ZR This patch prevents the libjxl encoder wrapper from failing to encode images when the input video has untagged primaries. It will instead assume BT.709/sRGB primaries and print a warning. Signed-off-by: Leo Izen --- libavcodec/libjxlenc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c index 6a948cc3ae..9d98a112e1 100644 --- a/libavcodec/libjxlenc.c +++ b/libavcodec/libjxlenc.c @@ -190,7 +190,7 @@ static av_cold int libjxl_encode_init(AVCodecContext *avctx) * Populate a JxlColorEncoding with the given enum AVColorPrimaries. * @return < 0 upon failure, >= 0 upon success */ -static int libjxl_populate_primaries(JxlColorEncoding *jxl_color, enum AVColorPrimaries prm) +static int libjxl_populate_primaries(void *avctx, JxlColorEncoding *jxl_color, enum AVColorPrimaries prm) { const AVColorPrimariesDesc *desc; @@ -211,6 +211,11 @@ static int libjxl_populate_primaries(JxlColorEncoding *jxl_color, enum AVColorPr jxl_color->primaries = JXL_PRIMARIES_P3; jxl_color->white_point = JXL_WHITE_POINT_D65; return 0; + case AVCOL_PRI_UNSPECIFIED: + av_log(avctx, AV_LOG_WARNING, "Unknown primaries, assuming BT.709/sRGB. Colors may be wrong.\n"); + jxl_color->primaries = JXL_PRIMARIES_SRGB; + jxl_color->white_point = JXL_WHITE_POINT_D65; + return 0; } desc = av_csp_primaries_desc_from_id(prm); @@ -340,7 +345,7 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra else jxl_color.color_space = JXL_COLOR_SPACE_RGB; - ret = libjxl_populate_primaries(&jxl_color, + ret = libjxl_populate_primaries(avctx, &jxl_color, frame->color_primaries && frame->color_primaries != AVCOL_PRI_UNSPECIFIED ? frame->color_primaries : avctx->color_primaries); if (ret < 0)