From patchwork Wed Apr 24 10:51:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 48247 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:2d06:b0:1a9:af23:56c1 with SMTP id tw6csp571081pzb; Wed, 24 Apr 2024 04:03:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUUTFFgz7hNo1hq5/NIdDunaCDlqci7IxVn+vAKYVt0f3MnkEWVTvqQjMa6Zycg5hba9KqhdU9KJZBL0H19vNS8SL/uy1KeyK78rw== X-Google-Smtp-Source: AGHT+IFl9HueAVuv8l0azAPdtQc83kc8COqPnMhiYbM0qUzHKvBIrANj4PmH0clpEs4v52yQEn3X X-Received: by 2002:ac2:5466:0:b0:518:d685:9935 with SMTP id e6-20020ac25466000000b00518d6859935mr1505705lfn.8.1713956617919; Wed, 24 Apr 2024 04:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713956617; cv=none; d=google.com; s=arc-20160816; b=b1w5kly9KxfomJec9c8eGbGOS6ef2T2ojzP6FIjAZj+OiLQRMAyz6zdarA4UAUK61D kQjbnbnaamgfT+7Z5eTX5G+1mCg6zTnYheNHfxqVaxx/spwcz9/A15i01TkEOOT330r+ AIt/bMLMQN8yRR8YPTUAH8l78yB7Zc/8tWcsW4PQZkt16fq6z6QEGeZjxKU4Yfv0bHvR DShRrHssQNHDf9C45Foo5qwK6yBaCExwYXa4OBCb0yOYuznrZH+3cNehkMIhc2jr+a5E FSandawUywAEPssrYJXTRGUkI2pnrPyXcQNDBneLXEhIoQDEIftUoq7fub57TGPeKRZy LIiw== 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=KdnBybd+DxHd7WwKyscJF3neL5HaF1tuGmhPk7yTR/8=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=orYrH4tikxjBj1tDbbA3bDR9geWO/3TduwGbPA/W1nA1zRZiFwnfPSnTyEKkTWZb/d 6C++0yyBnGWusLs+MliWQgP3K4AEdytUxnvYMu75FMXlwMjU6z6KSA9AKhnbBINebbJY snpQMSAQgcpkaSNmng0DY8OgBKg5FY9HnTTt+S6JL9InxQWVVFKALXtxoAvQs6+Oclex aYeHqBVenTYc3VfG2wtnmnwm1qfJvyDnWX/+dpdQ/gKwHCENAGlNQpv/zbwgjVXZk4VA cXYcO2LMF7bwGTbvGp5Kbh16ebwYQIxGgQyYJQjaN8dT+8yI6GdV7MzOpi9H6MoHjxwt ttFg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Z3cXRYKe; 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 z17-20020a056512309100b005195c66f78fsi4642369lfd.83.2024.04.24.04.03.35; Wed, 24 Apr 2024 04:03:37 -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=Z3cXRYKe; 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 264DA68D380; Wed, 24 Apr 2024 14:03:14 +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 9F8D368D0D9 for ; Wed, 24 Apr 2024 14:03:05 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1713956585; bh=8ILWec1I3HBOVjGiezvdRDQkYUiU3f80tUo+oCxLSII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z3cXRYKevNIwqmzFQw0xlOmg2LVTH1gEwbqN16wMLQfI/Lm9siBtUjvO4w2yKHv8w U61YpYdLEUEGL1sTe1Hrooe8Dr8WKvVqV7Fnekp+598IM6588n/TnORnD69DDJnOWK Z9fthqmIvF8MOQPBav9fInoSFOgrUtGa7MjchU5E= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 63BE042527; Wed, 24 Apr 2024 13:03:05 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Apr 2024 12:51:57 +0200 Message-ID: <20240424110257.38715-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424110257.38715-1-ffmpeg@haasn.xyz> References: <20240424110257.38715-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avfilter/vf_scale: switch to FFFrameSync 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: predUcrnLAW/ From: Niklas Haas Preliminary commit, in anticipation of adding support for multiple inputs (with proper synchronization and activate() callback). --- doc/filters.texi | 4 +-- libavfilter/vf_scale.c | 65 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index fc813f12c1..f20b72ab96 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -20989,8 +20989,8 @@ the next filter, the scale filter will convert the input to the requested format. @subsection Options -The filter accepts the following options, or any of the options -supported by the libswscale scaler. +The filter accepts the following options, any of the options supported +by the libswscale scaler, as well as any of the @ref{framesync} options. See @ref{scaler_options,,the ffmpeg-scaler manual,ffmpeg-scaler} for the complete list of scaler options. diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 1c07daeddf..a986dc97ae 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -29,6 +29,7 @@ #include "avfilter.h" #include "formats.h" +#include "framesync.h" #include "internal.h" #include "scale_eval.h" #include "video.h" @@ -113,6 +114,7 @@ typedef struct ScaleContext { struct SwsContext *isws[2]; ///< software scaler context for interlaced material // context used for forwarding options to sws struct SwsContext *sws_opts; + FFFrameSync fs; /** * New dimensions. Special values are: @@ -287,6 +289,8 @@ static av_cold int preinit(AVFilterContext *ctx) if (ret < 0) return ret; + ff_framesync_preinit(&scale->fs); + return 0; } @@ -302,6 +306,8 @@ static const int sws_colorspaces[] = { -1 }; +static int do_scale(FFFrameSync *fs); + static av_cold int init(AVFilterContext *ctx) { ScaleContext *scale = ctx->priv; @@ -388,6 +394,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_expr_free(scale->w_pexpr); av_expr_free(scale->h_pexpr); scale->w_pexpr = scale->h_pexpr = NULL; + ff_framesync_uninit(&scale->fs); sws_freeContext(scale->sws_opts); sws_freeContext(scale->sws); sws_freeContext(scale->isws[0]); @@ -677,6 +684,21 @@ static int config_props(AVFilterLink *outlink) flags_val); av_freep(&flags_val); + if (ctx->filter != &ff_vf_scale2ref) { + ret = ff_framesync_init(&scale->fs, ctx, ctx->nb_inputs); + if (ret < 0) + return ret; + scale->fs.on_event = do_scale; + scale->fs.in[0].time_base = ctx->inputs[0]->time_base; + scale->fs.in[0].sync = 1; + scale->fs.in[0].before = EXT_STOP; + scale->fs.in[0].after = EXT_STOP; + + ret = ff_framesync_configure(&scale->fs); + if (ret < 0) + return ret; + } + return 0; fail: @@ -894,6 +916,26 @@ scale: return ret; } +static int do_scale(FFFrameSync *fs) +{ + AVFilterContext *ctx = fs->parent; + AVFilterLink *outlink = ctx->outputs[0]; + AVFrame *in, *out; + int ret; + + ret = ff_framesync_get_frame(fs, 0, &in, 1); + if (ret < 0) + return ret; + + ret = scale_frame(ctx->inputs[0], in, &out); + if (out) { + out->pts = av_rescale_q(fs->pts, fs->time_base, outlink->time_base); + return ff_filter_frame(outlink, out); + } + + return ret; +} + static int filter_frame(AVFilterLink *link, AVFrame *in) { AVFilterContext *ctx = link->dst; @@ -972,11 +1014,24 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar return ret; } +static int activate(AVFilterContext *ctx) +{ + ScaleContext *scale = ctx->priv; + return ff_framesync_activate(&scale->fs); +} + static const AVClass *child_class_iterate(void **iter) { - const AVClass *c = *iter ? NULL : sws_get_class(); - *iter = (void*)(uintptr_t)c; - return c; + switch ((uintptr_t) *iter) { + case 0: + *iter = (void*)(uintptr_t) 1; + return sws_get_class(); + case 1: + *iter = (void*)(uintptr_t) 2; + return &ff_framesync_class; + } + + return NULL; } static void *child_next(void *obj, void *prev) @@ -984,6 +1039,8 @@ static void *child_next(void *obj, void *prev) ScaleContext *s = obj; if (!prev) return s->sws_opts; + if (prev == s->sws_opts) + return &s->fs; return NULL; } @@ -1051,7 +1108,6 @@ static const AVFilterPad avfilter_vf_scale_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, - .filter_frame = filter_frame, }, }; @@ -1074,6 +1130,7 @@ const AVFilter ff_vf_scale = { FILTER_INPUTS(avfilter_vf_scale_inputs), FILTER_OUTPUTS(avfilter_vf_scale_outputs), FILTER_QUERY_FUNC(query_formats), + .activate = activate, .process_command = process_command, };