From patchwork Sun Jun 18 11:16: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: 42197 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp57149pzb; Sun, 18 Jun 2023 04:22:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ75F/zYXrjy+0wUogjxp51zhUxdd7l0xrC85BjeC5TZtxIWujTdKhI20Ci7n93MJVXBjC/o X-Received: by 2002:a17:906:730c:b0:988:9d0f:db52 with SMTP id di12-20020a170906730c00b009889d0fdb52mr318421ejc.35.1687087349780; Sun, 18 Jun 2023 04:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687087349; cv=none; d=google.com; s=arc-20160816; b=OeOoaHDlTFAeJ/8y2l20hockbckMPFEQLiGq2nGTE/GS1I6pxg1kH8eQUPMbcBI79j MynPedxpSiFeWEhMzChi/UyFFdqolSdJaZLLhLeHOQJgu5UysdZrzz2PE1FYl+TPPMwF eV2omPpSaivKkfgojkpe3kigbFaQqS3xuWl74rHdj+G69PeAXiT3ffr42WEVrnY03fZ5 Nih6zQwoyUPNu4n9PDMOkDAoofFV0JO3vFNNwN/ViH8YBxv4LmFf71FkmAcTTy7RYGEe JmXEWintaFR3/im1NdfmLJk+5V1X93ydXg924TxZM1nsgJCzXSq6vTz3IT3jty5cbIHF 67Xw== 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=PrtfX+y3ISJ71u9jrLidFkCYkjcSas456OHiptUGwI4=; b=qG+HspLBPzaBxJGXZ6KPCHJRuGvx3SE7BNDmtprvKwRtK5XggSH8AJpICiMHFYc2bZ Z7ImMpC/HvH3hHnIPRYHhLMhgs4ek9nXhjXzqWNGQsk7BQ3m7zMxEntDHIdhWvDaj7ut 355sKkLs5RK1CAqz6KNS36dxU5PLSDAe/r2ML7u3KBt6zRJm7np09e+u8kQv4V3qMtbW WnTFg6gcejLhyhS5DexOBS4RGv41t13ALfYyLS9DBeTx5DFJcPiWkTQTto9REi/z8r02 AxEcImNpgi2F7Ak2w6DIbQa1ITPxEJx8bG0N86MP85s2mCGz4Q8ONA4EnRhngQ5UQnmG EkDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=i6nlzyIl; 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 ca10-20020a170906a3ca00b009864522956bsi3111695ejb.94.2023.06.18.04.22.29; Sun, 18 Jun 2023 04:22:29 -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=i6nlzyIl; 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 5D9A068BFCE; Sun, 18 Jun 2023 14:20:28 +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 CDAF768BF50 for ; Sun, 18 Jun 2023 14:20:13 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 08E0943FD1; Sun, 18 Jun 2023 13:20:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1687087210; bh=XjmHRAvQdX3OfvU3vFeXaIsQ6Gs17YxU16Kdk73QKO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i6nlzyIlNGB5pv89DrvwvEVxeWHsPBFc9Jn6Ac0Da4czWUIsqCxPYozHCdX7BSXYV g0FhX930U9tBqR75e8EwlEknNb8X+SVezjRB+Pz7uyhvNb8+yVXSiNEofrWDGYDMqE 8rkbfX3AQWhi1Ry8aMQUSTrAuWJ+l15/pMZ008pU= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Jun 2023 13:16:59 +0200 Message-ID: <20230618111955.40994-9-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230618111955.40994-2-ffmpeg@haasn.xyz> References: <20230618111955.40994-2-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: vPZuxHBmSFPa 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 0289187b46b..b83df24a84b 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) {