History

avfilter/vf_fftfilt: make it possible to evaluate expressions per frame

Paul B Mahol committed 9 years ago

Commit b43cd671 parent 4705a802 files · +55 −17Browse files

Unified · Split

2 files
  1. doc/filters.texi +17 −0
  2. libavfilter/vf_fftfilt.c +38 −17
doc/filters.texi+17−0
@@ -7926,6 +7926,20 @@ Set the frequency domain weight expression for the 1st chroma plane. · 7925 unmodified lines
79267926 @item weight_V
79277927 Set the frequency domain weight expression for the 2nd chroma plane.
79287928
7929+@item eval
7930+Set when the expressions are evaluated.
7931+
7932+It accepts the following values:
7933+@table @samp
7934+@item init
7935+Only evaluate expressions once during the filter initialization.
7936+
7937+@item frame
7938+Evaluate expressions for each incoming frame.
7939+@end table
7940+
7941+Default value is @samp{init}.
7942+
79297943 The filter accepts the following variables:
79307944 @item X
79317945 @item Y
@@ -7934,6 +7948,9 @@ The coordinates of the current sample. · 2 unmodified lines
79347948 @item W
79357949 @item H
79367950 The width and height of the image.
7951+
7952+@item N
7953+The number of input frame, starting from 0.
79377954 @end table
79387955
79397956 @subsection Examples
libavfilter/vf_fftfilt.c+38−17
@@ -33,9 +33,16 @@ · 32 unmodified lines
3333
3434 #define MAX_PLANES 4
3535
36+enum EvalMode {
37+ EVAL_MODE_INIT,
38+ EVAL_MODE_FRAME,
39+ EVAL_MODE_NB
40+};
41+
3642 typedef struct FFTFILTContext {
3743 const AVClass *class;
3844
45+ int eval_mode;
3946 int depth;
4047 int nb_planes;
4148 int planewidth[MAX_PLANES];
@@ -59,8 +66,8 @@ typedef struct FFTFILTContext { · 17 unmodified lines
5966
6067 } FFTFILTContext;
6168
62−static const char *const var_names[] = { "X", "Y", "W", "H", NULL };
63−enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_VARS_NB };
69+static const char *const var_names[] = { "X", "Y", "W", "H", "N", NULL };
70+enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_N, VAR_VARS_NB };
6471
6572 enum { Y = 0, U, V };
6673
@@ -74,6 +81,9 @@ static const AVOption fftfilt_options[] = { · 7 unmodified lines
7481 { "weight_Y", "set luminance expression in Y plane", OFFSET(weight_str[Y]), AV_OPT_TYPE_STRING, {.str = "1"}, CHAR_MIN, CHAR_MAX, FLAGS },
7582 { "weight_U", "set chrominance expression in U plane", OFFSET(weight_str[U]), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
7683 { "weight_V", "set chrominance expression in V plane", OFFSET(weight_str[V]), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
84+ { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
85+ { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" },
86+ { "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
7787 {NULL},
7888 };
7989
@@ -195,12 +205,30 @@ static av_cold int initialize(AVFilterContext *ctx) · 115 unmodified lines
195205 return ret;
196206 }
197207
208+static void do_eval(FFTFILTContext *s, AVFilterLink *inlink, int plane)
209+{
210+ double values[VAR_VARS_NB];
211+ int i, j;
212+
213+ values[VAR_N] = inlink->frame_count_out;
214+ values[VAR_W] = s->planewidth[plane];
215+ values[VAR_H] = s->planeheight[plane];
216+
217+ for (i = 0; i < s->rdft_hlen[plane]; i++) {
218+ values[VAR_X] = i;
219+ for (j = 0; j < s->rdft_vlen[plane]; j++) {
220+ values[VAR_Y] = j;
221+ s->weight[plane][i * s->rdft_vlen[plane] + j] =
222+ av_expr_eval(s->weight_expr[plane], values, s);
223+ }
224+ }
225+}
226+
198227 static int config_props(AVFilterLink *inlink)
199228 {
200229 FFTFILTContext *s = inlink->dst->priv;
201230 const AVPixFmtDescriptor *desc;
202− int rdft_hbits, rdft_vbits, i, j, plane;
203− double values[VAR_VARS_NB];
231+ int rdft_hbits, rdft_vbits, i, plane;
204232
205233 desc = av_pix_fmt_desc_get(inlink->format);
206234 s->depth = desc->comp[0].depth;
@@ -242,21 +270,11 @@ static int config_props(AVFilterLink *inlink) · 35 unmodified lines
242270
243271 /*Luminance value - Array initialization*/
244272 for (plane = 0; plane < 3; plane++) {
245− values[VAR_W] = s->planewidth[plane];
246− values[VAR_H] = s->planeheight[plane];
247−
248273 if(!(s->weight[plane] = av_malloc_array(s->rdft_hlen[plane], s->rdft_vlen[plane] * sizeof(double))))
249274 return AVERROR(ENOMEM);
250− for (i = 0; i < s->rdft_hlen[plane]; i++)
251− {
252− values[VAR_X] = i;
253− for (j = 0; j < s->rdft_vlen[plane]; j++)
254− {
255− values[VAR_Y] = j;
256− s->weight[plane][i * s->rdft_vlen[plane] + j] =
257− av_expr_eval(s->weight_expr[plane], values, s);
258− }
259− }
275+
276+ if (s->eval_mode == EVAL_MODE_INIT)
277+ do_eval(s, inlink, plane);
260278 }
261279 return 0;
262280 }
@@ -281,6 +299,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 18 unmodified lines
281299 int w = s->planewidth[plane];
282300 int h = s->planeheight[plane];
283301
302+ if (s->eval_mode == EVAL_MODE_FRAME)
303+ do_eval(s, inlink, plane);
304+
284305 rdft_horizontal(s, in, w, h, plane);
285306 rdft_vertical(s, h, plane);
286307

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t