From patchwork Wed Dec 13 13:11:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45098 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4263325pzf; Wed, 13 Dec 2023 05:16:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEivFqEWPNzC99KKWDRLSsa9VBMgOioOUZmBHmGndDJgLXQ6EHnNB+w5o+hw0/nSZwVdXjk X-Received: by 2002:aa7:d51a:0:b0:551:da4f:6243 with SMTP id y26-20020aa7d51a000000b00551da4f6243mr2315577edq.1.1702473361111; Wed, 13 Dec 2023 05:16:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473361; cv=none; d=google.com; s=arc-20160816; b=FKUxR116OcIciwCt2oOhezyA3PtP9/jSUOi5SkanNr272YtO87Y1JZFD9XMHkkNOn+ QJh2iv9L+9q9R+oeOIyeHbvHJrSO/jzID2kRPCGiFMP7A6subt4FrttO30zPS+IJj0V0 3PseUHyINYiT1Nl645D7TF5hbnWAwynZlTW1MkI6qjq0P8HXr9lYpGkpHMQhxKk/bSVh ALXbBvN9tRViaUrp4DjTbWw5EU0JQEQ/PK9EFjFIWn463NlCL7RmrUZfSEMLQGt5ZegF hV4k+fPnjbE2j0GnPY3IhqELsYZuw+l5en+BpKPVZJXfDHx2rC9SZl0CnoX817neMSGJ ldXw== 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=8x53Bx2cWh3XZOZLzU4gv6lYL3Y/e/n8nC5hMgfBtxY=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=VbrucZvV8CsAdfhqdNoePn3ezjyqeh9zUYGZbj4yXj+mdAtNFoczofNi2CpJxL9y4v sG3zgq2um4NvSvcVFXkyzWlzkvkRRqRo+tnZ1JMD4R00T6Nriqmxqd9gmCshVB79sKDY kZH1tKjADl2Sbcff1Ni7ulVdFHvO4gLFQZSE2w6GzaS2F3tQ4AEZOmBsPtQ8Wi06YEqu F2ifGFnJ6OgcJ2LYkstAaeVmujPznJzP1GFuHiX1d4LCsZ30hfTdiJqpHFfTDxAcLsW3 5HA9WPsRDph9sfMGlmUMtKcHF/bVMMoTcaBVEsMYS0JvS8s25flGr39mClECxaGaFLLo pe+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=CUaiHhUU; 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 m25-20020a50d7d9000000b00548c6efe84bsi5832527edj.112.2023.12.13.05.16.00; Wed, 13 Dec 2023 05:16:01 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=CUaiHhUU; 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 6D3A268D185; Wed, 13 Dec 2023 15:15:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2E8BD68CFA3 for ; Wed, 13 Dec 2023 15:15:39 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id D05EC42DED; Wed, 13 Dec 2023 14:15:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473338; bh=GNnwyIhFIioCuX+gTm0EvHERsU4cBM1USNUQPhboY7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CUaiHhUUcYT1MD6U9ijtUqm2f9PlTScWScKeyqY9ziJpxfOcy9HramwSB3Moprzbn vnnGuhGfW5kRz6KrQpuNOYhdIepqszw8mMCPMzfNffKIQKh23/2uMhqKr6FKLAKb8H Io6GncadwTfOYucd3D6QtMEvHbwl4hIIQ8mushU8= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:11:58 +0100 Message-ID: <20231213131536.10242-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 01/15] avfilter/formats: document ff_default_query_formats 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: fL27jpXHqN+I From: Niklas Haas In particular, make it clear that this function will not touch format lists which were already set by the caller before calling into this function. --- libavfilter/formats.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 22224dce2d..d44890109e 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -198,6 +198,10 @@ void ff_channel_layouts_unref(AVFilterChannelLayouts **ref); void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref); +/** + * Sets all remaining unset filter lists for all inputs/outputs to their + * corresponding `ff_all_*()` lists. + */ av_warn_unused_result int ff_default_query_formats(AVFilterContext *ctx); From patchwork Wed Dec 13 13:11:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45099 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4263422pzf; Wed, 13 Dec 2023 05:16:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfVe1e9PXCI/pYnGXlLG8leUG1J6Oi1SsdaB9shLtqYIry4BDMjn2lbIU8ENX/7N/hjpmo X-Received: by 2002:a50:cd18:0:b0:54c:6199:97e1 with SMTP id z24-20020a50cd18000000b0054c619997e1mr3462064edi.2.1702473370045; Wed, 13 Dec 2023 05:16:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473370; cv=none; d=google.com; s=arc-20160816; b=cnU+/8XATmf+g9dR/xA5nsNwzgT5tANPhNVsuQbuIcD8AXD7HkxCiD8AnOBduhllan FuqrSF18mjBYpep6vSqkNnWTQgH32h1cFxV0IYgmKlrMb7RrHVnP3BBnLP/xCRPjjRbn T+qQZ5XeVGVzP7yyU6UJ5+5rRledZ9q6mUf26MTir4cD1Z9KgRmI4rijqwEBl+GPTVfg ChrfEEsj9d8W/R0kcf99taXfi1WqXX5AzmmDgFZDWp1Dj72f+2g9w0m5+8hwnU+ku8J9 ccreoOcBIl40MJslsPhJjvurU+nvj/4nn10tZScyPuwwNK9sd2huuNgMwCycVDOCF3Cz SKAg== 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=qrkID2ENSAQH5uIUEJuyTy59eY8IpmJlZPblZaWJq0U=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=bmJIZHBCgABrjaC+WUe0ufhvNDKafn/veGmg0IfXideLo0MdjuJnvl/5jYQpf9+81S tUmRuEc/BYqhx2gT6TPhCkcQl409uVTKqMt7SgnFEbzlvuUHTlW7P4aBLzGecCjyNg2u gdnCL3MgEZVmA9gOps5d85Neks6kPL3SGXwP0fOlfVY0UuhmKycYY3NFTjuIuoR8FbJP IC6SVoqTR+nfLEY8wLPfOTUvRxt398eecxO23GCGVnUoX3GSFvHefumSb6i8bcSF2Jdq uudbNbQUZYKXP6F6g1J6z5FHwFru10w0qk6n9Rh9yuyiuhiy973EYyZfVAOtNLop6GRW 1uXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=HB6JesPE; 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 n23-20020a5099d7000000b0054c62822aadsi5440834edb.488.2023.12.13.05.16.09; Wed, 13 Dec 2023 05:16:10 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=HB6JesPE; 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 7963B68D1CD; Wed, 13 Dec 2023 15:15:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 83A3168CFA3 for ; Wed, 13 Dec 2023 15:15:39 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 3867C4B966; Wed, 13 Dec 2023 14:15:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473339; bh=2n/UjgEALUnXEFdbp3MkQj90ZuMuQq4agS3gg6F76Vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HB6JesPEF1tLS7kzReebEDPpTvHxodUGJ0fn/E0EzJkoAaNq3dYNxVi9Um9Lb01p8 ueWfOHfnPm/7hDNy007TeSDJ9e/V3ic+jnT6CFMYaj17TOTFx+WK3G+Yi/XkOpIFzK 4kX0LdEYDEIxNIONzBFiciyvS1abCFzlsyYU6a8U= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:11:59 +0100 Message-ID: <20231213131536.10242-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 02/15] avfilter: always call ff_default_query_formats 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FeukPH5KuVIb From: Niklas Haas Even if a query func is set. This is safe to do, because ff_default_query_formats is documented not to touch any filter lists that were already set by the query func. The reason to do this is because it allows us to extend AVFilterFormatsConfig without having to touch every filter in existence. An alternative implementation of this commit would be to explicitly add a `ff_default_query_formats` call at the end of every query_formats function, but that would end up functionally equivalent to this change while touching a whole lot more code paths for no reason. As a bonus, eliminates some code/logic duplication from this function. --- libavfilter/avfiltergraph.c | 39 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 68daa93e61..625cbc022e 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -341,33 +341,21 @@ static int filter_check_formats(AVFilterContext *ctx) static int filter_query_formats(AVFilterContext *ctx) { int ret; - AVFilterFormats *formats; - AVFilterChannelLayouts *chlayouts; - enum AVMediaType type = ctx->inputs && ctx->inputs [0] ? ctx->inputs [0]->type : - ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type : - AVMEDIA_TYPE_VIDEO; - - if ((ret = ctx->filter->formats.query_func(ctx)) < 0) { - if (ret != AVERROR(EAGAIN)) - av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n", - ctx->name, av_err2str(ret)); - return ret; - } - ret = filter_check_formats(ctx); - if (ret < 0) - return ret; - formats = ff_all_formats(type); - if ((ret = ff_set_common_formats(ctx, formats)) < 0) - return ret; - if (type == AVMEDIA_TYPE_AUDIO) { - if ((ret = ff_set_common_all_samplerates(ctx)) < 0) + if (ctx->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) { + if ((ret = ctx->filter->formats.query_func(ctx)) < 0) { + if (ret != AVERROR(EAGAIN)) + av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n", + ctx->name, av_err2str(ret)); return ret; - chlayouts = ff_all_channel_layouts(); - if ((ret = ff_set_common_channel_layouts(ctx, chlayouts)) < 0) + } + + ret = filter_check_formats(ctx); + if (ret < 0) return ret; } - return 0; + + return ff_default_query_formats(ctx); } static int formats_declared(AVFilterContext *f) @@ -416,10 +404,7 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) AVFilterContext *f = graph->filters[i]; if (formats_declared(f)) continue; - if (f->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) - ret = filter_query_formats(f); - else - ret = ff_default_query_formats(f); + ret = filter_query_formats(f); if (ret < 0 && ret != AVERROR(EAGAIN)) return ret; /* note: EAGAIN could indicate a partial success, not counted yet */ From patchwork Wed Dec 13 13:12:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45100 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4263542pzf; Wed, 13 Dec 2023 05:16:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqTYu/Ncg3mN4JKATySJ8SWTrJi5NzZy18me/9SSztDF42W8VA3fWfzQiAFK6OMNtX5Vo8 X-Received: by 2002:a17:906:ca57:b0:a1b:81c6:3900 with SMTP id jx23-20020a170906ca5700b00a1b81c63900mr3517200ejb.80.1702473379357; Wed, 13 Dec 2023 05:16:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473379; cv=none; d=google.com; s=arc-20160816; b=oNkOLq+c7CKHKCBOXC22qRj0a+fkBx8rYftXCDGtDcB4BL7KOURMDpgieRb+TZ1cJS ntp4v3ho3jgkQ1y+IJRk7XQazDH3DTdTFitHiqfDV1nyK8NsYEKEDKGTfqlevNveBYpB rBTDlZgdPrfxXSFbPgg10Q8nUEeXYJbFUFyFmX+XV/7IUKtfiNDFE3+09cYosprgNZTS 0LQ0hIc9ecIsYVwRIw98IgjCKVIz8R6sewszDBgYXB9v2w8VEcEH0AkEKeNZiqohhGgL RxP0QjJsqzgwrhj7GSdTfJYL+NdGiNKWUaPjOQYNOONm2fMJCcumSeCsn3hnbPfzcdAT jtUw== 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=zGn95xb63yMaamG4YXHXypWK0O+TGTXyb0ZJBX3pueM=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=BFwcnx29J/Y+L1Go6ljaXxe4fDXdKmmPU6SXCpxPAXpGBgWKE22jogrtW24+7YX37b qZOTDyixwXGPVAfc6PATo1U4iNfMeORIOjsFppnFuFhlNHDq6ucdfDAsgoHSBy7csADn xTy803utIM/0HKtANr21PEYdBLDZ7YLKqOTEUWaJ4uuYiBYlRh8tEaAT5sN+pfF9mMMg rwY73LyJdWbfian9+MMK1gOTZS1IRp7VS4SjHrmBdH8IT9uT2Wcx5andl0sHKhgR89DV +fF8+Y75w2KUaBfi4RENOSkegjym0B5yUWXoOyFFVBZoyOEmOH5LvHWCJ/B9bhOM2z+y b7oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=px1LtJ4h; 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 p18-20020a170906229200b00a1d2978f576si5380324eja.811.2023.12.13.05.16.18; Wed, 13 Dec 2023 05:16:19 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=px1LtJ4h; 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 8F61268D19A; Wed, 13 Dec 2023 15:15:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D0F1768CFA3 for ; Wed, 13 Dec 2023 15:15:39 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 84C1E4BC3D; Wed, 13 Dec 2023 14:15:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473339; bh=TqRxfg3TYRtdQFbvcYsfearLIjYaVB++E0YrVpcm7tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=px1LtJ4hDPjSvR1Lr2xhkDeEq7dnu+GLTGH7/zzLxfoMZoY/qQ1+3413bLVT40Cop Y3Mp8o8QYRURb9fXgeAKy9WXFfxqDdhttZGPadgoDYL7qXN8sLYH2I9AWGQVXh79wz wvjWE9IK2r5DxLXdU4hsfCQI8vFLgRQLzsn7+DH4= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:00 +0100 Message-ID: <20231213131536.10242-4-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 03/15] avfilter: add negotiation API for color space/range 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3cTj62bzwuIn From: Niklas Haas Motivated by YUVJ removal. This change will allow full negotiation between color ranges and matrices as needed. By default, all ranges and matrices are marked as supported. Because grayscale formats are currently handled very inconsistently (and in particular, assumed as forced full-range by swscale), we exclude them from negotiation altogether for the time being, to get this API merged. After filter negotiation is available, we can relax the grayscale-is-forced-jpeg restriction again, when it will be more feasible to do so without breaking a million test cases. Note that this commit updates one FATE test as a consequence of the sanity fallback for non-YUV formats. In particular, the test case now writes rgb24(pc, gbr/unspecified/unspecified) to the matroska file, instead of rgb24(unspecified/unspecified/unspecified) as before. --- doc/APIchanges | 3 + libavfilter/avfilter.c | 17 +++- libavfilter/avfilter.h | 28 ++++++ libavfilter/avfiltergraph.c | 173 +++++++++++++++++++++++++++++++++++- libavfilter/formats.c | 122 ++++++++++++++++++++++++- libavfilter/formats.h | 54 +++++++++++ libavfilter/internal.h | 6 ++ libavfilter/vaapi_vpp.c | 4 + libavfilter/video.c | 2 + tests/ref/fate/shortest-sub | 4 +- 10 files changed, 404 insertions(+), 9 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 4a2dc1c44f..2f6ea50f63 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-11-xx - xxxxxxxxxx - lavf 58.14.100 - avfilter.h + Add AVFilterLink.colorspace, AVFilterLink.color_range + 2023-11-08 - b82957a66a7 - lavu 58.32.100 - channel_layout.h Add AV_CH_LAYOUT_7POINT2POINT3 and AV_CHANNEL_LAYOUT_7POINT2POINT3. Add AV_CH_LAYOUT_9POINT1POINT4_BACK and AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK. diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index bde1c33d07..31300bb515 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -185,6 +185,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, link->type = src->output_pads[srcpad].type; av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1); link->format = -1; + link->colorspace = AVCOL_SPC_UNSPECIFIED; ff_framequeue_init(&link->fifo, &src->graph->internal->frame_queues); return 0; @@ -286,6 +287,12 @@ int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, if (link->outcfg.formats) ff_formats_changeref(&link->outcfg.formats, &filt->outputs[filt_dstpad_idx]->outcfg.formats); + if (link->outcfg.color_spaces) + ff_formats_changeref(&link->outcfg.color_spaces, + &filt->outputs[filt_dstpad_idx]->outcfg.color_spaces); + if (link->outcfg.color_ranges) + ff_formats_changeref(&link->outcfg.color_ranges, + &filt->outputs[filt_dstpad_idx]->outcfg.color_ranges); if (link->outcfg.samplerates) ff_formats_changeref(&link->outcfg.samplerates, &filt->outputs[filt_dstpad_idx]->outcfg.samplerates); @@ -730,6 +737,10 @@ static void free_link(AVFilterLink *link) ff_formats_unref(&link->incfg.formats); ff_formats_unref(&link->outcfg.formats); + ff_formats_unref(&link->incfg.color_spaces); + ff_formats_unref(&link->outcfg.color_spaces); + ff_formats_unref(&link->incfg.color_ranges); + ff_formats_unref(&link->outcfg.color_ranges); ff_formats_unref(&link->incfg.samplerates); ff_formats_unref(&link->outcfg.samplerates); ff_channel_layouts_unref(&link->incfg.channel_layouts); @@ -987,9 +998,9 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame) strcmp(link->dst->filter->name, "idet") && strcmp(link->dst->filter->name, "null") && strcmp(link->dst->filter->name, "scale")) { - av_assert1(frame->format == link->format); - av_assert1(frame->width == link->w); - av_assert1(frame->height == link->h); + av_assert1(frame->format == link->format); + av_assert1(frame->width == link->w); + av_assert1(frame->height == link->h); } frame->sample_aspect_ratio = link->sample_aspect_ratio; diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index d69381aed4..246d000251 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -301,6 +301,14 @@ typedef struct AVFilter { * @ref AVFilterFormatsConfig.formats "incfg.formats" * on every output link to a list of pixel/sample formats that the filter * supports on that link. + * For video links, this filter may also set + * @ref AVFilterFormatsConfig.color_spaces "incfg.color_spaces" + * / + * @ref AVFilterFormatsConfig.color_spaces "outcfg.color_spaces" + * and @ref AVFilterFormatsConfig.color_ranges "incfg.color_ranges" + * / + * @ref AVFilterFormatsConfig.color_ranges "outcfg.color_ranges" + * analogously. * For audio links, this filter must also set * @ref AVFilterFormatsConfig.samplerates "incfg.samplerates" * / @@ -322,6 +330,10 @@ typedef struct AVFilter { * to indicate that this filter supports each of these pixel formats, * provided that all inputs and outputs use the same pixel format. * + * In addition to that the generic code will mark all inputs + * and all outputs as supporting all color spaces and ranges, as + * long as all inputs and outputs use the same color space/range. + * * This list must never be NULL if the union is in this state. * The type of all inputs and outputs of filters using this must * be AVMEDIA_TYPE_VIDEO. @@ -514,6 +526,12 @@ typedef struct AVFilterFormatsConfig { */ AVFilterChannelLayouts *channel_layouts; + /** + * Lists of supported YUV color metadata, only for YUV video. + */ + AVFilterFormats *color_spaces; ///< AVColorSpace + AVFilterFormats *color_ranges; ///< AVColorRange + } AVFilterFormatsConfig; /** @@ -565,6 +583,16 @@ struct AVFilterLink { AVChannelLayout ch_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h) + /** + * For non-YUV links, these are respectively set to fallback values (as + * appropriate for that colorspace). + * + * Note: This includes grayscale formats, as these are currently treated + * as forced full range always. + */ + enum AVColorSpace colorspace; ///< agreed upon YUV color space + enum AVColorRange color_range; ///< agreed upon YUV color range + /***************************************************************** * All fields below this line are not part of the public API. They * may not be used outside of libavfilter and can be changed and diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 625cbc022e..ef739735bd 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -27,6 +27,7 @@ #include "libavutil/avassert.h" #include "libavutil/bprint.h" #include "libavutil/channel_layout.h" +#include "libavutil/hwcontext.h" #include "libavutil/imgutils.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" @@ -298,7 +299,9 @@ static int filter_link_check_formats(void *log, AVFilterLink *link, AVFilterForm switch (link->type) { case AVMEDIA_TYPE_VIDEO: - if ((ret = ff_formats_check_pixel_formats(log, cfg->formats)) < 0) + if ((ret = ff_formats_check_pixel_formats(log, cfg->formats)) < 0 || + (ret = ff_formats_check_color_spaces(log, cfg->color_spaces)) < 0 || + (ret = ff_formats_check_color_ranges(log, cfg->color_ranges)) < 0) return ret; break; @@ -365,6 +368,10 @@ static int formats_declared(AVFilterContext *f) for (i = 0; i < f->nb_inputs; i++) { if (!f->inputs[i]->outcfg.formats) return 0; + if (f->inputs[i]->type == AVMEDIA_TYPE_VIDEO && + !(f->inputs[i]->outcfg.color_ranges && + f->inputs[i]->outcfg.color_spaces)) + return 0; if (f->inputs[i]->type == AVMEDIA_TYPE_AUDIO && !(f->inputs[i]->outcfg.samplerates && f->inputs[i]->outcfg.channel_layouts)) @@ -373,6 +380,10 @@ static int formats_declared(AVFilterContext *f) for (i = 0; i < f->nb_outputs; i++) { if (!f->outputs[i]->incfg.formats) return 0; + if (f->outputs[i]->type == AVMEDIA_TYPE_VIDEO && + !(f->outputs[i]->incfg.color_ranges && + f->outputs[i]->incfg.color_spaces)) + return 0; if (f->outputs[i]->type == AVMEDIA_TYPE_AUDIO && !(f->outputs[i]->incfg.samplerates && f->outputs[i]->incfg.channel_layouts)) @@ -493,7 +504,16 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) av_assert0( inlink->outcfg.formats->refcount > 0); av_assert0(outlink->incfg.formats->refcount > 0); av_assert0(outlink->outcfg.formats->refcount > 0); - if (outlink->type == AVMEDIA_TYPE_AUDIO) { + if (outlink->type == AVMEDIA_TYPE_VIDEO) { + av_assert0( inlink-> incfg.color_spaces->refcount > 0); + av_assert0( inlink->outcfg.color_spaces->refcount > 0); + av_assert0(outlink-> incfg.color_spaces->refcount > 0); + av_assert0(outlink->outcfg.color_spaces->refcount > 0); + av_assert0( inlink-> incfg.color_ranges->refcount > 0); + av_assert0( inlink->outcfg.color_ranges->refcount > 0); + av_assert0(outlink-> incfg.color_ranges->refcount > 0); + av_assert0(outlink->outcfg.color_ranges->refcount > 0); + } else if (outlink->type == AVMEDIA_TYPE_AUDIO) { av_assert0( inlink-> incfg.samplerates->refcount > 0); av_assert0( inlink->outcfg.samplerates->refcount > 0); av_assert0(outlink-> incfg.samplerates->refcount > 0); @@ -583,6 +603,30 @@ static enum AVSampleFormat find_best_sample_fmt_of_2(enum AVSampleFormat dst_fmt return score1 < score2 ? dst_fmt1 : dst_fmt2; } +int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); + if (!desc) + return 0; + if (desc->nb_components < 3) + return 0; /* Grayscale is explicitly full-range in swscale */ + av_assert1(!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)); + if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL | + AV_PIX_FMT_FLAG_XYZ | AV_PIX_FMT_FLAG_FLOAT)) + return 0; + + switch (fmt) { + case AV_PIX_FMT_YUVJ420P: + case AV_PIX_FMT_YUVJ422P: + case AV_PIX_FMT_YUVJ444P: + case AV_PIX_FMT_YUVJ440P: + case AV_PIX_FMT_YUVJ411P: + return 0; + default: + return 1; + } +} + static int pick_format(AVFilterLink *link, AVFilterLink *ref) { if (!link || !link->incfg.formats) @@ -621,7 +665,46 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref) link->incfg.formats->nb_formats = 1; link->format = link->incfg.formats->formats[0]; - if (link->type == AVMEDIA_TYPE_AUDIO) { + if (link->type == AVMEDIA_TYPE_VIDEO) { + enum AVPixelFormat swfmt = link->format; + if (av_pix_fmt_desc_get(swfmt)->flags & AV_PIX_FMT_FLAG_HWACCEL) { + av_assert1(link->hw_frames_ctx); + swfmt = ((AVHWFramesContext *) link->hw_frames_ctx->data)->sw_format; + } + + if (!ff_fmt_is_regular_yuv(swfmt)) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(swfmt); + /* These fields are explicitly documented as affecting YUV only, + * so set them to sane values for other formats. */ + if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) + link->color_range = AVCOL_RANGE_UNSPECIFIED; + else + link->color_range = AVCOL_RANGE_JPEG; + if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_XYZ)) { + link->colorspace = AVCOL_SPC_RGB; + } else { + link->colorspace = AVCOL_SPC_UNSPECIFIED; + } + } else { + if (!link->incfg.color_spaces->nb_formats) { + av_log(link->src, AV_LOG_ERROR, "Cannot select color space for" + " the link between filters %s and %s.\n", link->src->name, + link->dst->name); + return AVERROR(EINVAL); + } + link->incfg.color_spaces->nb_formats = 1; + link->colorspace = link->incfg.color_spaces->formats[0]; + + if (!link->incfg.color_ranges->nb_formats) { + av_log(link->src, AV_LOG_ERROR, "Cannot select color range for" + " the link between filters %s and %s.\n", link->src->name, + link->dst->name); + return AVERROR(EINVAL); + } + link->incfg.color_ranges->nb_formats = 1; + link->color_range = link->incfg.color_ranges->formats[0]; + } + } else if (link->type == AVMEDIA_TYPE_AUDIO) { int ret; if (!link->incfg.samplerates->nb_formats) { @@ -661,6 +744,10 @@ FF_ENABLE_DEPRECATION_WARNINGS ff_formats_unref(&link->outcfg.samplerates); ff_channel_layouts_unref(&link->incfg.channel_layouts); ff_channel_layouts_unref(&link->outcfg.channel_layouts); + ff_formats_unref(&link->incfg.color_spaces); + ff_formats_unref(&link->outcfg.color_spaces); + ff_formats_unref(&link->incfg.color_ranges); + ff_formats_unref(&link->outcfg.color_ranges); return 0; } @@ -822,6 +909,82 @@ static void swap_samplerates(AVFilterGraph *graph) swap_samplerates_on_filter(graph->filters[i]); } +static void swap_color_spaces_on_filter(AVFilterContext *filter) +{ + AVFilterLink *link = NULL; + enum AVColorSpace csp; + int i; + + for (i = 0; i < filter->nb_inputs; i++) { + link = filter->inputs[i]; + if (link->type == AVMEDIA_TYPE_VIDEO && + link->outcfg.color_spaces->nb_formats == 1) + break; + } + if (i == filter->nb_inputs) + return; + + csp = link->outcfg.color_spaces->formats[0]; + + for (i = 0; i < filter->nb_outputs; i++) { + AVFilterLink *outlink = filter->outputs[i]; + if (outlink->type != AVMEDIA_TYPE_VIDEO) + continue; + /* there is no meaningful 'score' between different yuv matrices, + * so just prioritize an exact match if it exists */ + for (int j = 0; j < outlink->incfg.color_spaces->nb_formats; j++) { + if (csp == outlink->incfg.color_spaces->formats[j]) { + FFSWAP(int, outlink->incfg.color_spaces->formats[0], + outlink->incfg.color_spaces->formats[j]); + break; + } + } + } +} + +static void swap_color_spaces(AVFilterGraph *graph) +{ + for (int i = 0; i < graph->nb_filters; i++) + swap_color_spaces_on_filter(graph->filters[i]); +} + +static void swap_color_ranges_on_filter(AVFilterContext *filter) +{ + AVFilterLink *link = NULL; + enum AVColorRange range; + int i; + + for (i = 0; i < filter->nb_inputs; i++) { + link = filter->inputs[i]; + if (link->type == AVMEDIA_TYPE_VIDEO && + link->outcfg.color_ranges->nb_formats == 1) + break; + } + if (i == filter->nb_inputs) + return; + + range = link->outcfg.color_ranges->formats[0]; + + for (i = 0; i < filter->nb_outputs; i++) { + AVFilterLink *outlink = filter->outputs[i]; + if (outlink->type != AVMEDIA_TYPE_VIDEO) + continue; + for (int j = 0; j < outlink->incfg.color_ranges->nb_formats; j++) { + if (range == outlink->incfg.color_ranges->formats[j]) { + FFSWAP(int, outlink->incfg.color_ranges->formats[0], + outlink->incfg.color_ranges->formats[j]); + break; + } + } + } +} + +static void swap_color_ranges(AVFilterGraph *graph) +{ + for (int i = 0; i < graph->nb_filters; i++) + swap_color_ranges_on_filter(graph->filters[i]); +} + #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER) #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT) #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT) @@ -1098,6 +1261,10 @@ static int graph_config_formats(AVFilterGraph *graph, void *log_ctx) if ((ret = reduce_formats(graph)) < 0) return ret; + /* for video filters, ensure that the best colorspace metadata is selected */ + swap_color_spaces(graph); + swap_color_ranges(graph); + /* for audio filters, ensure the best format, sample rate and channel layout * is selected */ swap_sample_fmts(graph); diff --git a/libavfilter/formats.c b/libavfilter/formats.c index d1c97daf64..20f00d2db4 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -321,12 +321,46 @@ static int merge_channel_layouts(void *a, void *b) return merge_channel_layouts_internal(a, b, 0); } +static int merge_generic_internal(AVFilterFormats *a, + AVFilterFormats *b, int check) +{ + av_assert2(check || (a->refcount && b->refcount)); + + if (a == b) + return 1; + + MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0); + + return 1; +} + +static int can_merge_generic(const void *a, const void *b) +{ + return merge_generic_internal((AVFilterFormats *)a, + (AVFilterFormats *)b, 1); +} + +static int merge_generic(void *a, void *b) +{ + return merge_generic_internal(a, b, 0); +} + static const AVFilterFormatsMerger mergers_video[] = { { .offset = offsetof(AVFilterFormatsConfig, formats), .merge = merge_pix_fmts, .can_merge = can_merge_pix_fmts, }, + { + .offset = offsetof(AVFilterFormatsConfig, color_spaces), + .merge = merge_generic, + .can_merge = can_merge_generic, + }, + { + .offset = offsetof(AVFilterFormatsConfig, color_ranges), + .merge = merge_generic, + .can_merge = can_merge_generic, + }, }; static const AVFilterFormatsMerger mergers_audio[] = { @@ -594,6 +628,33 @@ AVFilterChannelLayouts *ff_all_channel_counts(void) return ret; } +AVFilterFormats *ff_all_color_spaces(void) +{ + AVFilterFormats *ret = NULL; + if (ff_add_format(&ret, AVCOL_SPC_UNSPECIFIED) < 0) + return NULL; + for (int csp = 0; csp < AVCOL_SPC_NB; csp++) { + if (csp == AVCOL_SPC_RESERVED || + csp == AVCOL_SPC_UNSPECIFIED) + continue; + if (ff_add_format(&ret, csp) < 0) + return NULL; + } + + return ret; +} + +AVFilterFormats *ff_all_color_ranges(void) +{ + AVFilterFormats *ret = NULL; + for (int range = 0; range < AVCOL_RANGE_NB; range++) { + if (ff_add_format(&ret, range) < 0) + return NULL; + } + + return ret; +} + #define FORMATS_REF(f, ref, unref_fn) \ void *tmp; \ \ @@ -763,6 +824,42 @@ int ff_set_common_all_samplerates(AVFilterContext *ctx) return ff_set_common_samplerates(ctx, ff_all_samplerates()); } +int ff_set_common_color_spaces(AVFilterContext *ctx, + AVFilterFormats *color_spaces) +{ + SET_COMMON_FORMATS(ctx, color_spaces, AVMEDIA_TYPE_VIDEO, + ff_formats_ref, ff_formats_unref); +} + +int ff_set_common_color_spaces_from_list(AVFilterContext *ctx, + const int *color_ranges) +{ + return ff_set_common_color_spaces(ctx, ff_make_format_list(color_ranges)); +} + +int ff_set_common_all_color_spaces(AVFilterContext *ctx) +{ + return ff_set_common_color_spaces(ctx, ff_all_color_spaces()); +} + +int ff_set_common_color_ranges(AVFilterContext *ctx, + AVFilterFormats *color_ranges) +{ + SET_COMMON_FORMATS(ctx, color_ranges, AVMEDIA_TYPE_VIDEO, + ff_formats_ref, ff_formats_unref); +} + +int ff_set_common_color_ranges_from_list(AVFilterContext *ctx, + const int *color_ranges) +{ + return ff_set_common_color_ranges(ctx, ff_make_format_list(color_ranges)); +} + +int ff_set_common_all_color_ranges(AVFilterContext *ctx) +{ + return ff_set_common_color_ranges(ctx, ff_all_color_ranges()); +} + /** * A helper for query_formats() which sets all links to the same list of * formats. If there are no links hooked to this filter, the list of formats is @@ -817,7 +914,14 @@ int ff_default_query_formats(AVFilterContext *ctx) ret = ff_set_common_formats(ctx, formats); if (ret < 0) return ret; - if (type == AVMEDIA_TYPE_AUDIO) { + if (type == AVMEDIA_TYPE_VIDEO) { + ret = ff_set_common_all_color_spaces(ctx); + if (ret < 0) + return ret; + ret = ff_set_common_all_color_ranges(ctx); + if (ret < 0) + return ret; + } else if (type == AVMEDIA_TYPE_AUDIO) { ret = ff_set_common_all_channel_counts(ctx); if (ret < 0) return ret; @@ -935,6 +1039,22 @@ int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts) return check_list(log, "sample rate", fmts); } +int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts) +{ + for (int i = 0; fmts && i < fmts->nb_formats; i++) { + if (fmts->formats[i] == AVCOL_SPC_RESERVED) { + av_log(log, AV_LOG_ERROR, "Invalid color range\n"); + return AVERROR(EINVAL); + } + } + return check_list(log, "color space", fmts); +} + +int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts) +{ + return check_list(log, "color range", fmts); +} + static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b) { return !av_channel_layout_compare(a, b) || diff --git a/libavfilter/formats.h b/libavfilter/formats.h index d44890109e..82b3af4be1 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -130,6 +130,20 @@ AVFilterChannelLayouts *ff_all_channel_counts(void); av_warn_unused_result AVFilterChannelLayouts *ff_make_channel_layout_list(const AVChannelLayout *fmts); +/** + * Construct an AVFilterFormats representing all possible color spaces. + * + * Note: This list does not include AVCOL_SPC_RESERVED. + */ +av_warn_unused_result +AVFilterFormats *ff_all_color_spaces(void); + +/** + * Construct an AVFilterFormats representing all possible color ranges. + */ +av_warn_unused_result +AVFilterFormats *ff_all_color_ranges(void); + /** * Helpers for query_formats() which set all free audio links to the same list * of channel layouts/sample rates. If there are no links hooked to this list, @@ -165,6 +179,38 @@ int ff_set_common_samplerates_from_list(AVFilterContext *ctx, av_warn_unused_result int ff_set_common_all_samplerates(AVFilterContext *ctx); +av_warn_unused_result +int ff_set_common_color_spaces(AVFilterContext *ctx, + AVFilterFormats *color_spaces); +/** + * Equivalent to ff_set_common_color_spaces(ctx, ff_make_format_list(color_spaces)) + */ +av_warn_unused_result +int ff_set_common_color_spaces_from_list(AVFilterContext *ctx, + const int *color_spaces); + +/** + * Equivalent to ff_set_common_color_spaces(ctx, ff_all_color_spaces()) + */ +av_warn_unused_result +int ff_set_common_all_color_spaces(AVFilterContext *ctx); + +av_warn_unused_result +int ff_set_common_color_ranges(AVFilterContext *ctx, + AVFilterFormats *color_ranges); +/** + * Equivalent to ff_set_common_color_ranges(ctx, ff_make_format_list(color_ranges)) + */ +av_warn_unused_result +int ff_set_common_color_ranges_from_list(AVFilterContext *ctx, + const int *color_ranges); + +/** + * Equivalent to ff_set_common_color_ranges(ctx, ff_all_color_ranges()) + */ +av_warn_unused_result +int ff_set_common_all_color_ranges(AVFilterContext *ctx); + /** * A helper for query_formats() which sets all links to the same list of * formats. If there are no links hooked to this filter, the list of formats is @@ -328,6 +374,14 @@ int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts); */ int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts); +/** + * Check that fmts is a valid formats list for YUV colorspace metadata. + * + * In particular, check for duplicates. + */ +int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts); +int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts); + typedef struct AVFilterFormatMerger { unsigned offset; int (*merge)(void *a, void *b); diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 2dbc5def0a..a6cdf9994c 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -203,6 +203,12 @@ enum FilterFormatsState { */ int ff_fmt_is_in(int fmt, const int *fmts); +/** + * Returns true if a pixel format is "regular YUV", which includes all pixel + * formats that are affected by YUV colorspace negotiation. + */ +int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt); + /* Functions to parse audio format arguments */ /** diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c index cf2592e068..59961bfa4a 100644 --- a/libavfilter/vaapi_vpp.c +++ b/libavfilter/vaapi_vpp.c @@ -38,6 +38,10 @@ int ff_vaapi_vpp_query_formats(AVFilterContext *avctx) &avctx->outputs[0]->incfg.formats)) < 0) return err; + if ((err = ff_set_common_all_color_spaces(avctx)) < 0 || + (err = ff_set_common_all_color_ranges(avctx)) < 0) + return err; + return 0; } diff --git a/libavfilter/video.c b/libavfilter/video.c index 42eeb98c28..243762c8fd 100644 --- a/libavfilter/video.c +++ b/libavfilter/video.c @@ -96,6 +96,8 @@ AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int alig return NULL; frame->sample_aspect_ratio = link->sample_aspect_ratio; + frame->colorspace = link->colorspace; + frame->color_range = link->color_range; return frame; } diff --git a/tests/ref/fate/shortest-sub b/tests/ref/fate/shortest-sub index 9caee587ce..16b1324e83 100644 --- a/tests/ref/fate/shortest-sub +++ b/tests/ref/fate/shortest-sub @@ -1,5 +1,5 @@ -73d142a80965f9e0884a5863abde0dab *tests/data/fate/shortest-sub.matroska -139249 tests/data/fate/shortest-sub.matroska +d6608277c93097383e62388196dc62f0 *tests/data/fate/shortest-sub.matroska +139260 tests/data/fate/shortest-sub.matroska #extradata 1: 167, 0xf7272d5f #tb 0: 1/1000 #media_type 0: video From patchwork Wed Dec 13 13:12:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45101 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4263638pzf; Wed, 13 Dec 2023 05:16:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDvLJI703D3UFKS42w1i2I/fZfbYh4ak6ZldyF9W7T9B/b5pK+OxRkrGSS3Yqy/4+EEoQE X-Received: by 2002:a50:d695:0:b0:54c:4837:81dc with SMTP id r21-20020a50d695000000b0054c483781dcmr4776071edi.45.1702473389028; Wed, 13 Dec 2023 05:16:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473389; cv=none; d=google.com; s=arc-20160816; b=Ufs7EJgBCKhFoW61r4yW3dujiB9s77h/yMxU2XM+LH15PC/fDX42Bts7Cyy46poMXv vPEr7ACNO+88Ymk2sCxXBs1rZGL7Dxo1p7sCv4UR/YMqkynx8pwEwC8Gca/dqw7W9c6n pEzIh7dGUSNNtg/jNstw3eivpX7LTtJFrSWBPeGCuDYdgLRQIkv41QGeuabwNqdHggIZ OwkCLhx7Gwq/nHyU14QWNK9AMDWYDmxeKE1GmhglTdaG7i2DXp5xtLx4cKjplabLjh6E haUg9AAAwRYD5bAw7aK9tMW7yR5MKdG+otApPTl6xMzYWgp2etCuXokPGXYqUkARj86I yBsQ== 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=mi5N/cbcaGYNhS7BvFOrNPGA4EGD+VL8bHNnYRWUOyw=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=swAJ4idQh8H80NVioIJuizpGMVlnMiN7qbNiBq6LG/yh5gSXvCdDz6Bv6wYYujjM1E 4hGvfwSEy9ufWerOMsp7oTf2llH3IpQAgrnWn0uSxtFsGZjP5AZ38WwrTfyWA04k+91L +NTzQ2AjOcny+wtoidImad9v3CDzIF7atXSDBicyiX2RKEsAiwD6san8wv6kN/owUmYb d01mQXwbf0KwxaTjsYlLjdNwR+3dG5IzB88473OAnrlqgeKGFCt+K6xdeBxrGAFUflHF PmdgsF8rXEmSxww/q3vOG7ZZTGjFpWnbRtS8Ur0TPAuzq0U7w+lcSG3RzX+KIExuftv4 dA1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=NIwlGuK6; 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 m20-20020a50d7d4000000b00551f60ad09asi726578edj.405.2023.12.13.05.16.28; Wed, 13 Dec 2023 05:16:29 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=NIwlGuK6; 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 89A8E68D1EA; Wed, 13 Dec 2023 15:15:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1EDFC68D032 for ; Wed, 13 Dec 2023 15:15:40 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id CC6524BCE7; Wed, 13 Dec 2023 14:15:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473339; bh=I7I4fttVRxE4mXq1G+8qvnf/fG9VCc/wYkEmnaCWdH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NIwlGuK6KX4Kbif6vuoAHMLeiBtyab8Z+DMva6s2qZYQrX13x4P2bamKgn3tWUshO mqyYmj3UWeZxvoGJtPEq6+tSz9PpGf0n/MRwuOFaPQdLf4iTSDbxhx56J+YGyTYJmQ GSu4U1p77CQlShxC2iezcOFsUN5rAn8fQkUpqPT0= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:01 +0100 Message-ID: <20231213131536.10242-5-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 04/15] fftools/ffmpeg_filter: don't clear buffersrc params 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Oxu+5wiPiRlx From: Niklas Haas This memset is bogus, it accomplishes nothing in the best case and regresses future additions to AVBufferSrcParameters in the worst case. --- fftools/ffmpeg_filter.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index ada235b084..e5b00123f2 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1461,11 +1461,8 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, int ret, pad_idx = 0; int64_t tsoffset = 0; AVBufferSrcParameters *par = av_buffersrc_parameters_alloc(); - if (!par) return AVERROR(ENOMEM); - memset(par, 0, sizeof(*par)); - par->format = AV_PIX_FMT_NONE; if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { av_log(fg, AV_LOG_ERROR, "Cannot connect video filter to audio input\n"); From patchwork Wed Dec 13 13:12:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45105 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4264048pzf; Wed, 13 Dec 2023 05:17:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2+riBboLA/83N0uEsYyIZV4VQFYHuWCilMAXqq7A2M/DjPp1s50x/RZqYonlsI5V0E3R0 X-Received: by 2002:a05:6402:1e86:b0:54f:55ad:f4e6 with SMTP id f6-20020a0564021e8600b0054f55adf4e6mr2274777edf.70.1702473426668; Wed, 13 Dec 2023 05:17:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473426; cv=none; d=google.com; s=arc-20160816; b=EPITOu5kn1MxCOwQyvx4CbLh+L6YoVwWwp1dTlSuVPD1ONze15FBu0WFFSGyUkeIX1 d+if+2PuSD8MU/zTJvxxFFfuxRNpYQKmzYh26oGraTSaK8vMGlVW84WOu+RFda9wpwuJ K/X2qkiFElU6xG+etP5ObJfaKlW8ruOlHA2UcY8r//2KR8SrYTvVqNhDuAe5tMkXCvAb ZNW3Lp89wm1+x8sEl5VpbKjtwY/DybF+30KxeLr+eG+Tux/tgVe89zHsB5pICv7ytINv oftMFC/TBUiixzk07yi0Gl1u+IDUDnC5r1ZOUgGd5Ho3YTLdeSAmCUVUFjZ6Vmh91M9P X6ZQ== 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=wHsqU2hcWHInJ1JSDaXXltHeXXBO9XksTm1pFNO7vXs=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=bxLJvBVbXzVU0mdcyObzR5E3hy1xqh8LjhZBF5QGsXi96oWxw2KtSGXNuxu3llawYu 12l93Fz4EGqos4BQXCpYzQIvKw/PPJGkAGNV1NbITj/F6h2sVL6ZkOsQwpUHdpXrPEbl izvvdJjT0mX/tYACvoivWtpL9eTzCUDzjOWrJW0v8+wBlhMiAvFi23F3gdZkop3sxuB6 18AiF2PjYwLf/0WzpaWEFLvp73cuTM6I5xVn3YP3CUH7oJdmjhnz3zSeEDgIDJ3VcClG iELk1tl4dCeNwY3ki3X+Ju9eQbB7YmCsI0ycG/25HENPqus1zAZZ4QxW4CbUrXEOqDyX Wj6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=SIvoA5wD; 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 s30-20020a50ab1e000000b0054f58424532si4799153edc.421.2023.12.13.05.17.05; Wed, 13 Dec 2023 05:17:06 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=SIvoA5wD; 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 0311068D201; Wed, 13 Dec 2023 15:15:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 074A168D1DD for ; Wed, 13 Dec 2023 15:15:44 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 2F80D4BCE9; Wed, 13 Dec 2023 14:15:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473340; bh=ZcYFxTklFesptx2PECHMCGDTCO2G3Yq5crfJkSJxChU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SIvoA5wDvNhKsyY736h4XPuqDi5bXRL3IR2qYNCzYuGZOgnWbg0KgtDINzrYRcyq+ R/QEr+3QYqQLvYv0kkprSqQBIlxYD5fonk3Zqj0pnBL06z0ERK3gqQm9O7sBd3h9nW jhKPgsWIY2xg1GLxa8YZk+rr/J2iVy7Hi2YgK4UQ= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:02 +0100 Message-ID: <20231213131536.10242-6-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 05/15] avfilter/buffersrc: add color_space/range parameters 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: i9r2WJ0s1GXM From: Niklas Haas To allow adding proper negotiation, in particular, to fftools. These values will simply be negotiated downstream for YUV formats, and ignored otherwise. --- doc/filters.texi | 10 ++++++ libavfilter/buffersrc.c | 74 ++++++++++++++++++++++++++++++++++++----- libavfilter/buffersrc.h | 6 ++++ 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 6d00ba2c3f..f182dc2ddb 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -28025,6 +28025,16 @@ Specify the timebase assumed by the timestamps of the buffered frames. @item frame_rate Specify the frame rate expected for the video stream. +@item colorspace +A string representing the color space of the buffered video frames. +It may be a number corresponding to a color space, or a color space +name. + +@item range +A string representing the color range of the buffered video frames. +It may be a number corresponding to a color range, or a color range +name. + @item pixel_aspect, sar The sample (pixel) aspect ratio of the input video. diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index b0a905d455..1c5db94696 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -28,6 +28,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/common.h" #include "libavutil/frame.h" +#include "libavutil/hwcontext.h" #include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/opt.h" @@ -50,6 +51,8 @@ typedef struct BufferSourceContext { /* video only */ int w, h; enum AVPixelFormat pix_fmt; + enum AVColorSpace color_space; + enum AVColorRange color_range; AVRational pixel_aspect; AVBufferRef *hw_frames_ctx; @@ -65,10 +68,13 @@ typedef struct BufferSourceContext { int64_t last_pts; } BufferSourceContext; -#define CHECK_VIDEO_PARAM_CHANGE(s, c, width, height, format, pts)\ - if (c->w != width || c->h != height || c->pix_fmt != format) {\ - av_log(s, AV_LOG_INFO, "filter context - w: %d h: %d fmt: %d, incoming frame - w: %d h: %d fmt: %d pts_time: %s\n",\ - c->w, c->h, c->pix_fmt, width, height, format, av_ts2timestr(pts, &s->outputs[0]->time_base));\ +#define CHECK_VIDEO_PARAM_CHANGE(s, c, width, height, format, csp, range, pts)\ + if (c->w != width || c->h != height || c->pix_fmt != format ||\ + c->color_space != csp || c->color_range != range) {\ + av_log(s, AV_LOG_INFO, "filter context - w: %d h: %d fmt: %d csp: %s range: %s, incoming frame - w: %d h: %d fmt: %d csp: %s range: %s pts_time: %s\n",\ + c->w, c->h, c->pix_fmt, av_color_space_name(c->color_space), av_color_range_name(c->color_range),\ + width, height, format, av_color_space_name(csp), av_color_range_name(range),\ + av_ts2timestr(pts, &s->outputs[0]->time_base));\ av_log(s, AV_LOG_WARNING, "Changing video frame properties on the fly is not supported by all filters.\n");\ } @@ -89,6 +95,8 @@ AVBufferSrcParameters *av_buffersrc_parameters_alloc(void) return NULL; par->format = -1; + par->color_range = AVCOL_RANGE_UNSPECIFIED; + par->color_space = AVCOL_SPC_UNSPECIFIED; return par; } @@ -119,6 +127,10 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par if (!s->hw_frames_ctx) return AVERROR(ENOMEM); } + if (param->color_space != AVCOL_SPC_UNSPECIFIED) + s->color_space = param->color_space; + if (param->color_range != AVCOL_RANGE_UNSPECIFIED) + s->color_range = param->color_range; break; case AVMEDIA_TYPE_AUDIO: if (param->format != AV_SAMPLE_FMT_NONE) { @@ -206,7 +218,8 @@ FF_ENABLE_DEPRECATION_WARNINGS switch (ctx->outputs[0]->type) { case AVMEDIA_TYPE_VIDEO: CHECK_VIDEO_PARAM_CHANGE(ctx, s, frame->width, frame->height, - frame->format, frame->pts); + frame->format, frame->colorspace, + frame->color_range, frame->pts); break; case AVMEDIA_TYPE_AUDIO: /* For layouts unknown on input but known on link after negotiation. */ @@ -303,10 +316,11 @@ static av_cold int init_video(AVFilterContext *ctx) return AVERROR(EINVAL); } - av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d\n", + av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d csp:%s range:%s\n", c->w, c->h, av_get_pix_fmt_name(c->pix_fmt), c->time_base.num, c->time_base.den, c->frame_rate.num, c->frame_rate.den, - c->pixel_aspect.num, c->pixel_aspect.den); + c->pixel_aspect.num, c->pixel_aspect.den, + av_color_space_name(c->color_space), av_color_range_name(c->color_range)); return 0; } @@ -329,6 +343,30 @@ static const AVOption buffer_options[] = { { "pixel_aspect", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V }, { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V }, { "frame_rate", NULL, OFFSET(frame_rate), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V }, + { "colorspace", "select colorspace", OFFSET(color_space), AV_OPT_TYPE_INT, {.i64=AVCOL_SPC_UNSPECIFIED}, 0, AVCOL_SPC_NB-1, V, "colorspace"}, + { "gbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_RGB}, INT_MIN, INT_MAX, V, "colorspace"}, + { "bt709", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT709}, INT_MIN, INT_MAX, V, "colorspace"}, + { "unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_UNSPECIFIED}, INT_MIN, INT_MAX, V, "colorspace"}, + { "fcc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_FCC}, INT_MIN, INT_MAX, V, "colorspace"}, + { "bt470bg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT470BG}, INT_MIN, INT_MAX, V, "colorspace"}, + { "smpte170m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_SMPTE170M}, INT_MIN, INT_MAX, V, "colorspace"}, + { "smpte240m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_SMPTE240M}, INT_MIN, INT_MAX, V, "colorspace"}, + { "ycgco", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_YCGCO}, INT_MIN, INT_MAX, V, "colorspace"}, + { "bt2020nc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT2020_NCL}, INT_MIN, INT_MAX, V, "colorspace"}, + { "bt2020c", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT2020_CL}, INT_MIN, INT_MAX, V, "colorspace"}, + { "smpte2085", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_SMPTE2085}, INT_MIN, INT_MAX, V, "colorspace"}, + { "chroma-derived-nc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_CHROMA_DERIVED_NCL},INT_MIN, INT_MAX, V, "colorspace"}, + { "chroma-derived-c", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_CHROMA_DERIVED_CL}, INT_MIN, INT_MAX, V, "colorspace"}, + { "ictcp", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_ICTCP}, INT_MIN, INT_MAX, V, "colorspace"}, + { "range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, AVCOL_RANGE_NB-1, V, "range"}, + { "unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, V, "range"}, + { "unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, V, "range"}, + { "limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, + { "pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, + { "jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, { NULL }, }; @@ -426,13 +464,33 @@ static int query_formats(AVFilterContext *ctx) AVFilterChannelLayouts *channel_layouts = NULL; AVFilterFormats *formats = NULL; AVFilterFormats *samplerates = NULL; + AVFilterFormats *color_spaces = NULL; + AVFilterFormats *color_ranges = NULL; int ret; switch (ctx->outputs[0]->type) { - case AVMEDIA_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO:; + enum AVPixelFormat swfmt = c->pix_fmt; + if (av_pix_fmt_desc_get(swfmt)->flags & AV_PIX_FMT_FLAG_HWACCEL) { + if (!c->hw_frames_ctx) { + av_log(ctx, AV_LOG_ERROR, "Setting BufferSourceContext.pix_fmt " + "to a HW format requires hw_frames_ctx to be non-NULL!\n"); + return AVERROR(EINVAL); + } + swfmt = ((AVHWFramesContext *) c->hw_frames_ctx->data)->sw_format; + } if ((ret = ff_add_format (&formats, c->pix_fmt)) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0) return ret; + /* force specific colorspace/range downstream only for ordinary YUV */ + if (ff_fmt_is_regular_yuv(swfmt)) { + if ((ret = ff_add_format(&color_spaces, c->color_space)) < 0 || + (ret = ff_set_common_color_spaces(ctx, color_spaces)) < 0) + return ret; + if ((ret = ff_add_format(&color_ranges, c->color_range)) < 0 || + (ret = ff_set_common_color_ranges(ctx, color_ranges)) < 0) + return ret; + } break; case AVMEDIA_TYPE_AUDIO: if ((ret = ff_add_format (&formats , c->sample_fmt )) < 0 || diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h index 3b248b37cd..1e29f0340e 100644 --- a/libavfilter/buffersrc.h +++ b/libavfilter/buffersrc.h @@ -123,6 +123,12 @@ typedef struct AVBufferSrcParameters { * Audio only, the audio channel layout */ AVChannelLayout ch_layout; + + /** + * Video only, the YUV colorspace and range. + */ + enum AVColorSpace color_space; + enum AVColorRange color_range; } AVBufferSrcParameters; /** From patchwork Wed Dec 13 13:12:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45106 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4264163pzf; Wed, 13 Dec 2023 05:17:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeLxPChPS1P4Sqi+TPJn7uqwSQF4UPud1sPr7m2VCTT/MGXZ3BwrZASWeSJiyBpX8/r+zP X-Received: by 2002:a19:675e:0:b0:50b:ed57:758c with SMTP id e30-20020a19675e000000b0050bed57758cmr6513763lfj.1.1702473435716; Wed, 13 Dec 2023 05:17:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473435; cv=none; d=google.com; s=arc-20160816; b=DQdNT2k0FqHqHlm6adlWdaedBbcpq4VNpJXouOeXA2fxxxPbiT8aa90ljbPgij6ifz 5I3LWwZOZLW3f9FY3ZGdN21iy6CrsM5JzvoNRWTkGwUDLYKENLH/PlBRxKuEOYeWU394 kXDIo5SO9d1fxD0RVfwfKS0Q0BBNJvFTZ7sXoItHIcFNMMJOksQICq7oYA52pZROBb7w yCPeGj1seyQd8XkqfxNrSfVH2yckqH5hFmw2kZSGwny7BpK7D69hP2aWxKvX2tKjLjnN C4O/3ZICa8mUxbc7gsNvB0EER/3aKYg3v+1BVt//mkSdSzNBHmANg5dr4NgpsRA4Ic4o R4JA== 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=nn8eco7JVXOa/OIAJPk24CaguhGqezab96+c9boMtN0=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=hMiFUfzUlLBFRwtwCk216ttfIaGleGL1pb2jsl4cxLxRu7FFoZU36YOFT8BdscpXt9 d9Jxr3FXfAk+fJA/ozA6ewwcrHAt73ECBFNpZHohZda1nfuEqsv0jKR/3k0tAA4By0NW B6e27OE0OSkxl49GT0itm6Qe8wAbTOq88E42yNgoxSSKs6QN2i89SHVcC3xW1BNF37ap mpFeq4MzJCe7JxR1PkAjjvZPl5NDIJe7l1WDTf4E3t7CSCmjt+AiulXQfcBUmBpgOwP3 bxOvvHax02mVieMgqb21n7dnv/EmWp8izLdhSRElDCkfn4Jfapotyb/3/1Kh9KNohtsS lytA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="Ky/iVNXz"; 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 z38-20020a509e29000000b0055238966e45si70677ede.135.2023.12.13.05.17.15; Wed, 13 Dec 2023 05:17:15 -0800 (PST) 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=@haasn.xyz header.s=mail header.b="Ky/iVNXz"; 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 E904168D237; Wed, 13 Dec 2023 15:15:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 156CF68D1DE for ; Wed, 13 Dec 2023 15:15:44 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 7CA774BCFF; Wed, 13 Dec 2023 14:15:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473340; bh=aCvvFZQzFXRVQGem8J5EQXj+lefEwzd6Dd9dVBlTixU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ky/iVNXz6po8VAkNl2HC6hvfDuF/7Ivsed5MG8adByz2dUXFTJlag5FvcIPvQyzBT LkNzEo/aev3qD7HRwebo6Rb+lnRd/vkvRZERqrH9DDLBINU341i6vKk9nZ9GjeF/wS mOXZzUsRHCLl7SDR9rIgvv+owmA1sW+gr6jcThGA= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:03 +0100 Message-ID: <20231213131536.10242-7-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 06/15] fftools/ffmpeg_filter: configure buffersrc with csp/range 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ORqs/UrDuJ8g From: Niklas Haas Propagates input metadata to the input filter graph. --- fftools/ffmpeg_filter.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index e5b00123f2..2da6d307a0 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -126,6 +126,8 @@ typedef struct InputFilterPriv { int width, height; AVRational sample_aspect_ratio; + enum AVColorSpace color_space; + enum AVColorRange color_range; int sample_rate; AVChannelLayout ch_layout; @@ -146,6 +148,8 @@ typedef struct InputFilterPriv { int width; int height; AVRational sample_aspect_ratio; + enum AVColorSpace color_space; + enum AVColorRange color_range; int sample_rate; AVChannelLayout ch_layout; @@ -257,6 +261,8 @@ static int sub2video_get_blank_frame(InputFilterPriv *ifp) frame->width = ifp->width; frame->height = ifp->height; frame->format = ifp->format; + frame->colorspace = ifp->color_space; + frame->color_range = ifp->color_range; ret = av_frame_get_buffer(frame, 0); if (ret < 0) @@ -833,6 +839,8 @@ static InputFilter *ifilter_alloc(FilterGraph *fg) ifp->index = fg->nb_inputs - 1; ifp->format = -1; ifp->fallback.format = -1; + ifp->color_space = ifp->fallback.color_space = AVCOL_SPC_UNSPECIFIED; + ifp->color_range = ifp->fallback.color_range = AVCOL_RANGE_UNSPECIFIED; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifp->frame_queue) @@ -1485,9 +1493,11 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprintf(&args, "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:" - "pixel_aspect=%d/%d", + "pixel_aspect=%d/%d:colorspace=%s:range=%s", ifp->width, ifp->height, ifp->format, - ifp->time_base.num, ifp->time_base.den, sar.num, sar.den); + ifp->time_base.num, ifp->time_base.den, sar.num, sar.den, + av_color_space_name(ifp->color_space), + av_color_range_name(ifp->color_range)); if (fr.num && fr.den) av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den); snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index, @@ -1831,6 +1841,8 @@ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec) ifp->fallback.width = dec->width; ifp->fallback.height = dec->height; ifp->fallback.sample_aspect_ratio = dec->sample_aspect_ratio; + ifp->fallback.color_space = dec->colorspace; + ifp->fallback.color_range = dec->color_range; } else if (dec->codec_type == AVMEDIA_TYPE_AUDIO) { int ret; @@ -1871,6 +1883,8 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr ifp->width = frame->width; ifp->height = frame->height; ifp->sample_aspect_ratio = frame->sample_aspect_ratio; + ifp->color_space = frame->colorspace; + ifp->color_range = frame->color_range; ifp->sample_rate = frame->sample_rate; ret = av_channel_layout_copy(&ifp->ch_layout, &frame->ch_layout); @@ -2543,6 +2557,8 @@ static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter, ifp->width = ifp->fallback.width; ifp->height = ifp->fallback.height; ifp->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio; + ifp->color_space = ifp->fallback.color_space; + ifp->color_range = ifp->fallback.color_range; ret = av_channel_layout_copy(&ifp->ch_layout, &ifp->fallback.ch_layout); @@ -2586,7 +2602,9 @@ static int send_frame(FilterGraph *fg, FilterGraphThread *fgt, break; case AVMEDIA_TYPE_VIDEO: need_reinit |= ifp->width != frame->width || - ifp->height != frame->height; + ifp->height != frame->height || + ifp->color_space != frame->colorspace || + ifp->color_range != frame->color_range; break; } From patchwork Wed Dec 13 13:12:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45107 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4264271pzf; Wed, 13 Dec 2023 05:17:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRy7guAwwZiXz3Y+n50Fx1490/vj34nLDimlDoYv1p0+SeMEVlYpVY1timAtrEJJJ7qC1t X-Received: by 2002:a17:907:7644:b0:a04:7ef6:b403 with SMTP id kj4-20020a170907764400b00a047ef6b403mr3747461ejc.52.1702473445399; Wed, 13 Dec 2023 05:17:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473445; cv=none; d=google.com; s=arc-20160816; b=ILgTJiXdTh77FSs9BRqr37nFZvwqeEidizGl6aOQNZzdzURplYpQ9ZoLRh6kx6ST3t 8K2EFhKZqrYqVWyONQ3jdC1B60t3WDGPdtAHzAlW3FB+I0yqlWG83oUnqO5t6vo4hsbh /GX1JxgIScpEcWz/4Q3RgSn4Z4JwFmYDoV+JKpGV6gkdkT6XwGG5w0uxCPduoH30hIIP IctgC/+3CE+nY+avN5UHmqg3433GlhsVLfHyPx9avj6o7ynxS+8rCiggYf/Kqriz3gCU 8YKdlyJskTYtfpm1R/GmFp+AFoAtwMJqxSGK2jMWfteVNBVYZ17YteWkImw1kceMPgjR x/Pg== 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=yfFJeN2xlQYkrSQ1RuIEPAc7YJLxTS4ZQLFaVRV62EQ=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=dN1ux9f5fieusOsDr9otHIMd5V0S35LSxxJ3KmpzhB5qy5XAXv5q8TCYkSWdqFt2W/ h8jjGIkVC24TBeIoa2pz9LqN4XKx2TWZnZ+RIwfsOgp3+JD3N9oddvT3H3jrtine/pbR JuCeBlNAMu54rBxNk0LWUcUQm2TyE5A4wGZDR7M2hMKFW20e6bTlBTp370VJXtZv/eDB fApXDRbikDaACZ6Ky9huP9agTASbkwV/TU4XlS0BssAO1BOFm55/+2yhKldo3W6pNnb0 C2AbkkGE9SbXwnAMdQSTIzpHU3uJ+1WXAT1USV4Tj0I3wqucF1AMsH1WO24/m7m4WmLc ihwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=divrls1d; 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 dv9-20020a170906b80900b009fe3afeee58si5496854ejb.165.2023.12.13.05.17.24; Wed, 13 Dec 2023 05:17:25 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=divrls1d; 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 E78C268D240; Wed, 13 Dec 2023 15:15:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 58BE168D1EA for ; Wed, 13 Dec 2023 15:15:44 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id C284A4BD22; Wed, 13 Dec 2023 14:15:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473340; bh=SMvW86ZlvsxihCbqjkbgQE4XUfQvIf25/7yNvxHT48Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=divrls1dsZKnLu+nlXzB3f5gczsQxbVQveWsw/gOWJcvIMeu1gl1pVkT6KxLfuE71 dNSdShEwcUdvvhhochFf8tzCZ4sRvhvOqd28Ykp4hcR0JPo3DdR354VuUi3+DKeXwO 119IYqoAlqhu/G5qOqw6tyOLm3vn3jzbRpA9kAu8= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:04 +0100 Message-ID: <20231213131536.10242-8-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 07/15] vf_scale: 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: LBDvJPFu+svj From: Niklas Haas This filter will always accept any input format, even if the user sets a specific in_range/in_color_matrix. This is to preserve status quo with current behavior, where passing a specific in_color_matrix merely overrides the incoming frames' attributes. (Use `vf_format` to force a specific input range) Because changing colorspace and color_range now requires reconfiguring the link, we can lift sws_setColorspaceDetails out of scale_frame and into config_props. (This will also get re-called if the input frame properties change) --- libavfilter/vf_scale.c | 188 ++++++++++++++++++++++------------------- 1 file changed, 103 insertions(+), 85 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index b45035907b..44dc1f2bf8 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -143,7 +143,6 @@ typedef struct ScaleContext { int out_color_matrix; int in_range; - int in_frame_range; int out_range; int out_h_chr_pos; @@ -292,6 +291,18 @@ static av_cold int preinit(AVFilterContext *ctx) return 0; } +static const int sws_colorspaces[] = { + AVCOL_SPC_UNSPECIFIED, + AVCOL_SPC_RGB, + AVCOL_SPC_BT709, + AVCOL_SPC_BT470BG, + AVCOL_SPC_SMPTE170M, + AVCOL_SPC_FCC, + AVCOL_SPC_SMPTE240M, + AVCOL_SPC_BT2020_NCL, + -1 +}; + static av_cold int init(AVFilterContext *ctx) { ScaleContext *scale = ctx->priv; @@ -332,6 +343,19 @@ static av_cold int init(AVFilterContext *ctx) if (ret < 0) return ret; + if (scale->in_color_matrix != -1 && + !ff_fmt_is_in(scale->in_color_matrix, sws_colorspaces)) { + av_log(ctx, AV_LOG_ERROR, "Unsupported input color matrix '%s'\n", + av_color_space_name(scale->in_color_matrix)); + return AVERROR(EINVAL); + } + + if (!ff_fmt_is_in(scale->out_color_matrix, sws_colorspaces)) { + av_log(ctx, AV_LOG_ERROR, "Unsupported output color matrix '%s'\n", + av_color_space_name(scale->out_color_matrix)); + return AVERROR(EINVAL); + } + av_log(ctx, AV_LOG_VERBOSE, "w:%s h:%s flags:'%s' interl:%d\n", scale->w_expr, scale->h_expr, (char *)av_x_if_null(scale->flags_str, ""), scale->interlaced); @@ -356,8 +380,6 @@ static av_cold int init(AVFilterContext *ctx) if (!threads) av_opt_set_int(scale->sws_opts, "threads", ff_filter_get_nb_threads(ctx), 0); - scale->in_frame_range = AVCOL_RANGE_UNSPECIFIED; - return 0; } @@ -376,6 +398,7 @@ static av_cold void uninit(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx) { + ScaleContext *scale = ctx->priv; AVFilterFormats *formats; const AVPixFmtDescriptor *desc; enum AVPixelFormat pix_fmt; @@ -407,6 +430,28 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->incfg.formats)) < 0) return ret; + /* accept all supported inputs, even if user overrides their properties */ + if ((ret = ff_formats_ref(ff_make_format_list(sws_colorspaces), + &ctx->inputs[0]->outcfg.color_spaces)) < 0) + return ret; + + if ((ret = ff_formats_ref(ff_all_color_ranges(), + &ctx->inputs[0]->outcfg.color_ranges)) < 0) + return ret; + + /* propagate output properties if overridden */ + formats = scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED + ? ff_make_formats_list_singleton(scale->out_color_matrix) + : ff_make_format_list(sws_colorspaces); + if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->incfg.color_spaces)) < 0) + return ret; + + formats = scale->out_range != AVCOL_RANGE_UNSPECIFIED + ? ff_make_formats_list_singleton(scale->out_range) + : ff_all_color_ranges(); + if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->incfg.color_ranges)) < 0) + return ret; + return 0; } @@ -497,6 +542,7 @@ static int config_props(AVFilterLink *outlink) const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outfmt); ScaleContext *scale = ctx->priv; uint8_t *flags_val = NULL; + int in_range, in_colorspace; int ret; if ((ret = scale_eval_dimensions(ctx)) < 0) @@ -521,6 +567,14 @@ static int config_props(AVFilterLink *outlink) if (outfmt == AV_PIX_FMT_PAL8) outfmt = AV_PIX_FMT_BGR8; scale->output_is_pal = av_pix_fmt_desc_get(outfmt)->flags & AV_PIX_FMT_FLAG_PAL; + in_range = scale->in_range; + if (in_range == AVCOL_RANGE_UNSPECIFIED) + in_range = inlink0->color_range; + + in_colorspace = scale->in_color_matrix; + if (in_colorspace == -1 /* auto */) + in_colorspace = inlink0->colorspace; + if (scale->sws) sws_freeContext(scale->sws); if (scale->isws[0]) @@ -530,8 +584,8 @@ static int config_props(AVFilterLink *outlink) scale->isws[0] = scale->isws[1] = scale->sws = NULL; if (inlink0->w == outlink->w && inlink0->h == outlink->h && - scale->out_color_matrix == AVCOL_SPC_UNSPECIFIED && - scale->in_range == scale->out_range && + in_range == outlink->color_range && + in_colorspace == outlink->colorspace && inlink0->format == outlink->format) ; else { @@ -540,6 +594,8 @@ static int config_props(AVFilterLink *outlink) for (i = 0; i < 3; i++) { int in_v_chr_pos = scale->in_v_chr_pos, out_v_chr_pos = scale->out_v_chr_pos; + int in_full, out_full, brightness, contrast, saturation; + const int *inv_table, *table; struct SwsContext *const s = sws_alloc_context(); if (!s) return AVERROR(ENOMEM); @@ -555,15 +611,12 @@ static int config_props(AVFilterLink *outlink) av_opt_set_int(s, "dstw", outlink->w, 0); av_opt_set_int(s, "dsth", outlink->h >> !!i, 0); av_opt_set_int(s, "dst_format", outfmt, 0); - if (scale->in_range != AVCOL_RANGE_UNSPECIFIED) - av_opt_set_int(s, "src_range", - scale->in_range == AVCOL_RANGE_JPEG, 0); - else if (scale->in_frame_range != AVCOL_RANGE_UNSPECIFIED) + if (in_range != AVCOL_RANGE_UNSPECIFIED) av_opt_set_int(s, "src_range", - scale->in_frame_range == AVCOL_RANGE_JPEG, 0); - if (scale->out_range != AVCOL_RANGE_UNSPECIFIED) + in_range == AVCOL_RANGE_JPEG, 0); + if (outlink->color_range != AVCOL_RANGE_UNSPECIFIED) av_opt_set_int(s, "dst_range", - scale->out_range == AVCOL_RANGE_JPEG, 0); + outlink->color_range == AVCOL_RANGE_JPEG, 0); /* Override chroma location default settings to have the correct * chroma positions. MPEG chroma positions are used by convention. @@ -584,6 +637,24 @@ static int config_props(AVFilterLink *outlink) if ((ret = sws_init_context(s, NULL, NULL)) < 0) return ret; + + sws_getColorspaceDetails(s, (int **)&inv_table, &in_full, + (int **)&table, &out_full, + &brightness, &contrast, &saturation); + + if (scale->in_color_matrix == -1 /* auto */) + inv_table = sws_getCoefficients(inlink0->colorspace); + else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) + inv_table = sws_getCoefficients(scale->in_color_matrix); + if (outlink->colorspace != AVCOL_SPC_UNSPECIFIED) + table = sws_getCoefficients(outlink->colorspace); + else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) + table = inv_table; + + sws_setColorspaceDetails(s, inv_table, in_full, + table, out_full, + brightness, contrast, saturation); + if (!scale->interlaced) break; } @@ -597,10 +668,12 @@ static int config_props(AVFilterLink *outlink) if (scale->sws) av_opt_get(scale->sws, "sws_flags", 0, &flags_val); - av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d flags:%s\n", + av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s csp:%s range:%s sar:%d/%d -> w:%d h:%d fmt:%s csp:%s range:%s sar:%d/%d flags:%s\n", inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format), + av_color_space_name(inlink->colorspace), av_color_range_name(inlink->color_range), inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den, outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format), + av_color_space_name(outlink->colorspace), av_color_range_name(outlink->color_range), outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den, flags_val); av_freep(&flags_val); @@ -620,6 +693,8 @@ static int config_props_ref(AVFilterLink *outlink) outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; outlink->time_base = inlink->time_base; outlink->frame_rate = inlink->frame_rate; + outlink->colorspace = inlink->colorspace; + outlink->color_range = inlink->color_range; return 0; } @@ -693,7 +768,6 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out) const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format); char buf[32]; int ret; - int in_range; int frame_changed; *frame_out = NULL; @@ -704,14 +778,9 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out) in->height != link->h || in->format != link->format || in->sample_aspect_ratio.den != link->sample_aspect_ratio.den || - in->sample_aspect_ratio.num != link->sample_aspect_ratio.num; - - if (in->color_range != AVCOL_RANGE_UNSPECIFIED && - scale->in_range == AVCOL_RANGE_UNSPECIFIED && - in->color_range != scale->in_frame_range) { - scale->in_frame_range = in->color_range; - frame_changed = 1; - } + in->sample_aspect_ratio.num != link->sample_aspect_ratio.num || + in->colorspace != link->colorspace || + in->color_range != link->color_range; if (scale->eval_mode == EVAL_MODE_FRAME || frame_changed) { unsigned vars_w[VARS_NB] = { 0 }, vars_h[VARS_NB] = { 0 }; @@ -768,9 +837,11 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif } - link->dst->inputs[0]->format = in->format; - link->dst->inputs[0]->w = in->width; - link->dst->inputs[0]->h = in->height; + link->dst->inputs[0]->format = in->format; + link->dst->inputs[0]->w = in->width; + link->dst->inputs[0]->h = in->height; + link->dst->inputs[0]->colorspace = in->colorspace; + link->dst->inputs[0]->color_range = in->color_range; link->dst->inputs[0]->sample_aspect_ratio.den = in->sample_aspect_ratio.den; link->dst->inputs[0]->sample_aspect_ratio.num = in->sample_aspect_ratio.num; @@ -798,69 +869,12 @@ scale: av_frame_copy_props(out, in); out->width = outlink->w; out->height = outlink->h; + out->color_range = outlink->color_range; + out->colorspace = outlink->colorspace; if (scale->output_is_pal) avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format); - in_range = in->color_range; - - if ( scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED - || scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED - || scale-> in_range != AVCOL_RANGE_UNSPECIFIED - || in_range != AVCOL_RANGE_UNSPECIFIED - || scale->out_range != AVCOL_RANGE_UNSPECIFIED) { - int in_full, out_full, brightness, contrast, saturation; - const int *inv_table, *table; - - sws_getColorspaceDetails(scale->sws, (int **)&inv_table, &in_full, - (int **)&table, &out_full, - &brightness, &contrast, &saturation); - - if (scale->in_color_matrix == -1 /* auto */) - inv_table = sws_getCoefficients(in->colorspace); - else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) - inv_table = sws_getCoefficients(scale->in_color_matrix); - if (scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED) - table = sws_getCoefficients(scale->out_color_matrix); - else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) - table = inv_table; - - if (scale-> in_range != AVCOL_RANGE_UNSPECIFIED) - in_full = (scale-> in_range == AVCOL_RANGE_JPEG); - else if (in_range != AVCOL_RANGE_UNSPECIFIED) - in_full = (in_range == AVCOL_RANGE_JPEG); - if (scale->out_range != AVCOL_RANGE_UNSPECIFIED) - out_full = (scale->out_range == AVCOL_RANGE_JPEG); - - sws_setColorspaceDetails(scale->sws, inv_table, in_full, - table, out_full, - brightness, contrast, saturation); - if (scale->isws[0]) - sws_setColorspaceDetails(scale->isws[0], inv_table, in_full, - table, out_full, - brightness, contrast, saturation); - if (scale->isws[1]) - sws_setColorspaceDetails(scale->isws[1], inv_table, in_full, - table, out_full, - brightness, contrast, saturation); - - out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; - if (scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED) - out->colorspace = scale->out_color_matrix; - } - - // Sanity checks: - // 1. If the output is RGB, set the matrix coefficients to RGB. - // 2. If the output is not RGB and we've got the RGB/XYZ (identity) - // matrix configured, unset the matrix. - // In theory these should be in swscale itself as the AVFrame - // based API gets in, so that not every swscale API user has - // to go through duplicating such sanity checks. - if (av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB) - out->colorspace = AVCOL_SPC_RGB; - else if (out->colorspace == AVCOL_SPC_RGB) - out->colorspace = AVCOL_SPC_UNSPECIFIED; - av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den, (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w, (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h, @@ -905,7 +919,9 @@ static int filter_frame_ref(AVFilterLink *link, AVFrame *in) in->height != link->h || in->format != link->format || in->sample_aspect_ratio.den != link->sample_aspect_ratio.den || - in->sample_aspect_ratio.num != link->sample_aspect_ratio.num; + in->sample_aspect_ratio.num != link->sample_aspect_ratio.num || + in->colorspace != link->colorspace || + in->color_range != link->color_range; if (frame_changed) { link->format = in->format; @@ -913,6 +929,8 @@ static int filter_frame_ref(AVFilterLink *link, AVFrame *in) link->h = in->height; link->sample_aspect_ratio.num = in->sample_aspect_ratio.num; link->sample_aspect_ratio.den = in->sample_aspect_ratio.den; + link->colorspace = in->colorspace; + link->color_range = in->color_range; config_props_ref(outlink); } From patchwork Wed Dec 13 13:12:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45108 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4264358pzf; Wed, 13 Dec 2023 05:17:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCsdw6tnAKHuhce8fEHyj2x7PgTwEpvG6dEj+iMsJ3SDkUu9yjcdZkcmkco6yNr931Nj0k X-Received: by 2002:a17:906:99cb:b0:9e6:dfee:8143 with SMTP id s11-20020a17090699cb00b009e6dfee8143mr8781957ejn.3.1702473454964; Wed, 13 Dec 2023 05:17:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473454; cv=none; d=google.com; s=arc-20160816; b=so51unUbNCzbipjpitIN1zBxsPXzvZABTQOMJHY1WKgJJppichNGlSX7w/PztTOtgO PWdovgwqQtuVGLcAsYIolipNmJuCRec1krwmgopmeAYh8tDB3ojr2+8+GMQ6hWKusE/D glahjJcMdSBy/jcaxDEFPL9LGPczhRBXEEbEJ/1yiYA0OzAqQygo9EISz8V+nZswdY7q ns+SNKWmGoPChHW1Z3/c00Zs+Auklq7WaZH7cjzyU3eMPEI6cADYoKYV6yjtiSnX2tVe sk+vr8JIjO3z6U0NnhkxcFCOxPbe9I1EYF2NRi4o9VnrNcoOlYNjRTNi/88SQU9jhcpE 99Vg== 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=cZU0lyMlgXJUEDzSq3kk2Po6U67JbCDtIN2I+a6c/V0=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=fCbBbzWL1GdELslS+wdQgHqlEv1BNI4RDFqEvSixR2nSO5Pz5o0GuO16VsT4Lgx9xX IcUXcu361Xp6QD8dhGiCEhfrfClYgXla8nZmwIVeeSQ/He0AdXyPfbXmhJ/W9XSWGphy ll21h4PVwkun/KByho4F/byS3YmY9MWG41huxtMpxvWZDQXX2K35+jWFN+7RoiujW090 pzhcNwttYM8pIOV2+zAEF48ewKGq48G2OoRl0sxeqGpEdF9k3CogxRF9gcjLZnTX5VSY OJr6yX3H/Jhl6tg7Rh0EuzNhC8mpc93FJZ2kdOXuh/eH3fwfxsFoLy4zQMhQ/lq7Q1zu 7Rwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=DAr0uLB4; 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 lg22-20020a170906f89600b009ae09378e2dsi5684137ejb.875.2023.12.13.05.17.34; Wed, 13 Dec 2023 05:17:34 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=DAr0uLB4; 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 0EE3968D25E; Wed, 13 Dec 2023 15:15:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6AE4968D19A for ; Wed, 13 Dec 2023 15:15:44 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 337FB4BD26; Wed, 13 Dec 2023 14:15:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473341; bh=wlBJ4p5mzEzY83SdJzRejvHKWRO5+lJCsaf8qFisoU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DAr0uLB47UxAC2iGg37leoe6SHMFgCOA8hX3oIp0sod7qsF0Q/C4zQGcJhJdJykei yUaiS2nuCp3FlrAK4txiJ2osQ9GlxuKpWM9UBuSfxNjAPG2Y/Te/lXeaIuWaqR2yyx PKR1b22mwwoyj6I8b1vUjVzOvJoWZB2UTxIfK4Uc= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:05 +0100 Message-ID: <20231213131536.10242-9-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 08/15] avfilter/vf_zscale: remove unused variables 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: y+qCZr8JFZwf From: Niklas Haas Only assigned, never read. --- libavfilter/vf_zscale.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c index 788870ffaf..f76c9954cd 100644 --- a/libavfilter/vf_zscale.c +++ b/libavfilter/vf_zscale.c @@ -132,12 +132,6 @@ typedef struct ZScaleContext { zimg_graph_builder_params alpha_params, params; zimg_graph_builder_params alpha_params_tmp, params_tmp; zimg_filter_graph *alpha_graph[MAX_THREADS], *graph[MAX_THREADS]; - - enum AVColorSpace in_colorspace, out_colorspace; - enum AVColorTransferCharacteristic in_trc, out_trc; - enum AVColorPrimaries in_primaries, out_primaries; - enum AVColorRange in_range, out_range; - enum AVChromaLocation in_chromal, out_chromal; } ZScaleContext; typedef struct ThreadData { @@ -816,15 +810,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) link->dst->inputs[0]->h = in->height; s->nb_threads = av_clip(FFMIN(ff_filter_get_nb_threads(ctx), FFMIN(link->h, outlink->h) / MIN_TILESIZE), 1, MAX_THREADS); - s->in_colorspace = in->colorspace; - s->in_trc = in->color_trc; - s->in_primaries = in->color_primaries; - s->in_range = in->color_range; - s->out_colorspace = out->colorspace; - s->out_trc = out->color_trc; - s->out_primaries = out->color_primaries; - s->out_range = out->color_range; - slice_params(s, out->height, in->height); zimg_image_format_default(&s->src_format, ZIMG_API_VERSION); From patchwork Wed Dec 13 13:12:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45109 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4264424pzf; Wed, 13 Dec 2023 05:17:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPvVYX57N49VvnBZXjpIdbPGBmWvNrW4ebg8qr4KGbpAfIYey4f4tHVM+PZsokn1SbCssq X-Received: by 2002:a05:6402:222b:b0:551:3f17:4763 with SMTP id cr11-20020a056402222b00b005513f174763mr2013070edb.80.1702473464459; Wed, 13 Dec 2023 05:17:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473464; cv=none; d=google.com; s=arc-20160816; b=OjOnBEU3mKov2rqeKBPIVlWJ/wXKFXY82jgayh9NDA2wnHZ9ZVLuN0l+Ab7m55LB3W GnhCEl2NUNMQLXfbU0vPnbehX5tO8teUXLU76ARYQT6qR37vk/JBPN3eWPC++xw383dO G0uTWG19pVm/x6K+zLbw9ujTarXbQWAZOwHYcJSdeH17/ZRd5VKicUN5avPW3w8CiPdF zDJcUH48a7a5CTTEbWiWjoqD3M7ouUDLKpK1qEyVllfa+zT7EMXjrsHNU1+9P7O2Si+F IRZa7LGRuWZzo1ABNdME+GYQuty5KmJlg85Xj0uOibiqAc/Bbjm+pgNF4AUPGpz9bSwn oGgA== 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=jShybgn+WkgYYD8DuihiafD+6CcIyBhvYcTU3JSwY30=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=aUiiX+WHcavBIJAyTs/GSkAlEuDsM8GL5qTE7esMZOoKh3sgD/7/17HkLm/h3pKvA+ lotc8gvWaXzrmX4FVaSkjVdAhVNPd7O3NPBtMOaWLHGNvP1LUv07bTYKxSgrjSGq7hHw 5Bm+IFOj5q/ZD/rO6nFNqTWgkXtZzUoj1aneaXuJjCD1/xcwolcTb0VTmm8RpcAY0y40 iiFRj+A4Exz2Vl0MbJDpGXvXgtbTKEQVd4RtCIt0iLRWQuz5p7pCZ5kbht9eq8Ol8UTI 5r/QPBjqQncDytPm9sEhiytgDlD4jj1ZsVg8qbLFHBJ/VDbpkFDI0cQAKn9TfFtz5EPk t6xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=ajOpNyJd; 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 t1-20020a50d701000000b00551d1fffae2si1056123edi.664.2023.12.13.05.17.44; Wed, 13 Dec 2023 05:17:44 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=ajOpNyJd; 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 1268C68D264; Wed, 13 Dec 2023 15:15:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AABA168D1F3 for ; Wed, 13 Dec 2023 15:15:44 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 8F3C54BD27; Wed, 13 Dec 2023 14:15:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473341; bh=ZWyysk/LHs7fyKwe16KHz9FnxwWMlWLO57svolpyn4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ajOpNyJdbpbbRT+UT4iTCTDBmzChnd3+SSmmxS6ehrs2qCDrRmeYr7kDMrDieQbmp OcNOreeVee6zKDWDvf7kF4zTCxIn02HC85LDgqPiesChSL4wwfKCaqcCYl1on0+pXp 7HnRsFpsmnlCZnfc/rzT3WzBXtSUFE8lxf1W/WyQ= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:06 +0100 Message-ID: <20231213131536.10242-10-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 09/15] avfilter/vf_zscale: switch to 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +9g9lj/0FfZe From: Niklas Haas Following the same design as vf_scale. --- libavfilter/vf_zscale.c | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c index f76c9954cd..3b14ce4f33 100644 --- a/libavfilter/vf_zscale.c +++ b/libavfilter/vf_zscale.c @@ -187,8 +187,12 @@ static av_cold int init(AVFilterContext *ctx) return 0; } +static enum AVColorRange convert_range_from_zimg(enum zimg_pixel_range_e color_range); + static int query_formats(AVFilterContext *ctx) { + ZScaleContext *s = ctx->priv; + AVFilterFormats *formats; static const enum AVPixelFormat pixel_fmts[] = { AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, @@ -217,7 +221,27 @@ static int query_formats(AVFilterContext *ctx) ret = ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->inputs[0]->outcfg.formats); if (ret < 0) return ret; - return ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->outputs[0]->incfg.formats); + ret = ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->outputs[0]->incfg.formats); + if (ret < 0) + return ret; + + if ((ret = ff_formats_ref(ff_all_color_spaces(), &ctx->inputs[0]->outcfg.formats)) < 0 || + (ret = ff_formats_ref(ff_all_color_ranges(), &ctx->inputs[0]->outcfg.formats)) < 0) + return ret; + + formats = s->colorspace != ZIMG_MATRIX_UNSPECIFIED && s->colorspace > 0 + ? ff_make_formats_list_singleton(s->colorspace) + : ff_all_color_spaces(); + if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->incfg.formats)) < 0) + return ret; + + formats = s->range != -1 + ? ff_make_formats_list_singleton(convert_range_from_zimg(s->range)) + : ff_all_color_ranges(); + if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->incfg.formats)) < 0) + return ret; + + return 0; } static void slice_params(ZScaleContext *s, int out_h, int in_h) @@ -678,15 +702,9 @@ fail: static void update_output_color_information(ZScaleContext *s, AVFrame *frame) { - if (s->colorspace != -1) - frame->colorspace = (int)s->dst_format.matrix_coefficients; - if (s->primaries != -1) frame->color_primaries = (int)s->dst_format.color_primaries; - if (s->range != -1) - frame->color_range = convert_range_from_zimg(s->dst_format.pixel_range); - if (s->trc != -1) frame->color_trc = (int)s->dst_format.transfer_characteristics; @@ -775,6 +793,8 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) if ((link->format != outlink->format) || (link->w != outlink->w) || (link->h != outlink->h) || + (link->colorspace != outlink->colorspace) || + (link->color_range != outlink->color_range) || s->first_time || (s->src_format.chroma_location != s->dst_format.chroma_location) || (s->src_format.color_family !=s->dst_format.color_family) || @@ -796,6 +816,8 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) goto fail; av_frame_copy_props(out, in); + out->colorspace = outlink->colorspace; + out->color_range = outlink->color_range; if ((ret = realign_frame(desc, &in, 1)) < 0) goto fail; @@ -805,9 +827,11 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) snprintf(buf, sizeof(buf)-1, "%d", outlink->h); av_opt_set(s, "h", buf, 0); - link->dst->inputs[0]->format = in->format; - link->dst->inputs[0]->w = in->width; - link->dst->inputs[0]->h = in->height; + link->dst->inputs[0]->format = in->format; + link->dst->inputs[0]->w = in->width; + link->dst->inputs[0]->h = in->height; + link->dst->inputs[0]->colorspace = in->colorspace; + link->dst->inputs[0]->color_range = in->color_range; s->nb_threads = av_clip(FFMIN(ff_filter_get_nb_threads(ctx), FFMIN(link->h, outlink->h) / MIN_TILESIZE), 1, MAX_THREADS); slice_params(s, out->height, in->height); From patchwork Wed Dec 13 13:12:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45110 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4264535pzf; Wed, 13 Dec 2023 05:17:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJWJPz0BTApdLhybiAxhCbjYTCUggIRApLm7gkPs6vUdQOP5hA4mag8YEYjyi5FV7Aeb1N X-Received: by 2002:a17:906:10c6:b0:a1d:b779:46af with SMTP id v6-20020a17090610c600b00a1db77946afmr4105401ejv.11.1702473474341; Wed, 13 Dec 2023 05:17:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473474; cv=none; d=google.com; s=arc-20160816; b=HuZmFSwbeocEJCye6BWGmfpWbYA7ZuW5CxIHrrYnsOZ8mYYz/hmKsJ0QMUi3Pbqwvi PfmilaC6V6s8VpDXM9crEsoEgJUvD8/Y/FsK3QZKz6nfESLf2KyR5PcIOm8yeXj98Mzb 5p3BazFj4P6VgVBQkvUR0TlUl4TGinyHgtyglXvbJfY4NV4daVOchzVSTK3m9XAN1wan BocgB46vYcertAdIEkY1Dcv/n/pJ1Oqr5+LBy2/U0mIaB5hBUHXhza67bSeXLm8XWRSk YAs5KC85vzf+NRsvWuycshZ18lpUKK0DwR4UTJDuw1EAlQt9jja17z7F5QWGFM2scOVL lnCA== 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=Lkz9/M0CPLgemaeZ08AaI83s5XhRefpxin00C4/GPxA=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=NV6Vfzw7SNBNt4vDkq4WZD9c9nekMvr8Lp2d/c//bHsNuFKgH2hWTZ7Kv0CDpADGev SuU5LBUW0uNFKoOpKy/uFIQXhN3Lw2OPXcgwzF28OP6t7n8x3FH8qwYLoS4KW1UJ5Llb BDQoQXIxZYl638oCqCQiFKMs7tUS5OM7XfEXxDBe8B3eCrx8z6BaFZppzlV5xTmNgaBZ Kfo8C7x4AVTAEdHNzlqPH9fOmjqHa7or00jQTeBfWEiB10gfvf6d7LZPG9RUR6oFCSJE ngcj7JJaEvqQ6ciaYb6M8el9vOy3JHxsKjTQ8uwgZIhe6NUyTBMS3R9DQdxh4aEicK+M ydew== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=t69w+SlM; 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 y19-20020a170906559300b00a1d7d2dc490si5668711ejp.759.2023.12.13.05.17.53; Wed, 13 Dec 2023 05:17:54 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=t69w+SlM; 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 0971868D27F; Wed, 13 Dec 2023 15:16:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B522E68D1F8 for ; Wed, 13 Dec 2023 15:15:44 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id D0D734BD38; Wed, 13 Dec 2023 14:15:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473341; bh=Lhe+ImdwMnInsxKFKJ+uO7Kh2+yTN+vsnnzX8n2JUeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t69w+SlM7ZSD9fqI/bYJ2uIPMTt6ArhxgJ+9T5/JtmzYrFV05GRwJmxOH53dJk7GY QE/IxAtrSl7yJziyvFA+RGqcrjJt7SAFT1tyQSQ9xN7L3iC3nZ6Wa8aG+4T6deQ7Ha Cev5aVt6LBK1sDISLPzxQUXBQ2ywzQ0QK3OWkGA4= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:07 +0100 Message-ID: <20231213131536.10242-11-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 10/15] avfilter/vf_libplacebo: don't force dovi frames to bt.2020-ncl 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: RcH7tlaPrNNG From: Niklas Haas This is at odds with the YUV matrix negotiation API, in which such dynamic changes in YUV encoding are no longer easily possible. There is also no really strong motivating reason to do this, since the choice of YUV matrix is essentially arbitrary and not actually related to the Dolby Vision decoding process. --- libavfilter/vf_libplacebo.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 8534945ba6..b6e82a61e0 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -888,7 +888,6 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) if (s->apply_dovi && av_frame_get_side_data(ref, AV_FRAME_DATA_DOVI_METADATA)) { /* Output of dovi reshaping is always BT.2020+PQ, so infer the correct * output colorspace defaults */ - out->colorspace = AVCOL_SPC_BT2020_NCL; out->color_primaries = AVCOL_PRI_BT2020; out->color_trc = AVCOL_TRC_SMPTE2084; } From patchwork Wed Dec 13 13:12:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45112 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4264695pzf; Wed, 13 Dec 2023 05:18:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzDEW0jdyg1vLvx8d4h5sv6hpsb/y1Wxg+0+voDlvE1S2S0Ar7g0/FVqLEJ/18ac9lo7j6 X-Received: by 2002:a17:907:7d8c:b0:a1d:58ff:df2b with SMTP id oz12-20020a1709077d8c00b00a1d58ffdf2bmr4806866ejc.17.1702473491455; Wed, 13 Dec 2023 05:18:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473491; cv=none; d=google.com; s=arc-20160816; b=BAmqBi3njojYypLsFo9LRIcqUYRPQbRo15bCELkcQJtgFWr9MB0HxPdi3m5N+yb5Od 1nMJvDEbF+abhsq8l3elNJYmRAucOV9V9iKTJBt5RXTfqlPGGq8hcUiesBa6EwxSYkDf 1xSBbSmCWYOSNNRfoB1YPOWZ3uyzhun0n19J2+yPs7+xzyBGNHJvN3F+tF2HRBZiWahI kpewGEKSLz8m8DmEy3l91jnLh8jT/edlrt9bueqVbz3zQlNjBiBkVDb06mM0H9cG7BDT AAm1spiJcERzm7PoF2oUOX9C+ZzCk5T5CpUdsKqf2aRPRDyweJyVcscP6YChF/7Tker2 /ETw== 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=S0saI32HwvlAYWDTKIcHcmQY2yTTzyZ8gv2J35SXX7A=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=t8VHQK+rDGn5Phf8nTB+iA953C0iCMDZNyZKnaB+KSaRe2mW4tVrW+avPc8SNcyyu0 +tMUxJzdkpXYduGKcCma4XR9XqJPAvqx0Z9FTSbyWq/X8b8xJ9CL6XSIUwqcRBcmpWP/ O8PqeunBpk2u2lpAqKGLji50/J8X5AZmACE1bxywcg4pMLtvA5+Ae65g1N7luLruRlnn vKs/Xf0u3qSlsHFk2H2U5jTtNiNnyhwIXKOoXUmLzes+XI4HVB/U/pQoMdRMHzSyq9zg nu9MatwxGHR6MTGTq/bdmC+ne+jGS0ThR3NtXBn7uEsIqrkcTuxJK5uys/2CnmGY9h7d ECQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=ZfpkfVQw; 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 lj3-20020a170906f9c300b00a1cd7788572si4956509ejb.828.2023.12.13.05.18.10; Wed, 13 Dec 2023 05:18:11 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=ZfpkfVQw; 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 F2B7568D285; Wed, 13 Dec 2023 15:16:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 15B9068D1F8 for ; Wed, 13 Dec 2023 15:15:45 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 28CF34BD40; Wed, 13 Dec 2023 14:15:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473342; bh=wJVk4x8gnlNDgmcDNkgNESobmlOqX3LJbIWBYXPECEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZfpkfVQwCaSNYKuVzvvb9huCrxOOghm/pWZ1kUhWOTo/ln2yC5FZaLCHNXnOnJUQj KUfn8JM5axmfk8umEhkLJBe0HgD+unMdcb15jB/jdYKXLhbITg22Ac6Dn54DxXa4l5 N0kG1uFwKHHVazSj+U9+X3HU+WNted+kMXGJvzSI= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:08 +0100 Message-ID: <20231213131536.10242-12-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 11/15] avfilter/vf_libplacebo: switch to 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: hS2hlrp26y5m From: Niklas Haas --- libavfilter/vf_libplacebo.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index b6e82a61e0..a9a3d884ce 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -882,6 +882,8 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) out->pts = pts; out->width = outlink->w; out->height = outlink->h; + out->colorspace = outlink->colorspace; + out->color_range = outlink->color_range; if (s->fps.num) out->duration = 1; @@ -892,22 +894,11 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) out->color_trc = AVCOL_TRC_SMPTE2084; } - if (s->colorspace >= 0) - out->colorspace = s->colorspace; - if (s->color_range >= 0) - out->color_range = s->color_range; if (s->color_trc >= 0) out->color_trc = s->color_trc; if (s->color_primaries >= 0) out->color_primaries = s->color_primaries; - /* Sanity colorspace overrides */ - if (outdesc->flags & AV_PIX_FMT_FLAG_RGB) { - out->colorspace = AVCOL_SPC_RGB; - } else if (out->colorspace == AVCOL_SPC_RGB) { - out->colorspace = AVCOL_SPC_UNSPECIFIED; - } - changed_csp = ref->colorspace != out->colorspace || ref->color_range != out->color_range || ref->color_trc != out->color_trc || @@ -1203,6 +1194,18 @@ static int libplacebo_query_format(AVFilterContext *ctx) for (int i = 0; i < s->nb_inputs; i++) RET(ff_formats_ref(infmts, &ctx->inputs[i]->outcfg.formats)); RET(ff_formats_ref(outfmts, &ctx->outputs[0]->incfg.formats)); + + /* Set colorspace properties */ + RET(ff_formats_ref(ff_all_color_spaces(), &ctx->inputs[0]->outcfg.color_spaces)); + RET(ff_formats_ref(ff_all_color_ranges(), &ctx->inputs[0]->outcfg.color_ranges)); + + outfmts = s->colorspace > 0 ? ff_make_formats_list_singleton(s->colorspace) + : ff_all_color_spaces(); + RET(ff_formats_ref(outfmts, &ctx->outputs[0]->incfg.color_spaces)); + + outfmts = s->color_range > 0 ? ff_make_formats_list_singleton(s->color_range) + : ff_all_color_ranges(); + RET(ff_formats_ref(outfmts, &ctx->outputs[0]->incfg.color_ranges)); return 0; fail: From patchwork Wed Dec 13 13:12:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45111 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4264606pzf; Wed, 13 Dec 2023 05:18:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnKRZ/V/EkB5miJRsi3uNx4jrTLLwF85aMDKZssF9wcC6OHhoqvY4qnXPSMJSAt8VTU816 X-Received: by 2002:a19:a404:0:b0:50b:f9bf:66de with SMTP id q4-20020a19a404000000b0050bf9bf66demr3594448lfc.36.1702473482881; Wed, 13 Dec 2023 05:18:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473482; cv=none; d=google.com; s=arc-20160816; b=JIp8AmyKF44UclTIazPODpSSzb91hejmI02K2q+DmFIyzIwcBQIuSra7NM4B9UhYS6 HdpUcloQ4ZUSd79DBgE7bLJxDovb3OwlFIZkfNzpKs65W/p63T7U/QIIm2/Sc/JuI6ah hx5NzZBHLe1bNlYOmDj+y6blpUiql7kQIdruGIMTup3ryF+vx/qeYnOCKEw3f4Cyf1Xl PED3eEilzL/Fd44kaExhAG41pO8Hb5HbmGP5N0j8SmpWmZnsclgGU4tXB26czyJnrCY8 1NkHIfR7nlLT67+WEIG6E0QLPERpEhgU//tMHw9AkFBrrHylX3Nb13X1jXi82q1Rzu+7 S01A== 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=WSi09+yeEY0k2cGpZMBGaPF8Bdzd1s2fkrYgsnJoPrE=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=iP+1Wyqyv2pTJL64VUxeY9fQWujj9t2kB0SoA7ngpyFd8vcgFaw/OOSW5LteiKOyQs S7YVaEMXHbDvVFh/waild7EGIqviCQ8mqidf34AVXRddhdg/DO1w2ByVvZ+KnMHS8Yip PI5fxCmJpIfdcpzbwZW2p6MD2S1lNeKXcOoAIWgiBaw+kVU8tVy/hPXDR2poo3/+TRZt m21GF2R4DDDi9Z83M+MdvLnaepxErCV9QUtVnK1rnCBycmXyhP/V8lPIf9D3DzdToel3 rSZ8jSKXPIOYKWTbgnOJRtRnB/wD4nLSJ5hhodg9hsojM7hB2komHndOGzGywf/CoN09 YgFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Y2Z7w+Kj; 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 z11-20020a1709067e4b00b00a1b7769f832si5625996ejr.614.2023.12.13.05.18.02; Wed, 13 Dec 2023 05:18:02 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=Y2Z7w+Kj; 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 06F9468D032; Wed, 13 Dec 2023 15:16:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0DA0068D1F3 for ; Wed, 13 Dec 2023 15:15:45 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 7C7514BD47; Wed, 13 Dec 2023 14:15:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473342; bh=O4YG7kRTn7L6E4rHeK7afoWuwMrv40EuRsuAv/4L4lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y2Z7w+Kj4ERIZitek+Fqkq2nCmD0OhVa//wwa5cs1h6XmRacKAEnUoKjIFoloiUw4 NOY2rzDl7jwP0RoUGIO9WoxITgczfE/51ZnVituikmeDHbFDaZpI4btaqWkS0+RHJU PFid948i+Zj/3vBlAYRtzJyJQ8zuks6pi25DedPE= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:09 +0100 Message-ID: <20231213131536.10242-13-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 12/15] avfilter/buffersink: add color space/range accessors 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /Zsgsa29Ii24 From: Niklas Haas Needed for fftools. --- doc/APIchanges | 3 +++ libavfilter/buffersink.c | 2 ++ libavfilter/buffersink.h | 2 ++ libavfilter/version.h | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 2f6ea50f63..578c2c4641 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-11-xx - xxxxxxxxxx - lavf 58.15.100 - buffersink.h + Add av_buffersink_get_colorspace and av_buffersink_get_color_range. + 2023-11-xx - xxxxxxxxxx - lavf 58.14.100 - avfilter.h Add AVFilterLink.colorspace, AVFilterLink.color_range diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 3da3331159..6ba2970dd5 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -209,6 +209,8 @@ MAKE_AVFILTERLINK_ACCESSOR(AVRational , frame_rate ) MAKE_AVFILTERLINK_ACCESSOR(int , w ) MAKE_AVFILTERLINK_ACCESSOR(int , h ) MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio) +MAKE_AVFILTERLINK_ACCESSOR(enum AVColorSpace, colorspace) +MAKE_AVFILTERLINK_ACCESSOR(enum AVColorRange, color_range) #if FF_API_OLD_CHANNEL_LAYOUT FF_DISABLE_DEPRECATION_WARNINGS diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index 64e08de53e..a9374b8b4f 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -117,6 +117,8 @@ AVRational av_buffersink_get_frame_rate (const AVFilterContext *c int av_buffersink_get_w (const AVFilterContext *ctx); int av_buffersink_get_h (const AVFilterContext *ctx); AVRational av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx); +enum AVColorSpace av_buffersink_get_colorspace (const AVFilterContext *ctx); +enum AVColorRange av_buffersink_get_color_range (const AVFilterContext *ctx); int av_buffersink_get_channels (const AVFilterContext *ctx); #if FF_API_OLD_CHANNEL_LAYOUT diff --git a/libavfilter/version.h b/libavfilter/version.h index 7642b670d1..59330858bd 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -31,7 +31,7 @@ #include "version_major.h" -#define LIBAVFILTER_VERSION_MINOR 14 +#define LIBAVFILTER_VERSION_MINOR 15 #define LIBAVFILTER_VERSION_MICRO 100 From patchwork Wed Dec 13 13:12:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45103 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4263853pzf; Wed, 13 Dec 2023 05:16:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNLimatyXUjhpMqX1sm8hbdy71zn0PUGwyyHmKrM9h/H/eRrQid/GKMkGy1vgfVyPWJG5l X-Received: by 2002:a17:907:c312:b0:a01:ae7b:d19b with SMTP id tl18-20020a170907c31200b00a01ae7bd19bmr9388469ejc.7.1702473408004; Wed, 13 Dec 2023 05:16:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473407; cv=none; d=google.com; s=arc-20160816; b=ApW8GegTnKrqAnzmzJ8NzuiKoVMNWIdzFqUc744fMe5eoHDkTjDHiQnAmkDKQWSu1m /1xo5ONPiPSfzvah4ic5wZDOdYgHW2bH/yvbNoGpyFZwODPPaDgzNJUc3HaC3+8tvZPB MavNe7M0833MG8oYG2A2ANirTwUIJMQ0bVcXrpf//txdEr3hpRZRnRWqLi214DsKTnaw Of06v3sPybkPbHB/fVx82y9DfZOi4RRIdlYrNZxVkoTQ32YkxLEOkjc9lYfsy1B/SLQG OSs0v64XaORksxfoIoQGQmTFstP+W2loBgx4d86t3u4ihvTD3H/PY2NimJNLLCjHLOC7 /0dQ== 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=uRxwznLNbSEs6izUhIUzwBVJDdcxyboyueBFe8Q34PM=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=OeWgUZCt8o2w/0MLnLcm8RAGBC15R2K7tsSmiHLR4aCYx0knKl4yKvCPcDezIrgqIk rtb91xkgLIwM9vbJwVxwe+3N0gjxit5TOR79h7MEZiBwFpBitIRtg4U5wRvomkb5QUeh b9T/HZq4VtdvRj7FDsDb5OpRSdalP1DwdQttMhfL+UaZ1sXY7FpHqF81WhQH5B9H5EMg TVwITY3ipJ96jojMaCRimP+HcIKcRsIc4rNtFxTTZCdaFT55eQP0BFF23DPXcW6VAlkC BtOBo01MqqMoz/t5v5sHMxxnMfQI3aqgTxiD/3aB5tIevD1Bps2X9Uym7k6qubr06MVC Yy7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Emo3+cmk; 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 m7-20020a170906234700b00a1f673b5eb5si4943966eja.784.2023.12.13.05.16.47; Wed, 13 Dec 2023 05:16:47 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=Emo3+cmk; 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 D01EF68D1DD; Wed, 13 Dec 2023 15:15:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 51B7468D15F for ; Wed, 13 Dec 2023 15:15:45 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id C84034BD4A; Wed, 13 Dec 2023 14:15:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473342; bh=ngZwxPipoD6o9iWOx9WY5GaYJvmLQ3OjQGlZ5Gv5onE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Emo3+cmkXWNC6ErkdSUMV0dCz86u+SU/DwHw54cm0RbCgxsiPYf2cwbZvqpdYoorL 65Rsq6ccrKFZYybceYJqWPslUIZKUHiEuKuCJeanQTh+SaHXpMFIM+EweWJiQV6sfN GThIB1wkwu/RGHJZpEr84oWch3wpstTLojRS7TP0= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:10 +0100 Message-ID: <20231213131536.10242-14-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 13/15] avfilter/vf_format: re-use AVFilterFormats for pix_fmt parsing 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4bi/61jLs5et From: Niklas Haas Rewrite the format parsing code to make it more easily generalizable. In particular, `invert_formats` does not depend on the type of format list passed to it, which allows me to re-use this helper in an upcoming commit. Slightly shortens the code, at the sole cost of doing several malloc (ff_add_format) instead of a single malloc. --- libavfilter/vf_format.c | 103 +++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 60 deletions(-) diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c index 1189bd61c2..59832b7768 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -41,25 +41,48 @@ typedef struct FormatContext { const AVClass *class; char *pix_fmts; - /** - * pix_fmts parsed into AVPixelFormats and terminated with - * AV_PIX_FMT_NONE - */ - enum AVPixelFormat *formats; + AVFilterFormats *formats; ///< parsed from `pix_fmts` } FormatContext; static av_cold void uninit(AVFilterContext *ctx) { FormatContext *s = ctx->priv; - av_freep(&s->formats); + ff_formats_unref(&s->formats); +} + +static av_cold int invert_formats(AVFilterFormats **fmts, + AVFilterFormats *allfmts) +{ + if (!allfmts) + return AVERROR(ENOMEM); + if (!*fmts) { + /* empty fmt list means no restriction, regardless of filter type */ + ff_formats_unref(&allfmts); + return 0; + } + + for (int i = 0; i < allfmts->nb_formats; i++) { + for (int j = 0; j < (*fmts)->nb_formats; j++) { + if (allfmts->formats[i] == (*fmts)->formats[j]) { + /* format is forbidden, remove it from allfmts list */ + memmove(&allfmts->formats[i], &allfmts->formats[i+1], + (allfmts->nb_formats - (i+1)) * sizeof(*allfmts->formats)); + allfmts->nb_formats--; + i--; /* repeat loop with same idx */ + break; + } + } + } + + ff_formats_unref(fmts); + *fmts = allfmts; + return 0; } static av_cold int init(AVFilterContext *ctx) { FormatContext *s = ctx->priv; - char *cur, *sep; - int nb_formats = 1; - int i; + enum AVPixelFormat pix_fmt; int ret; if (!s->pix_fmts) { @@ -67,64 +90,24 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); } - /* count the formats */ - cur = s->pix_fmts; - while ((cur = strchr(cur, '|'))) { - nb_formats++; - if (*cur) - cur++; - } - - s->formats = av_malloc_array(nb_formats + 1, sizeof(*s->formats)); - if (!s->formats) - return AVERROR(ENOMEM); - - /* parse the list of formats */ - cur = s->pix_fmts; - for (i = 0; i < nb_formats; i++) { + for (char *sep, *cur = s->pix_fmts; cur; cur = sep) { sep = strchr(cur, '|'); - if (sep) + if (sep && *sep) *sep++ = 0; - - if ((ret = ff_parse_pixel_format(&s->formats[i], cur, ctx)) < 0) + if ((ret = ff_parse_pixel_format(&pix_fmt, cur, ctx)) < 0 || + (ret = ff_add_format(&s->formats, pix_fmt)) < 0) return ret; - - cur = sep; } - s->formats[nb_formats] = AV_PIX_FMT_NONE; if (!strcmp(ctx->filter->name, "noformat")) { - const AVPixFmtDescriptor *desc = NULL; - enum AVPixelFormat *formats_allowed; - int nb_formats_lavu = 0, nb_formats_allowed = 0; - - /* count the formats known to lavu */ - while ((desc = av_pix_fmt_desc_next(desc))) - nb_formats_lavu++; - - formats_allowed = av_malloc_array(nb_formats_lavu + 1, sizeof(*formats_allowed)); - if (!formats_allowed) - return AVERROR(ENOMEM); - - /* for each format known to lavu, check if it's in the list of - * forbidden formats */ - while ((desc = av_pix_fmt_desc_next(desc))) { - enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(desc); - - for (i = 0; i < nb_formats; i++) { - if (s->formats[i] == pix_fmt) - break; - } - if (i < nb_formats) - continue; - - formats_allowed[nb_formats_allowed++] = pix_fmt; - } - formats_allowed[nb_formats_allowed] = AV_PIX_FMT_NONE; - av_freep(&s->formats); - s->formats = formats_allowed; + if ((ret = invert_formats(&s->formats, ff_all_formats(AVMEDIA_TYPE_VIDEO))) < 0) + return ret; } + /* hold on to a ref for the lifetime of the filter */ + if ((ret = ff_formats_ref(s->formats, &s->formats)) < 0) + return ret; + return 0; } @@ -132,7 +115,7 @@ static int query_formats(AVFilterContext *ctx) { FormatContext *s = ctx->priv; - return ff_set_common_formats_from_list(ctx, s->formats); + return ff_set_common_formats(ctx, s->formats); } From patchwork Wed Dec 13 13:12:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45102 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4263742pzf; Wed, 13 Dec 2023 05:16:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IH33iyXFtWSwEsKx+jjUD5il2FYB0PCBQiERQLxohEz/ZVzta5mHYIccwKkikTkznUoVtuS X-Received: by 2002:a2e:a49c:0:b0:2cc:202f:9757 with SMTP id h28-20020a2ea49c000000b002cc202f9757mr2386574lji.54.1702473398660; Wed, 13 Dec 2023 05:16:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473398; cv=none; d=google.com; s=arc-20160816; b=qBUNg/8O0WpJvSjVC+Trh1VQdEq/RrwY/xJU3cqUXT08rKyYLkj3N+byLqIL97b8aO 2RK03jG9Qqoha8maJTKD4GSS5jkKij7FgmxaAefSJxH1SG/b9TfPX9c8nI3G8uMTbxye e1ngr9DhuNFAhj79d3KyBE8mbir186Ent/nrJWrqjJouXTMOZHvXbmwhUC4o96QQQjAy S6RkMVnIEF6/uqixQKRabd5VXOZEGR4Jj3IyG/hG0thS1dxfoZOEh1VM0o4CVVlNdavM +OeBv1jiyOYknsSIaWWp7GYvzGkOTSUm1s9eGWVeWTY4mtTlr4SCW/ZLhFQTjPbfAyx5 t0Dw== 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=zlziIFH89cE4FRy3xUO+GbdBljI1vub5S90PfQnJ3MU=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=oTObxp9+Xskfc6u3qdETLaXap2os/AWyqfpYT8qbTYfnNY4SaGdbY9xERlXU6nlmfV 6Fvf+voPV+l0GRDipuI3SWADm10GSVR0ORP3hvYJmrv6CeTNCOr52S9JOjpcs8iCX9nS NSJdE3fy+LrKVDyH1tsij+IUNXBJKpKkndq35lHhB6Vq3EwfhLFCo5NrW/OPTDNrJqwX EtdGv3C2kXRu0CXck2xgkDeJAHQZsWoRFau5XXpws70kQbyBCKdU5/JQBKCgbrlfJPv+ qA1UAHH/frIbTXQugf15p+hUmBW23rQUXXwJS85ukpb+tj9FOsHPgqSPf3LjTFWtZJ1v d7gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Rgw22EKr; 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 b98-20020a509f6b000000b00551d07ecb07si1041583edf.222.2023.12.13.05.16.38; Wed, 13 Dec 2023 05:16:38 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=Rgw22EKr; 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 9E68F68D21E; Wed, 13 Dec 2023 15:15:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4A13468D032 for ; Wed, 13 Dec 2023 15:15:45 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 341ED4BD4D; Wed, 13 Dec 2023 14:15:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473343; bh=MHso3/zJH94N9jYAAMyxaP+sDjuwzk52IqZDsrR81r8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rgw22EKrDp6nlX+fgFhHN0lks1IdA8jQZxUgQ9jV/4B0Ptxdub233KLk05edaNu6k qBMi0y2Nua2er8zd+1r3cI4SmZWiUyY3eWriC0cnBiQIZwzIAm+d3o6e/XhqRPTx/D 0CvkqRXa+Mh4JA3xcfZ+As8GyBr+SstGIWk5Jl1Y= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:11 +0100 Message-ID: <20231213131536.10242-15-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 14/15] avfilter/vf_format: add color_ranges/spaces 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: fgoQtWNKvTA6 From: Niklas Haas Needed for fftools/ffmpeg_filter to be able to force specific output formats via the filter chain. --- doc/filters.texi | 8 ++++++++ libavfilter/vf_format.c | 42 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index f182dc2ddb..4be4dbf270 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -14323,6 +14323,14 @@ It accepts the following parameters: A '|'-separated list of pixel format names, such as "pix_fmts=yuv420p|monow|rgb24". +@item color_spaces +A '|'-separated list of color space names, such as +"color_spaces=bt709|bt470bg|bt2020nc". + +@item color_ranges +A '|'-separated list of color range names, such as +"color_spaces=tv|pc". + @end table @subsection Examples diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c index 59832b7768..d1bb9daa97 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -40,14 +40,20 @@ typedef struct FormatContext { const AVClass *class; char *pix_fmts; + char *csps; + char *ranges; AVFilterFormats *formats; ///< parsed from `pix_fmts` + AVFilterFormats *color_spaces; ///< parsed from `csps` + AVFilterFormats *color_ranges; ///< parsed from `ranges` } FormatContext; static av_cold void uninit(AVFilterContext *ctx) { FormatContext *s = ctx->priv; ff_formats_unref(&s->formats); + ff_formats_unref(&s->color_spaces); + ff_formats_unref(&s->color_ranges); } static av_cold int invert_formats(AVFilterFormats **fmts, @@ -99,13 +105,35 @@ static av_cold int init(AVFilterContext *ctx) return ret; } + for (char *sep, *cur = s->csps; cur; cur = sep) { + sep = strchr(cur, '|'); + if (sep && *sep) + *sep++ = 0; + if ((ret = av_color_space_from_name(cur)) < 0 || + (ret = ff_add_format(&s->color_spaces, ret)) < 0) + return ret; + } + + for (char *sep, *cur = s->ranges; cur; cur = sep) { + sep = strchr(cur, '|'); + if (sep && *sep) + *sep++ = 0; + if ((ret = av_color_range_from_name(cur)) < 0 || + (ret = ff_add_format(&s->color_ranges, ret)) < 0) + return ret; + } + if (!strcmp(ctx->filter->name, "noformat")) { - if ((ret = invert_formats(&s->formats, ff_all_formats(AVMEDIA_TYPE_VIDEO))) < 0) + if ((ret = invert_formats(&s->formats, ff_all_formats(AVMEDIA_TYPE_VIDEO))) < 0 || + (ret = invert_formats(&s->color_spaces, ff_all_color_spaces())) < 0 || + (ret = invert_formats(&s->color_ranges, ff_all_color_ranges())) < 0) return ret; } /* hold on to a ref for the lifetime of the filter */ - if ((ret = ff_formats_ref(s->formats, &s->formats)) < 0) + if ((ret = ff_formats_ref(s->formats, &s->formats)) < 0 || + s->color_spaces && (ret = ff_formats_ref(s->color_spaces, &s->color_spaces)) < 0 || + s->color_ranges && (ret = ff_formats_ref(s->color_ranges, &s->color_ranges)) < 0) return ret; return 0; @@ -114,14 +142,22 @@ static av_cold int init(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx) { FormatContext *s = ctx->priv; + int ret; + + if ((ret = ff_set_common_formats(ctx, s->formats)) < 0 || + s->color_spaces && (ret = ff_set_common_color_spaces(ctx, s->color_spaces)) < 0 || + s->color_ranges && (ret = ff_set_common_color_ranges(ctx, s->color_ranges)) < 0) + return ret; - return ff_set_common_formats(ctx, s->formats); + return 0; } #define OFFSET(x) offsetof(FormatContext, x) static const AVOption options[] = { { "pix_fmts", "A '|'-separated list of pixel formats", OFFSET(pix_fmts), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM }, + { "color_spaces", "A '|'-separated list of color spaces", OFFSET(csps), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM }, + { "color_ranges", "A '|'-separated list of color ranges", OFFSET(ranges), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM }, { NULL } }; From patchwork Wed Dec 13 13:12:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45104 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4263952pzf; Wed, 13 Dec 2023 05:16:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxNUFjwKbUUON+K54EByM7Grw7HAyuOfdgYTC8fDAM1rAjfBLvNzCFyrvFt2425d/TzDt6 X-Received: by 2002:a17:906:1083:b0:a19:a19b:5608 with SMTP id u3-20020a170906108300b00a19a19b5608mr4185106eju.152.1702473418616; Wed, 13 Dec 2023 05:16:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473418; cv=none; d=google.com; s=arc-20160816; b=MzEr4RpYs//I2N0ICDxgyLOx57+bMj2uNgiOZJJyvcxrfwChkV2lkW5NwAZlc9OAZw Zylis+AvfoM2AFDi1w0ftridCARekHXfuy0p+M5xVLcht3sN3+8ZMY1Mc1XDs63Tu4Xs PbXZ4j3lqee2FgyFjP26GgJjI5E1r+XgwHMei38Wn0poyJN/9Tzg52lBC6CPp88jHKQ9 PBvM4e7uX8cywyXTY/FmcqcBfYv3nkybKTfkCrmTwYzQ8civiikY/c5Q3wQ0sMdlMxPK gvbR9xc4kjKAuEvlwS4ZgtIryAO20oOWqk/yjgBt+ydmM36hB0XNoz+wRXZfYPuKCI8l POgA== 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=PIJf1WphmT1np+7piGH4qziOpBGRlzaBcLr8d4xQAYc=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=m6ZIeKcrQG2uTTPEPFEDSN8Y/uFfwMf7+4Fgnwe6+e8Z23JZsc5x346LMYPWW/cnym oTw018E407z+TdzLZntF+8o6Rm4nCFbFOAKHEOsxYPSTY9eBv6Qh3vPkSP2Ojb4vitTF 013RkjvHdpaTK+ZIMoCWUVUoUL4B/uebQSdzitKm7fXg6+EwpLEEfsiZk5KTecCcfk2V iD/lNK0ZD849pnLlFAsMXm0REdvYr1Lcf47kYgLestOoc90+SDUP8uX6K1nOmkJ+vSgS 9ciqjXjbQiGmLYCIlVkphYZynikN7AtY6b90UveF7IXXjKI145gnveMXmmvYs9IEPJXJ 56+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Aa7UsMng; 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 h14-20020a170906110e00b00a1d9d1e09f1si5475491eja.214.2023.12.13.05.16.56; Wed, 13 Dec 2023 05:16:58 -0800 (PST) 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=@haasn.xyz header.s=mail header.b=Aa7UsMng; 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 EBB4068D20F; Wed, 13 Dec 2023 15:15:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6399C68D15D for ; Wed, 13 Dec 2023 15:15:45 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 8C65D4BD4E; Wed, 13 Dec 2023 14:15:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473343; bh=qaCUdr5buc4kX5IRj+lzXx8mSumZsYx6RYwzMJNLDIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Aa7UsMngMLM5XdwB8NGvH0T1vv+cnr3fPRed4FTCeOeiYOA0eGaRak8vNDfNhE0SH dqxeDMTFBEdZYzyK0wztLVwieIMMpvsZf8tnp+piMIo0+x3TbwE/8JFoqD/GtSrZB9 1lA/Ggp+BZpshkKP0laO4tPKauO5QywAXn3kBKhQ= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:12:12 +0100 Message-ID: <20231213131536.10242-16-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 15/15] avfilter/vf_format: allow empty pix_fmts list 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: xaOyiAU26Grl From: Niklas Haas Which will impose no restriction. This makes sense when using e.g. `color_ranges=pc` to limit the color range, without also limiting the pixel format. --- libavfilter/vf_format.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c index d1bb9daa97..3a353bbb0d 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -91,11 +91,6 @@ static av_cold int init(AVFilterContext *ctx) enum AVPixelFormat pix_fmt; int ret; - if (!s->pix_fmts) { - av_log(ctx, AV_LOG_ERROR, "Empty output format string.\n"); - return AVERROR(EINVAL); - } - for (char *sep, *cur = s->pix_fmts; cur; cur = sep) { sep = strchr(cur, '|'); if (sep && *sep) @@ -131,7 +126,7 @@ static av_cold int init(AVFilterContext *ctx) } /* hold on to a ref for the lifetime of the filter */ - if ((ret = ff_formats_ref(s->formats, &s->formats)) < 0 || + if (s->formats && (ret = ff_formats_ref(s->formats, &s->formats)) < 0 || s->color_spaces && (ret = ff_formats_ref(s->color_spaces, &s->color_spaces)) < 0 || s->color_ranges && (ret = ff_formats_ref(s->color_ranges, &s->color_ranges)) < 0) return ret; @@ -144,7 +139,7 @@ static int query_formats(AVFilterContext *ctx) FormatContext *s = ctx->priv; int ret; - if ((ret = ff_set_common_formats(ctx, s->formats)) < 0 || + if (s->formats && (ret = ff_set_common_formats(ctx, s->formats)) < 0 || s->color_spaces && (ret = ff_set_common_color_spaces(ctx, s->color_spaces)) < 0 || s->color_ranges && (ret = ff_set_common_color_ranges(ctx, s->color_ranges)) < 0) return ret;