From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 2/5] avfilter/vf_scale: switch to FFFrameSync
Date: Wed, 24 Apr 2024 12:51:57 +0200
Message-ID: <20240424110257.38715-3-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20240424110257.38715-1-ffmpeg@haasn.xyz>
From: Niklas Haas <git@haasn.dev>
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,
};
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-04-24 11:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-24 10:51 [FFmpeg-devel] [PATCH 0/5] replace scale2ref by scale=rw:rh Niklas Haas
2024-04-24 10:51 ` [FFmpeg-devel] [PATCH 1/5] avfilter/framesync: make framesync_class un-static Niklas Haas
2024-04-24 10:51 ` Niklas Haas [this message]
2024-04-24 10:51 ` [FFmpeg-devel] [PATCH 3/5] avfilter/vf_scale: add optional "ref" input Niklas Haas
2024-04-24 10:51 ` [FFmpeg-devel] [PATCH 4/5] fate/scale2ref_keep_aspect: switch to vf_scale ref_* Niklas Haas
2024-04-24 10:52 ` [FFmpeg-devel] [PATCH 5/5] avfilter/scale2ref: deprecate in favor of scale=rw:rh Niklas Haas
2024-04-24 11:18 ` [FFmpeg-devel] [PATCH 0/5] replace scale2ref by scale=rw:rh Gyan Doshi
2024-04-24 11:38 ` Timo Rothenpieler
2024-04-24 11:40 ` Niklas Haas
2024-05-02 10:12 ` Niklas Haas
2024-05-23 6:36 ` Anton Khirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240424110257.38715-3-ffmpeg@haasn.xyz \
--to=ffmpeg@haasn.xyz \
--cc=ffmpeg-devel@ffmpeg.org \
--cc=git@haasn.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git