From patchwork Mon Mar 25 17:58:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 47452 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c889:b0:1a3:b6bb:3029 with SMTP id hb9csp1351184pzb; Mon, 25 Mar 2024 10:58:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVGRNB5PFjLE9I1hb+9CvOs6uWaJwoj/H0zBs6pmcCor6i6ed3e1Xi2m4VYu61AkjELpiXmYcRuegrAyHdVAM03+fxIQN1I7MmW8Q== X-Google-Smtp-Source: AGHT+IHVESKMBwjyGicU/no3ypC1X9CzRy7iHAb3TeKImph69QsHRCBEJTedj2Yo86/qSXESyaJq X-Received: by 2002:a19:770e:0:b0:515:9410:5807 with SMTP id s14-20020a19770e000000b0051594105807mr4117450lfc.6.1711389530443; Mon, 25 Mar 2024 10:58:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711389530; cv=none; d=google.com; s=arc-20160816; b=iOpUI27cpGKyRNqjJUVLzlgTVa5/baXCKM11hDh4lUlA8KMhyCV3fZpFTgZjc6ZYxd FItWbwQ9HDx1aFLsTOUQZGk+6tTxCeFlCBhVpnKGa9QEeCLw9iWnbH4MrYTfirFttFyw KUPu8EDYKzh8vM7InWe62qrYqpxHcS3s8IrXuRHQRPsyMD4MxbpE1gsZy0Kjswjhz+zE /QJl/vh11LdtVylaa35owgPa7+8rktlfDOt0X6vZecioLxDfE/XIZJVvl8fwAIG1ICjB DoBVnpj67yBU9z3aIL4pPzy2fKS4ThIA6XV9gwLiJKDXOK+yXiVDntjONmZwYrgJWoRG Z99g== 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:message-id:date:to:from :delivered-to; bh=ill5e2KsOIaW2qKkuRYCIuGEpUnfehM4cJ6dYF6cD/A=; fh=zgMS+X4RExv2k7fU8QdWClnqVJdqO/9UbUuBS5xxJDs=; b=PHXvkWPBV/PXb7zTQZWxuMHTGbRwCckp2Czl/RizOeqmYNYqUyP4OB8zFN2ZVLASCy yRQEfZn4autssAXNAxfmXtbZ30mK4Ac0Art0adMgI8WubpS0ncbt4J9Q5m9SXiJWPf9C 7djtUWt4pzCpp9p/AzaDborr90V+f8s2Af1MkKYZzNRvKoPBYKtUKM3wu8WZJuSOOkgE sp7L3uIDs6akxTAst7JxwbXXecMF5/QBjggXmhwdU+ftWhFE2FaVQpOO03CNEL6XGhPx iPTjqTbDgSuUp6Y9kMyQnLqDHjvawsbh8hY8COpawno2K4H2uNp3sD5x3bHLaI9ir6mA A4Eg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id do2-20020a170906c10200b00a47472025adsi2291512ejc.475.2024.03.25.10.58.49; Mon, 25 Mar 2024 10:58:50 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 49B7B68D461; Mon, 25 Mar 2024 19:58:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from srv-infra-1.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D4F868C4E3 for ; Mon, 25 Mar 2024 19:58:39 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 73C0A2062B; Mon, 25 Mar 2024 17:58:38 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 Mar 2024 18:58:36 +0100 Message-Id: <20240325175836.301657-1-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_colorspace: use colorspace negotiation API 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: Nicolas Gaullier Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: q3IaxHJsPLXE Fixes a regression due to the fact that the colorspace filter does not use the new API introduced by 8c7934f73ab6c568acaa. The scale filter uses it since 45e09a30419cc2a7251e, and the setparams filter since 3bf80df3ccd32aed23f0. Example: ffmpeg -f lavfi -i testsrc -vf setparams=color_primaries=bt470bg: color_trc=smpte170m:colorspace=bt470bg,colorspace=bt709:range=tv,scale ,showinfo -f null -frames 1 - Before: color_range:unknown color_space:unknown color_primaries:bt709 ... After: color_range:tv color_space:bt709 color_primaries:bt709 ... There is still an issue with the color_range when it is not specified: the documentation states the output defaults to the same value as the input, but it does not seem possible to implement currently. Signed-off-by: Nicolas Gaullier --- libavfilter/vf_colorspace.c | 62 +++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c index f367ce17c6..b1e1b9b719 100644 --- a/libavfilter/vf_colorspace.c +++ b/libavfilter/vf_colorspace.c @@ -432,8 +432,7 @@ static int create_filtergraph(AVFilterContext *ctx, if (out->color_trc != s->out_trc) s->out_txchr = NULL; if (in->colorspace != s->in_csp || in->color_range != s->in_rng) s->in_lumacoef = NULL; - if (out->colorspace != s->out_csp || - out->color_range != s->out_rng) s->out_lumacoef = NULL; + if (out->color_range != s->out_rng) s->rgb2yuv = NULL; if (!s->out_primaries || !s->in_primaries) { s->in_prm = in->color_primaries; @@ -562,26 +561,8 @@ static int create_filtergraph(AVFilterContext *ctx, redo_yuv2rgb = 1; } - if (!s->out_lumacoef) { - s->out_csp = out->colorspace; + if (!s->rgb2yuv) { s->out_rng = out->color_range; - s->out_lumacoef = av_csp_luma_coeffs_from_avcsp(s->out_csp); - if (!s->out_lumacoef) { - if (s->out_csp == AVCOL_SPC_UNSPECIFIED) { - if (s->user_all == CS_UNSPECIFIED) { - av_log(ctx, AV_LOG_ERROR, - "Please specify output colorspace\n"); - } else { - av_log(ctx, AV_LOG_ERROR, - "Unsupported output color property %d\n", s->user_all); - } - } else { - av_log(ctx, AV_LOG_ERROR, - "Unsupported output colorspace %d (%s)\n", s->out_csp, - av_color_space_name(s->out_csp)); - } - return AVERROR(EINVAL); - } redo_rgb2yuv = 1; } @@ -686,6 +667,26 @@ static av_cold int init(AVFilterContext *ctx) { ColorSpaceContext *s = ctx->priv; + s->out_csp = s->user_csp == AVCOL_SPC_UNSPECIFIED ? + default_csp[FFMIN(s->user_all, CS_NB)] : s->user_csp; + s->out_lumacoef = av_csp_luma_coeffs_from_avcsp(s->out_csp); + if (!s->out_lumacoef) { + if (s->out_csp == AVCOL_SPC_UNSPECIFIED) { + if (s->user_all == CS_UNSPECIFIED) { + av_log(ctx, AV_LOG_ERROR, + "Please specify output colorspace\n"); + } else { + av_log(ctx, AV_LOG_ERROR, + "Unsupported output color property %d\n", s->user_all); + } + } else { + av_log(ctx, AV_LOG_ERROR, + "Unsupported output colorspace %d (%s)\n", s->out_csp, + av_color_space_name(s->out_csp)); + } + return AVERROR(EINVAL); + } + ff_colorspacedsp_init(&s->dsp); return 0; @@ -745,10 +746,10 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) } else { out->color_trc = s->user_trc; } - out->colorspace = s->user_csp == AVCOL_SPC_UNSPECIFIED ? - default_csp[FFMIN(s->user_all, CS_NB)] : s->user_csp; - out->color_range = s->user_rng == AVCOL_RANGE_UNSPECIFIED ? - in->color_range : s->user_rng; + // FIXME color_range must be set in query_formats for negotiation. + // The value updated here will not be propagated further in the graph. + if (s->user_rng == AVCOL_RANGE_UNSPECIFIED) + out->color_range = outlink->color_range = in->color_range; if (rgb_sz != s->rgb_sz) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(out->format); int uvw = in->width >> desc->log2_chroma_w; @@ -838,10 +839,19 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE }; - int res; + int res, ret; ColorSpaceContext *s = ctx->priv; + AVFilterLink *outlink = ctx->outputs[0]; AVFilterFormats *formats = ff_make_format_list(pix_fmts); + if (ret = ff_formats_ref(ff_make_formats_list_singleton(s->out_csp), + &outlink->incfg.color_spaces) < 0) + return ret; + if (s->user_rng != AVCOL_RANGE_UNSPECIFIED + && (ret = ff_formats_ref(ff_make_formats_list_singleton(s->user_rng), + &outlink->incfg.color_ranges) < 0)) + return ret; + if (!formats) return AVERROR(ENOMEM); if (s->user_format == AV_PIX_FMT_NONE)