Browse code

lavfi/decimate: use named options

Stefano Sabatini authored on 2013/02/20 23:02:42
Showing 3 changed files
... ...
@@ -2069,11 +2069,14 @@ for very-low-bitrate encoding (e.g. streaming over dialup modem), but
2069 2069
 it could in theory be used for fixing movies that were
2070 2070
 inverse-telecined incorrectly.
2071 2071
 
2072
-It accepts the following parameters:
2073
-@var{max}:@var{hi}:@var{lo}:@var{frac}.
2072
+The filter accepts parameters as a list of @var{key}=@var{value}
2073
+pairs, separated by ":". If the key of the first options is omitted,
2074
+the arguments are interpreted according to the syntax:
2075
+@option{max}:@option{hi}:@option{lo}:@option{frac}.
2074 2076
 
2075
-@table @option
2077
+A description of the accepted options follows.
2076 2078
 
2079
+@table @option
2077 2080
 @item max
2078 2081
 Set the maximum number of consecutive frames which can be dropped (if
2079 2082
 positive), or the minimum interval between dropped frames (if
... ...
@@ -2082,20 +2085,22 @@ number of previous sequentially dropped frames.
2082 2082
 
2083 2083
 Default value is 0.
2084 2084
 
2085
-@item hi, lo, frac
2085
+@item hi
2086
+@item lo
2087
+@item frac
2086 2088
 Set the dropping threshold values.
2087 2089
 
2088
-Values for @var{hi} and @var{lo} are for 8x8 pixel blocks and
2090
+Values for @option{hi} and @option{lo} are for 8x8 pixel blocks and
2089 2091
 represent actual pixel value differences, so a threshold of 64
2090 2092
 corresponds to 1 unit of difference for each pixel, or the same spread
2091 2093
 out differently over the block.
2092 2094
 
2093 2095
 A frame is a candidate for dropping if no 8x8 blocks differ by more
2094
-than a threshold of @var{hi}, and if no more than @var{frac} blocks (1
2095
-meaning the whole image) differ by more than a threshold of @var{lo}.
2096
+than a threshold of @option{hi}, and if no more than @option{frac} blocks (1
2097
+meaning the whole image) differ by more than a threshold of @option{lo}.
2096 2098
 
2097
-Default value for @var{hi} is 64*12, default value for @var{lo} is
2098
-64*5, and default value for @var{frac} is 0.33.
2099
+Default value for @option{hi} is 64*12, default value for @option{lo} is
2100
+64*5, and default value for @option{frac} is 0.33.
2099 2101
 @end table
2100 2102
 
2101 2103
 @section delogo
... ...
@@ -30,7 +30,7 @@
30 30
 
31 31
 #define LIBAVFILTER_VERSION_MAJOR  3
32 32
 #define LIBAVFILTER_VERSION_MINOR  38
33
-#define LIBAVFILTER_VERSION_MICRO 103
33
+#define LIBAVFILTER_VERSION_MICRO 104
34 34
 
35 35
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 36
                                                LIBAVFILTER_VERSION_MINOR, \
... ...
@@ -24,6 +24,7 @@
24 24
  * Rich Felker.
25 25
  */
26 26
 
27
+#include "libavutil/opt.h"
27 28
 #include "libavutil/pixdesc.h"
28 29
 #include "libavutil/timestamp.h"
29 30
 #include "libavcodec/dsputil.h"
... ...
@@ -33,6 +34,7 @@
33 33
 #include "video.h"
34 34
 
35 35
 typedef struct {
36
+    const AVClass *class;
36 37
     int lo, hi;                    ///< lower and higher threshold number of differences
37 38
                                    ///< values for 8x8 blocks
38 39
 
... ...
@@ -50,6 +52,20 @@ typedef struct {
50 50
     AVCodecContext *avctx;         ///< codec context required for the DSPContext
51 51
 } DecimateContext;
52 52
 
53
+#define OFFSET(x) offsetof(DecimateContext, x)
54
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
55
+
56
+static const AVOption decimate_options[] = {
57
+    { "max",  "set the maximum number of consecutive dropped frames (positive), or the minimum interval between dropped frames (negative)",
58
+      OFFSET(max_drop_count), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS },
59
+    { "hi",   "set high dropping threshold", OFFSET(hi), AV_OPT_TYPE_INT, {.i64=64*12}, INT_MIN, INT_MAX, FLAGS },
60
+    { "lo",   "set low dropping threshold", OFFSET(lo), AV_OPT_TYPE_INT, {.i64=64*5}, INT_MIN, INT_MAX, FLAGS },
61
+    { "frac", "set fraction dropping threshold",  OFFSET(frac), AV_OPT_TYPE_FLOAT, {.dbl=0.33}, 0, 1, FLAGS },
62
+    { NULL }
63
+};
64
+
65
+AVFILTER_DEFINE_CLASS(decimate);
66
+
53 67
 /**
54 68
  * Return 1 if the two planes are different, 0 otherwise.
55 69
  */
... ...
@@ -116,29 +132,14 @@ static int decimate_frame(AVFilterContext *ctx,
116 116
 static av_cold int init(AVFilterContext *ctx, const char *args)
117 117
 {
118 118
     DecimateContext *decimate = ctx->priv;
119
+    static const char *shorthand[] = { "max", "hi", "lo", "frac", NULL };
120
+    int ret;
119 121
 
120
-    /* set default values */
121
-    decimate->drop_count = decimate->max_drop_count = 0;
122
-    decimate->lo = 64*5;
123
-    decimate->hi = 64*12;
124
-    decimate->frac = 0.33;
125
-
126
-    if (args) {
127
-        char c1, c2, c3, c4;
128
-        int n = sscanf(args, "%d%c%d%c%d%c%f%c",
129
-                       &decimate->max_drop_count, &c1,
130
-                       &decimate->hi, &c2, &decimate->lo, &c3,
131
-                       &decimate->frac, &c4);
132
-        if (n != 1 &&
133
-            (n != 3 || c1 != ':') &&
134
-            (n != 5 || c1 != ':' || c2 != ':') &&
135
-            (n != 7 || c1 != ':' || c2 != ':' || c3 != ':')) {
136
-            av_log(ctx, AV_LOG_ERROR,
137
-                   "Invalid syntax for argument '%s': "
138
-                   "must be in the form 'max:hi:lo:frac'\n", args);
139
-            return AVERROR(EINVAL);
140
-        }
141
-    }
122
+    decimate->class = &decimate_class;
123
+    av_opt_set_defaults(decimate);
124
+
125
+    if ((ret = av_opt_set_from_string(decimate, args, shorthand, "=", ":")) < 0)
126
+        return ret;
142 127
 
143 128
     av_log(ctx, AV_LOG_VERBOSE, "max_drop_count:%d hi:%d lo:%d frac:%f\n",
144 129
            decimate->max_drop_count, decimate->hi, decimate->lo, decimate->frac);
... ...
@@ -156,6 +157,7 @@ static av_cold void uninit(AVFilterContext *ctx)
156 156
     DecimateContext *decimate = ctx->priv;
157 157
     avfilter_unref_bufferp(&decimate->ref);
158 158
     avcodec_close(decimate->avctx);
159
+    av_opt_free(decimate);
159 160
     av_freep(&decimate->avctx);
160 161
 }
161 162
 
... ...
@@ -260,4 +262,5 @@ AVFilter avfilter_vf_decimate = {
260 260
     .query_formats = query_formats,
261 261
     .inputs        = decimate_inputs,
262 262
     .outputs       = decimate_outputs,
263
+    .priv_class    = &decimate_class,
263 264
 };