[FFmpeg-cvslog] lavfi/hue: add process_command callback
Jérémy Tran
git at videolan.org
Fri Aug 31 18:23:48 CEST 2012
ffmpeg | branch: master | Jérémy Tran <tran.jeremy.av at gmail.com> | Fri Aug 31 01:56:58 2012 +0200| [54ca7e39dae120fefe96d30e965a304b63a1b491] | committer: Stefano Sabatini
lavfi/hue: add process_command callback
This allows dynamic reconfiguration of the filter.
The callback uses some code that was in the init function. Hence this code
has been moved in its own function.
Signed-off-by: Stefano Sabatini <stefasab at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=54ca7e39dae120fefe96d30e965a304b63a1b491
---
doc/filters.texi | 12 ++++++++++++
libavfilter/version.h | 2 +-
libavfilter/vf_hue.c | 45 +++++++++++++++++++++++++++++++++++++++++----
3 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 4824d9c..2312d77 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2350,6 +2350,18 @@ hue=PI/2:1
@end example
@end itemize
+ at subsection Commands
+
+This filter supports the following command:
+ at table @option
+ at item reinit
+Modify the hue and/or the saturation of the input video.
+The command accepts the same named options and syntax than when calling the
+filter from the command-line.
+
+If a parameter is omitted, it is kept at its current value.
+ at end table
+
@section idet
Interlaceing detect filter. This filter tries to detect if the input is
diff --git a/libavfilter/version.h b/libavfilter/version.h
index a216d9c..6a25d82 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 15
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MICRO 101
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_hue.c b/libavfilter/vf_hue.c
index cf1fe5f..dd36d8e 100644
--- a/libavfilter/vf_hue.c
+++ b/libavfilter/vf_hue.c
@@ -63,19 +63,19 @@ static const AVOption hue_options[] = {
AVFILTER_DEFINE_CLASS(hue);
-static av_cold int init(AVFilterContext *ctx, const char *args)
+static inline int set_options(AVFilterContext *ctx, const char *args)
{
HueContext *hue = ctx->priv;
int n, ret;
char c1 = 0, c2 = 0;
char *equal;
- hue->class = &hue_class;
- av_opt_set_defaults(hue);
-
if (args) {
/* named options syntax */
if (equal = strchr(args, '=')) {
+ hue->hue = -FLT_MAX;
+ hue->hue_deg = -FLT_MAX;
+
if ((ret = av_set_options_string(hue, args, "=", ":")) < 0)
return ret;
if (hue->hue != -FLT_MAX && hue->hue_deg != -FLT_MAX) {
@@ -103,6 +103,20 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
}
}
+ return 0;
+}
+
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+ HueContext *hue = ctx->priv;
+ int ret;
+
+ hue->class = &hue_class;
+ av_opt_set_defaults(hue);
+
+ if ((ret = set_options(ctx, args)) < 0)
+ return ret;
+
if (hue->saturation == -FLT_MAX)
hue->hue = SAT_DEFAULT_VAL;
if (hue->hue == -FLT_MAX)
@@ -223,6 +237,28 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
}
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+ char *res, int res_len, int flags)
+{
+ HueContext *hue = ctx->priv;
+ int ret;
+
+ if (!strcmp(cmd, "reinit")) {
+ if ((ret = set_options(ctx, args)) < 0)
+ return ret;
+
+ if (hue->hue_deg != -FLT_MAX)
+ /* Convert angle from degrees to radians */
+ hue->hue = hue->hue_deg * M_PI / 180;
+
+ hue->hue_sin = rint(sin(hue->hue) * (1 << 16) * hue->saturation);
+ hue->hue_cos = rint(cos(hue->hue) * (1 << 16) * hue->saturation);
+ } else
+ return AVERROR(ENOSYS);
+
+ return 0;
+}
+
AVFilter avfilter_vf_hue = {
.name = "hue",
.description = NULL_IF_CONFIG_SMALL("Adjust the hue and saturation of the input video."),
@@ -232,6 +268,7 @@ AVFilter avfilter_vf_hue = {
.init = init,
.uninit = uninit,
.query_formats = query_formats,
+ .process_command = process_command,
.inputs = (const AVFilterPad[]) {
{
More information about the ffmpeg-cvslog
mailing list