From patchwork Sat Aug 7 10:15:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linjie Fu X-Patchwork-Id: 29334 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp1249923ioh; Sat, 7 Aug 2021 03:16:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK4fkdFU/zBW5PkXx/NM/ZM/NwgQt/ez+GHu0t0mnS+8NM+3b2l87pvU9JYheNME8plIo1 X-Received: by 2002:a17:906:76c1:: with SMTP id q1mr14338003ejn.156.1628331375539; Sat, 07 Aug 2021 03:16:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628331375; cv=none; d=google.com; s=arc-20160816; b=eVe5lYppYLkkrFF2PaLOPuM5HxEEkCYaMSYCXEwS6Hhpo0G5ZmufB7JtB8mhN5B+a6 lMJNN0C2g3nDn4JMft6eoupRufhDZWTV/PRjhrrvdGppIdsdIUZS9VBs4TcLrgHXlQPT JZa16t9OB3Fl2jcTQByfS0kMYCsdYLUG7wQV0Fubgt+UY+tGZ9dA70RQb5aGnc6zSXg9 ij/ysi9ad3JQli9iJbByS6DS1Tg7f5peZKEshAeOjCXN2C/G907lqN1hCR2Ob1GwPKIT yeMnaDIOklT8wcGCX4OkF9K7cNIl6JbUCl1uGNHyCTpq2l771mvh65CDJ593Npo+Xm6W rZ1w== 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:delivered-to; bh=42spVipcOiBbmsb30SDmrcw0zGTnNUWAPrRhIJSwkD4=; b=Mpl8XyJiACqZ8KUfrJu4azCTXnaXLUKg0aYZSrC5qVzcUkYBBsqCN5gcGMXT7UHAbh HUZnv3/zUEkbiinSNkKm3HQi52HYZbxoKVcg6b8CEeXMOmMy33a4qK29d2efxMQHNG/Z jeGJ+y53+yPZDHcIqxQl7oyu79o9LH8igv+jzv9y3NymCfI7+w9eV0ev6snBmu7vScYs 1frNRQ+IIQUQJa5LiKTgYz7FDk8rp/NcdlMFmIHo+9HxXg+xC3nRmY9r4WRE457j4Y4w tE16S0wfValUSAj3Fem/KLom4KMSbDqantl4wtSwTDQOTlaPSdFKqMqfY1+9RkA1bo5x Kpeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id nb19si8974639ejc.45.2021.08.07.03.16.15; Sat, 07 Aug 2021 03:16:15 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 186AC68A101; Sat, 7 Aug 2021 13:16:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from zg8tmty1ljiyny4xntqumjca.icoremail.net (zg8tmty1ljiyny4xntqumjca.icoremail.net [165.227.154.27]) by ffbox0-bg.mplayerhq.hu (Postfix) with SMTP id E8DFE68A126 for ; Sat, 7 Aug 2021 13:15:56 +0300 (EEST) Received: from localhost.localdomain (unknown [58.247.209.118]) by mail-app3 (Coremail) with SMTP id cC_KCgCXP6RHXQ5hESe8Ag--.117S4; Sat, 07 Aug 2021 18:15:52 +0800 (CST) From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Sat, 7 Aug 2021 18:15:07 +0800 Message-Id: <20210807101507.83161-3-fulinjie@zju.edu.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807101507.83161-1-fulinjie@zju.edu.cn> References: <20210807101507.83161-1-fulinjie@zju.edu.cn> MIME-Version: 1.0 X-CM-TRANSID: cC_KCgCXP6RHXQ5hESe8Ag--.117S4 X-Coremail-Antispam: 1UD129KBjvJXoWxCw45Jr1fKr4rCF45ur17Jrb_yoW5CF48p3 WfCa4rJF17KF1fCwn2v3W8XF4YgryrGryFvrW8Kr9FqFs8Jr92y393Cry5uw1xJ3WUCrs7 Ja15ta4UCwnrKr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Eb7Iv0xC_Zr1lb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI 8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_Jrv_JF4l8cAvFVAK0II2c7xJM28CjxkF 64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcV CY1x0267AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY 1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4 xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCa FVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8twCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k2 6cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxV AFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8Dku7UUUUU== X-CM-SenderInfo: ysrvjiarsuq6lmxovvfxof0/ Subject: [FFmpeg-devel] [PATCH 3/3] libavfilter/graphparser: Add scale_sws_opts parse support in avfilter_graph_parse2 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: Linjie Fu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3Z+iYRXxkna2 From: Linjie Fu To pass the swscale options for the inserted scalers. ffmpeg -i input.mp4 -filter_complex \ "scale_sws_opts=alphablend=checkerboard;format=nv12" \ -t 0.5 output.mp4 Update docs. Signed-off-by: Linjie Fu --- doc/filters.texi | 7 ++++--- libavfilter/graphparser.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 790d165433..dbbb3a6940 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -204,9 +204,9 @@ pads must be connected. A filtergraph is considered valid if all the filter input and output pads of all the filterchains are connected. Libavfilter will automatically insert @ref{scale} filters where format -conversion is required. It is possible to specify swscale flags -for those automatically inserted scalers by prepending -@code{sws_flags=@var{flags};} +conversion is required. It is possible to specify swscale flags or +scale_sws_opts for those automatically inserted scalers by prepending +@code{sws_flags=@var{flags};} or @code{scale_sws_opts=@var{scale_sws_opts};} to the filtergraph description. Here is a BNF description of the filtergraph syntax: @@ -219,6 +219,7 @@ Here is a BNF description of the filtergraph syntax: @var{FILTER} ::= [@var{LINKLABELS}] @var{FILTER_NAME} ["=" @var{FILTER_ARGUMENTS}] [@var{LINKLABELS}] @var{FILTERCHAIN} ::= @var{FILTER} [,@var{FILTERCHAIN}] @var{FILTERGRAPH} ::= [sws_flags=@var{flags};] @var{FILTERCHAIN} [;@var{FILTERGRAPH}] +@var{FILTERGRAPH} ::= [scale_sws_opts=@var{opts};] @var{FILTERCHAIN} [;@var{FILTERGRAPH}] @end example @anchor{filtergraph escaping} diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index 1385c3ae71..8c63d6454e 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -415,6 +415,30 @@ static int parse_sws_flags(const char **buf, AVFilterGraph *graph) return 0; } +static int parse_scale_sws_opts(const char **buf, AVFilterGraph *graph) +{ + char *p = strchr(*buf, ';'); + + if (strncmp(*buf, "scale_sws_opts=", 15)) { + return 0; + } + + if (!p) { + av_log(graph, AV_LOG_ERROR, "scale_sws_opts not terminated with ';'.\n"); + return AVERROR(EINVAL); + } + + *buf += 15; + + av_freep(&graph->scale_sws_opts); + if (!(graph->scale_sws_opts = av_mallocz(p - *buf + 1))) + return AVERROR(ENOMEM); + av_strlcpy(graph->scale_sws_opts, *buf, p - *buf + 1); + + *buf = p + 1; + return 0; +} + int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs) @@ -429,6 +453,9 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, if ((ret = parse_sws_flags(&filters, graph)) < 0) goto fail; + if ((ret = parse_scale_sws_opts(&filters, graph)) < 0) + goto fail; + do { AVFilterContext *filter; filters += strspn(filters, WHITESPACES);