[FFmpeg-devel] [PATCH] lavfi/yadif: add support to named options and options introspection

Stefano Sabatini stefasab at gmail.com
Wed Jan 2 17:21:11 CET 2013


---
 doc/filters.texi       |   25 ++++++++++++++++++-------
 libavfilter/vf_yadif.c |   30 +++++++++++++++++++++++-------
 libavfilter/yadif.h    |    2 ++
 3 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index ad23024..420bf18 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4400,10 +4400,17 @@ ffmpeg -i in.avi -vf "vflip" out.avi
 Deinterlace the input video ("yadif" means "yet another deinterlacing
 filter").
 
-It accepts the optional parameters: @var{mode}:@var{parity}:@var{auto}.
+The filter accepts parameters as a list of @var{key}=@var{value}
+pairs, separated by ":". If the key of the first options is omitted,
+the arguments are interpreted according to syntax
+ at var{mode}:@var{parity}:@var{enable}.
+
+The description of the accepted parameters follows.
 
- at var{mode} specifies the interlacing mode to adopt, accepts one of the
-following values:
+ at table @option
+ at item mode
+Specify the interlacing mode to adopt. Accept one of the following
+values:
 
 @table @option
 @item 0
@@ -4418,8 +4425,9 @@ like 1 but skips spatial interlacing check
 
 Default value is 0.
 
- at var{parity} specifies the picture field parity assumed for the input
-interlaced video, accepts one of the following values:
+ at item parity
+Specify the picture field parity assumed for the input interlaced
+video. Accept one of the following values:
 
 @table @option
 @item 0
@@ -4434,8 +4442,10 @@ Default value is -1.
 If interlacing is unknown or decoder does not export this information,
 top field first will be assumed.
 
- at var{auto} specifies if deinterlacer should trust the interlaced flag
-and only deinterlace frames marked as interlaced
+ at item enable
+Specify if the deinterlacer should trust the interlaced flag and only
+deinterlace frames marked as interlaced. Accept one of the following
+values:
 
 @table @option
 @item 0
@@ -4445,6 +4455,7 @@ only deinterlace frames marked as interlaced
 @end table
 
 Default value is 0.
+ at end table
 
 @c man end VIDEO FILTERS
 
diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
index 901ef30..5ea7b2f 100644
--- a/libavfilter/vf_yadif.c
+++ b/libavfilter/vf_yadif.c
@@ -20,6 +20,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/cpu.h"
 #include "libavutil/common.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "formats.h"
@@ -296,18 +297,31 @@ static int request_frame(AVFilterLink *link)
     return 0;
 }
 
+#define OFFSET(x) offsetof(YADIFContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption yadif_options[] = {
+    { "mode",        "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS },
+    { "parity",      "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=-1}, -1, 1, FLAGS },
+    { "enable", "specify for which frames to enable the deinterlacer", OFFSET(auto_enable), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
+    {NULL},
+};
+
+AVFILTER_DEFINE_CLASS(yadif);
+
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     YADIFContext *yadif = ctx->priv;
+    static const char *shorthand[] = { "mode", "parity", "enable", NULL };
+    int ret;
 
-    yadif->mode = 0;
-    yadif->parity = -1;
-    yadif->auto_enable = 0;
     yadif->csp = NULL;
 
-    if (args)
-        sscanf(args, "%d:%d:%d",
-               &yadif->mode, &yadif->parity, &yadif->auto_enable);
+    yadif->class = &yadif_class;
+    av_opt_set_defaults(yadif);
+
+    if ((ret = av_opt_set_from_string(yadif, args, shorthand, "=", ":")) < 0)
+        return ret;
 
     yadif->filter_line = filter_line_c;
 
@@ -328,6 +342,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     avfilter_unref_bufferp(&yadif->cur );
     avfilter_unref_bufferp(&yadif->next);
     av_freep(&yadif->temp_line); yadif->temp_line_size = 0;
+    av_opt_free(yadif);
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -413,6 +428,7 @@ AVFilter avfilter_vf_yadif = {
     .query_formats = query_formats,
 
     .inputs    = avfilter_vf_yadif_inputs,
-
     .outputs   = avfilter_vf_yadif_outputs,
+
+    .priv_class = &yadif_class,
 };
diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
index 41691de..2afe7e7 100644
--- a/libavfilter/yadif.h
+++ b/libavfilter/yadif.h
@@ -23,6 +23,8 @@
 #include "avfilter.h"
 
 typedef struct YADIFContext {
+    const AVClass *class;
+
     /**
      * 0: send 1 frame for each frame
      * 1: send 1 frame for each field
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list