From patchwork Wed Sep 25 13:29:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51842 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9548:0:b0:48e:c0f8:d0de with SMTP id t8csp466160vqk; Wed, 25 Sep 2024 06:30:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVGi0aaQOILCuX5vyDrSimepkZTvEws3YEF3Z5T2otGbwWLvkmcbXbvRvYBk5EURJCgIO60NHE+IQPK9V/XOgpp@gmail.com X-Google-Smtp-Source: AGHT+IF9Gk2mEqaZBh9hQXd+sRZp11RLrOhvp/+2gSaMAu3BFRR+nCyAZC8lfqz5v/WlsQiXGSc3 X-Received: by 2002:a05:6512:6d6:b0:536:9ef3:3b0d with SMTP id 2adb3069b0e04-5387048bde2mr1575145e87.2.1727271000061; Wed, 25 Sep 2024 06:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727271000; cv=none; d=google.com; s=arc-20240605; b=VUfmtOK5KwkWmV6o+FMLoMxPNX1Ffm5yF38quzpleRWeGpyOozsuuROYXk0x/g2Jnt K9Eu50G0yf1YJTxlIDXP2wxOS/86IcDsfkxrQF5VgrtUocNag8/Y+ED/slBHEK6Y97Va cDTb06Nq7OBNT9Qc3xt1v5rrfjDh3iSgERhZqjfBeqecbEy34IyHWk+25I3J54Av787U N1CJThlqyxKCgDexW1PvgEfnMNUrJTeI3WY4jk/JDkhIcdvTE/cc0dj/z5p/7JdzNd1T MfKfu9h8QWl9dTj7Qa1r+NR9jtlvFzL5scsmyV9tQ47Waf+f4++Y1Y5aqBo8RQLCU6qP DiYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:message-id:date:to:from :dkim-signature:delivered-to; bh=EDfRz1pissOCIvQmbQR9kKY6ZrshIJ5iDz0k4pRJMmg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=HB1n8v9RCtv3HLpG3v0+gvKwEILVqTeOuhxnJ16jV64Bn4gSjbk43UYNViU1zQktLt aAUcnOUdtDBexH9kyHKUPHCU/vLCoru/Zl8qQIQilDgjqZDiHOWd91xHl6lQOm7jnYaP /SVlXCs1vkfkOp37ETHTSrCvxV68cxpQW+gnvKIYwNL7DmfNj1/3fEG7As6iDmro2qm1 ki6tipjNSDmbs//hm20ECtE3BCg2abX7xV5G8SaYZY/AGwneQEsCIeRUmMKjcgpvn4Fj W6dyqL542ZzaymECRBa8HdrwmiKrNIhdmCqbzM39U6vCt9/MyqgKSPuA4i5Su8Xq38jD pCfQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=HvMLrWB8; 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 2adb3069b0e04-537a85ee665si1290980e87.163.2024.09.25.06.29.59; Wed, 25 Sep 2024 06:30:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=HvMLrWB8; 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 2DA5768DB88; Wed, 25 Sep 2024 16:29:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE16B68DABC for ; Wed, 25 Sep 2024 16:29:26 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=HvMLrWB8; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 2A1BD4D9D for ; Wed, 25 Sep 2024 15:29:26 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id gKXDiWc9HIXj for ; Wed, 25 Sep 2024 15:29:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727270964; bh=gtssp9wqeinGkgnGl0h29Si5GdJF4THZ0vNbI9NvnLA=; h=From:To:Subject:Date:From; b=HvMLrWB8pS9g0A2oPOewAK02foGMNfe/4BUPZygnubtAmksDRoBuJANt+SK2Xfs+Z PeyS+UH5ubp4opJIU0YSv1sSRWmvULjbSWsSANDC6wJDoE7Cn9GCslgWB4GnlwPzVM duCmmrP+ez4ZT2YFivcO9KuWjSsUcg0J3UTdVyJY7tA5Kn2aZaMTm5JS0BDBWT6ueC Mqh8btJRklYxCRMg25kkLuy0zFe6iH3wEYSYl0fxGZajdqANQNgNgT/N3OyNek22g5 bzwCG2i45Nh329OLCkGFa+6TpU1kXiUqv9jMxKZzmBKsVEfSz3QNR0rqPKmrc1gB6o Xj6CWuFTju7VQ== 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 mail1.khirnov.net (Postfix) with ESMTPS id AF28E4DE6 for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 87A5B3A03CA for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 25 Sep 2024 15:29:12 +0200 Message-ID: <20240925132921.11203-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/10] fftools/ffmpeg_filter: stop using avfilter_graph_alloc_filter() incorrectly 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: dFmDfJ9zrKnK This function creates AND initializes a filter, so setting any filter options after it is wrong. It happens to work when the filter's init function does not touch the options in question, but is forbidden by the API and is not guaranteed to remain functional. Instead, use avfilter_graph_alloc_filter(), followed by setting the options, and avfilter_init_dict(). --- fftools/ffmpeg_filter.c | 53 ++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index c36a3ad00a..2f7597b491 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1586,14 +1586,18 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, int ret; snprintf(name, sizeof(name), "out_%s", ofp->name); - ret = avfilter_graph_create_filter(&ofp->filter, - avfilter_get_by_name("abuffersink"), - name, NULL, NULL, graph); - if (ret < 0) - return ret; + ofp->filter = avfilter_graph_alloc_filter(graph, + avfilter_get_by_name("abuffersink"), + name); + if (!ofp->filter) + return AVERROR(ENOMEM); if ((ret = av_opt_set_int(ofp->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0) return ret; + ret = avfilter_init_dict(ofp->filter, NULL); + if (ret < 0) + return ret; + #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \ AVFilterContext *filt_ctx; \ \ @@ -1686,9 +1690,6 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, AVFilterContext *last_filter; const AVFilter *buffer_filt = avfilter_get_by_name("buffer"); const AVPixFmtDescriptor *desc; - AVRational fr = ifp->opts.framerate; - AVRational sar; - AVBPrint args; char name[255]; int ret, pad_idx = 0; AVBufferSrcParameters *par = av_buffersrc_parameters_alloc(); @@ -1698,30 +1699,34 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) sub2video_prepare(ifp); - sar = ifp->sample_aspect_ratio; - if(!sar.den) - sar = (AVRational){0,1}; - 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:colorspace=%d:range=%d", - ifp->width, ifp->height, ifp->format, - ifp->time_base.num, ifp->time_base.den, sar.num, sar.den, - ifp->color_space, 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 %s", fg->index, ifp->opts.name); - - if ((ret = avfilter_graph_create_filter(&ifp->filter, buffer_filt, name, - args.str, NULL, graph)) < 0) + ifp->filter = avfilter_graph_alloc_filter(graph, buffer_filt, name); + if (!ifp->filter) { + ret = AVERROR(ENOMEM); goto fail; - par->hw_frames_ctx = ifp->hw_frames_ctx; + } + + par->format = ifp->format; + par->time_base = ifp->time_base; + par->frame_rate = ifp->opts.framerate; + par->width = ifp->width; + par->height = ifp->height; + par->sample_aspect_ratio = ifp->sample_aspect_ratio.den > 0 ? + ifp->sample_aspect_ratio : (AVRational){ 0, 1 }; + par->color_space = ifp->color_space; + par->color_range = ifp->color_range; + par->hw_frames_ctx = ifp->hw_frames_ctx; ret = av_buffersrc_parameters_set(ifp->filter, par); if (ret < 0) goto fail; av_freep(&par); + + ret = avfilter_init_dict(ifp->filter, NULL); + if (ret < 0) + goto fail; + last_filter = ifp->filter; desc = av_pix_fmt_desc_get(ifp->format);