From patchwork Fri Jun 16 09:29:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 42142 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp1391493pzb; Fri, 16 Jun 2023 02:32:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rgnd3LjaW/dxCzdJJt0LGymDaocWcACfhUgABrH7EymdlqmRGA16ByZjlhKVp336+Ssgq X-Received: by 2002:a17:907:a41e:b0:96f:f6a6:58dd with SMTP id sg30-20020a170907a41e00b0096ff6a658ddmr1508981ejc.5.1686907925903; Fri, 16 Jun 2023 02:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686907925; cv=none; d=google.com; s=arc-20160816; b=AMC808S1Mkuq4JA3g+WpjUFDYYqhTNUCwdspJv8VAQ58EpJ+OMY/oWZf2mfRDdSUMd 21aVMhaiV4UCTHRwDRI9auETb+2PQC49f9kazjoLGcxF1PkzbmZ83sZK54adcmBwZOQd yJhK/LZXHQj+XY4zub4iXkIYJ7zRWFJ5IRmUwwrYXDakJCdz0wgdVhg4SZbe3qPvrGiE hUyGojsMffC1U3TR54pwq4gAHnsfE8pQteybGIQsAdD377l5qKNqudfgCm1ByvUpEQc2 qXp96MysM4gU+zPutduPnDR54Adit0vH/xbTWK2YsHQctVocot3leP2CyBzFnRs00fFO qYEw== 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=Au0CETddz/uGeHH12/V6bhnyMn4/WrGEmEJM9coZNu0=; b=ew8ogCPQ+o9O+AejhqXiSDQTU1HY32KqElyfknqJdrQWId+fUCdso70Ggn16ya6EAd 4QJF5xAxjqo4GKTqABPczuDNyRzGKdu0YHRehQWWmKsnUY6VyDyWJPYpNKAm4w6jBRy4 T1EnCzY9yPwZgsvV41x/8RBLZ5yILhrFlJ0sPyCylLQ7Nxko6jLdGC7K7g6mjfOnKlTr Y7f9dbL1EcYib29lTH2RQuRKLIy+Rax1mw4h+rOg5f9lpWNWwpnXYp4UuF8kvpIXkxHL Qk2jmxlceqkZGnGANKASFbkmxuEQDXyVL0/clkkhHYWg0ISrxyy3Wqd0QJiVm9dnEOoT iSlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="J12k9Q/N"; 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 p5-20020a170906838500b0094f791be3c0si9952898ejx.268.2023.06.16.02.32.05; Fri, 16 Jun 2023 02:32:05 -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=@haasn.xyz header.s=mail header.b="J12k9Q/N"; 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 1DF5D68C5F8; Fri, 16 Jun 2023 12:30:37 +0300 (EEST) 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 7EEF368C5BB for ; Fri, 16 Jun 2023 12:30:25 +0300 (EEST) Received: from localhost (217-74-0-168.hsi.r-kom.net [217.74.0.168]) by haasn.dev (Postfix) with ESMTPSA id 67947436B4; Fri, 16 Jun 2023 11:30:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1686907823; bh=TQv+QL92w+szjSjseDX8j6f2uQfHndzdocG+7D4VDzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J12k9Q/N3E/Flum5Erl1ZUMiSxWGAmB7i9Na5dp8MXQzJSC2i3M7ateK0k22GC4yi TkXl9JaFIsDOI31ccMd2D0BCw1hDV9oVi9ycMTUVm1rhs8IpL6960NtYYoQ8Xb/W+e OEsBV5aUow/dhz2PZrqT2PFcvBpM8ErdpOxFtQ4w= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Jun 2023 11:29:44 +0200 Message-ID: <20230616092959.5247-7-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616092959.5247-1-ffmpeg@haasn.xyz> References: <20230616092959.5247-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/22] lavfi/vf_libplacebo: factor out ref frame logic 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: vkwU5tj/imRv From: Niklas Haas Instead of finding the ref frame in output_frame() and then passing its signature to update_crops(), pull out the logic and invoke it a second time inside update_crops(). This may seem wasteful at present, but will actually become required in the future, since update_crops() runs on *every* input, and needs values specific to that input (which the signature isn't), while output_frame() is only interested in a single input. It's much easier to just split the logic cleanly. --- libavfilter/vf_libplacebo.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 0289187b46..b83df24a84 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -706,11 +706,21 @@ fail: return err; } +static const AVFrame *ref_frame(const struct pl_frame_mix *mix) +{ + for (int i = 0; i < mix->num_frames; i++) { + if (i+1 == mix->num_frames || mix->timestamps[i+1] > 0) + return pl_get_mapped_avframe(mix->frames[i]); + } + return NULL; +} + static void update_crops(AVFilterContext *ctx, struct pl_frame_mix *mix, struct pl_frame *target, - uint64_t ref_sig, double target_pts) + double target_pts) { LibplaceboContext *s = ctx->priv; + const AVFrame *ref = ref_frame(mix); for (int i = 0; i < mix->num_frames; i++) { // Mutate the `pl_frame.crop` fields in-place. This is fine because we @@ -745,7 +755,7 @@ static void update_crops(AVFilterContext *ctx, image->crop.x1 = image->crop.x0 + s->var_values[VAR_CROP_W]; image->crop.y1 = image->crop.y0 + s->var_values[VAR_CROP_H]; - if (mix->signatures[i] == ref_sig) { + if (src == ref) { /* Only update the target crop once, for the 'reference' frame */ target->crop.x0 = av_expr_eval(s->pos_x_pexpr, s->var_values, NULL); target->crop.y0 = av_expr_eval(s->pos_y_pexpr, s->var_values, NULL); @@ -768,25 +778,16 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) LibplaceboInput *in = &s->input; AVFilterLink *outlink = ctx->outputs[0]; const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format); + const AVFrame *ref = ref_frame(&in->mix); struct pl_frame target; - const AVFrame *ref; AVFrame *out; - uint64_t ref_sig; - if (!in->mix.num_frames) + if (!ref) return 0; out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) return AVERROR(ENOMEM); - /* Use the last frame before current PTS value as reference */ - for (int i = 0; i < in->mix.num_frames; i++) { - if (i && in->mix.timestamps[i] > 0.0f) - break; - ref = pl_get_mapped_avframe(in->mix.frames[i]); - ref_sig = in->mix.signatures[i]; - } - RET(av_frame_copy_props(out, ref)); out->pts = pts; out->width = outlink->w; @@ -850,7 +851,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) goto fail; } - update_crops(ctx, &in->mix, &target, ref_sig, out->pts * av_q2d(outlink->time_base)); + update_crops(ctx, &in->mix, &target, out->pts * av_q2d(outlink->time_base)); pl_render_image_mix(in->renderer, &in->mix, &target, &s->params); if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {