Hi all,
I want to implement process_command for vf_scale.c and vf_crop.c in order to use zmq to change
scaling and cropping dynamically.
I have implemented it using av_opt_set() and calling config_props() for scale and config_input() and
config_output() for crop. I am using the config_-functions because they handle variable parsing and
checking of the values. But I do not know if this is the right way to do it and if it is safe to
call these functions from process_command.
Maybe someone can comment on these implementation or outline a way to implement process_command for
these filters.
I attach patches including my implementation so far.
Thank you very much in advance
Bernd
>From 95e79abfea966585c18d0eef3047ab41783421ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernd=20Ble=C3=9Fmann?= <b...@it-entwicklung.de>
Date: Fri, 12 Jun 2015 13:50:55 +0200
Subject: [PATCH 1/2] libavfilter/vf_scale: implement process_command
---
libavfilter/vf_scale.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 2a3d008..5982128 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -544,6 +544,30 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
return ff_filter_frame(outlink, out);
}
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+ char *res, int res_len, int flags)
+{
+ ScaleContext *scale = ctx->priv;
+ int ret;
+
+ if ( !strcmp(cmd, "width") || !strcmp(cmd, "w")
+ || !strcmp(cmd, "height") || !strcmp(cmd, "h")) {
+
+ int old_w = scale->w;
+ int old_h = scale->h;
+ AVFilterLink *outlink = ctx->outputs[0];
+
+ av_opt_set(scale, cmd, args, 0);
+ if ((ret = config_props(outlink)) < 0) {
+ scale->w = old_w;
+ scale->h = old_h;
+ }
+ } else
+ ret = AVERROR(ENOSYS);
+
+ return ret;
+}
+
static const AVClass *child_class_next(const AVClass *prev)
{
return prev ? NULL : sws_get_class();
@@ -619,4 +643,5 @@ AVFilter ff_vf_scale = {
.priv_class = &scale_class,
.inputs = avfilter_vf_scale_inputs,
.outputs = avfilter_vf_scale_outputs,
+ .process_command = process_command,
};
--
2.1.4
>From 1bd057068e574a6ae1c7395732457e71f901c735 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernd=20Ble=C3=9Fmann?= <b...@it-entwicklung.de>
Date: Fri, 12 Jun 2015 13:51:40 +0200
Subject: [PATCH 2/2] libavfilter/vf_crop: implement process_command
---
libavfilter/vf_crop.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
index f58a7ae..b18760b 100644
--- a/libavfilter/vf_crop.c
+++ b/libavfilter/vf_crop.c
@@ -296,6 +296,42 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame)
return ff_filter_frame(link->dst->outputs[0], frame);
}
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+ char *res, int res_len, int flags)
+{
+ CropContext *s = ctx->priv;
+ int ret;
+
+ if ( !strcmp(cmd, "out_w") || !strcmp(cmd, "w")
+ || !strcmp(cmd, "out_h") || !strcmp(cmd, "h")
+ || !strcmp(cmd, "x") || !strcmp(cmd, "y")) {
+
+ int old_x = s->x;
+ int old_y = s->y;
+ int old_w = s->w;
+ int old_h = s->h;
+
+ AVFilterLink *outlink = ctx->outputs[0];
+ AVFilterLink *inlink = ctx->inputs[0];
+
+ av_opt_set(s, cmd, args, 0);
+
+ if ((ret = config_input(inlink)) < 0) {
+ s->x = old_x;
+ s->y = old_y;
+ s->w = old_w;
+ s->h = old_h;
+ return ret;
+ }
+
+ ret = config_output(outlink);
+
+ } else
+ ret = AVERROR(ENOSYS);
+
+ return ret;
+}
+
#define OFFSET(x) offsetof(CropContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
@@ -340,4 +376,5 @@ AVFilter ff_vf_crop = {
.uninit = uninit,
.inputs = avfilter_vf_crop_inputs,
.outputs = avfilter_vf_crop_outputs,
+ .process_command = process_command,
};
--
2.1.4
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel