From patchwork Sun Jan 8 12:58:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39923 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp2423656pzb; Sun, 8 Jan 2023 04:59:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXu7bSKT9XgWG2ALCjw1+2m+Pn5FXJ9BPeEBjjx3GfpHSjD1XqARExB1j+KdproN92v1K6t1 X-Received: by 2002:a17:907:6f18:b0:837:3ed3:9c2b with SMTP id sy24-20020a1709076f1800b008373ed39c2bmr58763098ejc.5.1673182788691; Sun, 08 Jan 2023 04:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673182788; cv=none; d=google.com; s=arc-20160816; b=tPpbGcoDt4Na6mOb1hdApbLBs/681lMgyK/ccgw6vGtSeVEUD2FdYCIfculFCLLoR4 707egPBYc7m93kJAeRQiL/oKedcqkz3JfasKSaohriRMqzvJ82/aUQJ4ghtgfHpMOcgi XFSlzwkqhlXTs2qQVKKw6je4e5L0sOi0CNj3aCy7fbHfdr2cpFEY0BEl4VAqEo6URSKa 0jSPx16UhsyfJpZ10qp65DWgdii7zj17gk+z6lgDLoHRXwctJ0Un62B75ANmhIXRCIiq wUxg0WtJj3ZW/HilwJGUW0PPR7ADMsveyMHSr1cusTKxt+6WnDwSHgDvIbrNXkqXEWWj 1kZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=fU5uxLAkw/K0hqfOqT2TBxpqsKagL/3vG7716DaP5Kc=; b=uS0kMyMORVhc2gQsyLnVJ5ebQ2K1E9uifJsk6DkiUQvPNbF736u2yFXgGo1sLMogPH kNF+n3MEpDSMrBNt81nWTkIVf8UWUBeNMXBFMOAjLbg1eFb7CLu9ZjjqbXcRZ2btglZg 8VEfX8axCyKtT5LsgtccTqd5MVY1E3tGoOck6fC0ySBXdB8yoBy3wXaolfFpkc6epVr3 0mh+FxWlKeuNTnopz1S4oQDqIwun2tRDU8JPnrciFj7x4n7BQnQvuFZ+7hWdG06Js6Pa oTGj2Lk8CMIazirYYyjLGj/hsBxClnIDDKvplDjd/ueit0slr57rqJb/PxlhTBSJ9q5y h8EA== 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 wt2-20020a170906ee8200b0084d3a7b6a04si2810690ejb.576.2023.01.08.04.59.48; Sun, 08 Jan 2023 04:59:48 -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; 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 509C668BC8F; Sun, 8 Jan 2023 14:58:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 28FE168BC59 for ; Sun, 8 Jan 2023 14:58:41 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 64E9B2405EC for ; Sun, 8 Jan 2023 13:58:37 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0MGMPqfJejzZ for ; Sun, 8 Jan 2023 13:58:36 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id EA8AB2406C7 for ; Sun, 8 Jan 2023 13:58:33 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8FBB23A03D9 for ; Sun, 8 Jan 2023 13:58:26 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 8 Jan 2023 13:58:10 +0100 Message-Id: <20230108125811.17967-7-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230108125811.17967-1-anton@khirnov.net> References: <20230108125811.17967-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/8] lavfi/graphparser: improve applying graph-level sws options 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ExOLd/kVvXGm The current code will apply them if the options string does not contain a 'flags' substring, and will do so by appending the graph-level option string to the filter option string (with the standard ':' separator). This is flawed in at least the following ways: - naive substring matching without actually parsing the options string may lead to false positives (e.g. flags are specified by shorthand) and false negatives (e.g. the 'flags' substring is not actually the option name) - graph-level sws options are not limited to flags, but may set arbitrary sws options This commit simply applies the graph-level options with av_set_options_string() and lets them be overridden as desired by the user-specified filter options (if any). This is also shorter and avoids extra string handling. --- libavfilter/graphparser.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index 1385c3ae71..c8b0af5aba 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -25,6 +25,8 @@ #include "libavutil/avstring.h" #include "libavutil/mem.h" +#include "libavutil/opt.h" + #include "avfilter.h" #define WHITESPACES " \n\t\r" @@ -101,7 +103,6 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind const AVFilter *filt; char name2[30]; const char *inst_name = NULL, *filt_name = NULL; - char *tmp_args = NULL; int ret, k; av_strlcpy(name2, name, sizeof(name2)); @@ -136,16 +137,10 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind return AVERROR(ENOMEM); } - if (!strcmp(filt_name, "scale") && (!args || !strstr(args, "flags")) && - ctx->scale_sws_opts) { - if (args) { - tmp_args = av_asprintf("%s:%s", - args, ctx->scale_sws_opts); - if (!tmp_args) - return AVERROR(ENOMEM); - args = tmp_args; - } else - args = ctx->scale_sws_opts; + if (!strcmp(filt_name, "scale") && ctx->scale_sws_opts) { + ret = av_set_options_string(*filt_ctx, ctx->scale_sws_opts, "=", ":"); + if (ret < 0) + return ret; } ret = avfilter_init_str(*filt_ctx, args); @@ -159,7 +154,6 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind *filt_ctx = NULL; } - av_free(tmp_args); return ret; }