Browse code

avfilter: add waveform monitor filter

Paul B Mahol authored on 2015/08/16 20:01:53
Showing 7 changed files
... ...
@@ -33,6 +33,7 @@ version <next>:
33 33
 - aphasemeter filter
34 34
 - showfreqs filter
35 35
 - vectorscope filter
36
+- waveform filter
36 37
 
37 38
 
38 39
 version 2.7:
... ...
@@ -10927,6 +10927,82 @@ Only deinterlace frames marked as interlaced.
10927 10927
 Default value is @samp{all}.
10928 10928
 @end table
10929 10929
 
10930
+@section waveform
10931
+Video waveform monitor.
10932
+
10933
+The waveform monitor plots color component intensity. By default luminance
10934
+only. Each column of the waveform corresponds to a column of pixels in the
10935
+source video.
10936
+
10937
+It accepts the following options:
10938
+
10939
+@table @option
10940
+@item mode, m
10941
+Can be either @code{row}, or @code{column}. Default is @code{column}.
10942
+In row mode, the graph on the left side represents color component value 0 and
10943
+the right side represents value = 255. In column mode, the top side represents
10944
+color component value = 0 and bottom side represents value = 255.
10945
+
10946
+@item intensity, i
10947
+Set intensity. Smaller values are useful to find out how many values of the same
10948
+luminance are distributed across input rows/columns.
10949
+Default value is @code{10}. Allowed range is [1, 255].
10950
+
10951
+@item mirror, r
10952
+Set mirroring mode. @code{0} means unmirrored, @code{1} means mirrored.
10953
+In mirrored mode, higher values will be represented on the left
10954
+side for @code{row} mode and at the top for @code{column} mode. Default is
10955
+@code{1} (mirrored).
10956
+
10957
+@item display, d
10958
+Set display mode.
10959
+It accepts the following values:
10960
+@table @samp
10961
+@item overlay
10962
+Presents information identical to that in the @code{parade}, except
10963
+that the graphs representing color components are superimposed directly
10964
+over one another.
10965
+
10966
+This display mode makes it easier to spot relative differences or similarities
10967
+in overlapping areas of the color components that are supposed to be identical,
10968
+such as neutral whites, grays, or blacks.
10969
+
10970
+@item parade
10971
+Display separate graph for the color components side by side in
10972
+@code{row} mode or one below the other in @code{column} mode.
10973
+
10974
+Using this display mode makes it easy to spot color casts in the highlights
10975
+and shadows of an image, by comparing the contours of the top and the bottom
10976
+graphs of each waveform. Since whites, grays, and blacks are characterized
10977
+by exactly equal amounts of red, green, and blue, neutral areas of the picture
10978
+should display three waveforms of roughly equal width/height. If not, the
10979
+correction is easy to perform by making level adjustments the three waveforms.
10980
+@end table
10981
+Default is @code{parade}.
10982
+
10983
+@item components, c
10984
+Set which color components to display. Default is 1, which means only luminance
10985
+or red color component if input is in RGB colorspace. If is set for example to
10986
+7 it will display all 3 (if) available color components.
10987
+
10988
+@item envelope, e
10989
+@table @samp
10990
+@item none
10991
+No envelope, this is default.
10992
+
10993
+@item instant
10994
+Instant envelope, minimum and maximum values presented in graph will be easily
10995
+visible even with small @code{step} value.
10996
+
10997
+@item peak
10998
+Hold minimum and maximum values presented in graph across time. This way you
10999
+can still spot out of range values without constantly looking at waveforms.
11000
+
11001
+@item peak+instant
11002
+Peak and instant envelope combined together.
11003
+@end table
11004
+@end table
11005
+
10930 11006
 @section xbr
10931 11007
 Apply the xBR high-quality magnification filter which is designed for pixel
10932 11008
 art. It follows a set of edge-detection rules, see
... ...
@@ -232,6 +232,7 @@ OBJS-$(CONFIG_VIDSTABDETECT_FILTER)          += vidstabutils.o vf_vidstabdetect.
232 232
 OBJS-$(CONFIG_VIDSTABTRANSFORM_FILTER)       += vidstabutils.o vf_vidstabtransform.o
233 233
 OBJS-$(CONFIG_VIGNETTE_FILTER)               += vf_vignette.o
234 234
 OBJS-$(CONFIG_W3FDIF_FILTER)                 += vf_w3fdif.o
235
+OBJS-$(CONFIG_WAVEFORM_FILTER)               += vf_waveform.o
235 236
 OBJS-$(CONFIG_XBR_FILTER)                    += vf_xbr.o
236 237
 OBJS-$(CONFIG_YADIF_FILTER)                  += vf_yadif.o
237 238
 OBJS-$(CONFIG_ZMQ_FILTER)                    += f_zmq.o
... ...
@@ -247,6 +247,7 @@ void avfilter_register_all(void)
247 247
     REGISTER_FILTER(VIDSTABTRANSFORM, vidstabtransform, vf);
248 248
     REGISTER_FILTER(VIGNETTE,       vignette,       vf);
249 249
     REGISTER_FILTER(W3FDIF,         w3fdif,         vf);
250
+    REGISTER_FILTER(WAVEFORM,       waveform,       vf);
250 251
     REGISTER_FILTER(XBR,            xbr,            vf);
251 252
     REGISTER_FILTER(YADIF,          yadif,          vf);
252 253
     REGISTER_FILTER(ZMQ,            zmq,            vf);
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/version.h"
31 31
 
32 32
 #define LIBAVFILTER_VERSION_MAJOR  5
33
-#define LIBAVFILTER_VERSION_MINOR  36
33
+#define LIBAVFILTER_VERSION_MINOR  37
34 34
 #define LIBAVFILTER_VERSION_MICRO 100
35 35
 
36 36
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
... ...
@@ -172,6 +172,7 @@ static int config_output(AVFilterLink *outlink)
172 172
         outlink->h = (h->level_height + h->scale_height) * FFMAX(ncomp * h->display_mode, 1);
173 173
         break;
174 174
     case MODE_WAVEFORM:
175
+        av_log(ctx, AV_LOG_WARNING, "This mode is deprecated, please use waveform filter instead.\n");
175 176
         if (h->waveform_mode)
176 177
             outlink->h = 256 * FFMAX(h->ncomp * h->display_mode, 1);
177 178
         else
178 179
new file mode 100644
... ...
@@ -0,0 +1,437 @@
0
+/*
1
+ * Copyright (c) 2012-2015 Paul B Mahol
2
+ * Copyright (c) 2013 Marton Balint
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "libavutil/avassert.h"
22
+#include "libavutil/opt.h"
23
+#include "libavutil/parseutils.h"
24
+#include "libavutil/pixdesc.h"
25
+#include "avfilter.h"
26
+#include "formats.h"
27
+#include "internal.h"
28
+#include "video.h"
29
+
30
+typedef struct WaveformContext {
31
+    const AVClass *class;
32
+    int            mode;
33
+    int            ncomp;
34
+    int            pcomp;
35
+    const uint8_t  *bg_color;
36
+    int            intensity;
37
+    int            mirror;
38
+    int            display;
39
+    int            envelope;
40
+    int            estart[4];
41
+    int            eend[4];
42
+    int            *emax[4];
43
+    int            *emin[4];
44
+    const AVPixFmtDescriptor *desc;
45
+} WaveformContext;
46
+
47
+#define OFFSET(x) offsetof(WaveformContext, x)
48
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
49
+
50
+static const AVOption waveform_options[] = {
51
+    { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
52
+    { "m",    "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
53
+        { "row",    NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
54
+        { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
55
+    { "intensity", "set intensity", OFFSET(intensity), AV_OPT_TYPE_INT, {.i64=10}, 1, 255, FLAGS },
56
+    { "i",         "set intensity", OFFSET(intensity), AV_OPT_TYPE_INT, {.i64=10}, 1, 255, FLAGS },
57
+    { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS },
58
+    { "r",      "set mirroring", OFFSET(mirror), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS },
59
+    { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "display" },
60
+    { "d",       "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "display" },
61
+        { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "display" },
62
+        { "parade",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "display" },
63
+    { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
64
+    { "c",          "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
65
+    { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
66
+    { "e",        "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
67
+        { "none",         NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
68
+        { "instant",      NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
69
+        { "peak",         NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
70
+        { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
71
+    { NULL }
72
+};
73
+
74
+AVFILTER_DEFINE_CLASS(waveform);
75
+
76
+static const enum AVPixelFormat pix_fmts[] = {
77
+     AV_PIX_FMT_GBRP,     AV_PIX_FMT_GBRAP,
78
+     AV_PIX_FMT_YUV422P,  AV_PIX_FMT_YUV420P,
79
+     AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV440P,
80
+     AV_PIX_FMT_YUV411P,  AV_PIX_FMT_YUV410P,
81
+     AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
82
+     AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
83
+     AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
84
+     AV_PIX_FMT_GRAY8,
85
+     AV_PIX_FMT_NONE
86
+};
87
+
88
+static int query_formats(AVFilterContext *ctx)
89
+{
90
+    AVFilterFormats *fmts_list;
91
+
92
+    fmts_list = ff_make_format_list(pix_fmts);
93
+    if (!fmts_list)
94
+        return AVERROR(ENOMEM);
95
+    return ff_set_common_formats(ctx, fmts_list);
96
+}
97
+
98
+static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
99
+static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
100
+
101
+static int config_input(AVFilterLink *inlink)
102
+{
103
+    AVFilterContext *ctx = inlink->dst;
104
+    WaveformContext *s = ctx->priv;
105
+
106
+    s->desc  = av_pix_fmt_desc_get(inlink->format);
107
+    s->ncomp = s->desc->nb_components;
108
+
109
+    switch (inlink->format) {
110
+    case AV_PIX_FMT_GBRAP:
111
+    case AV_PIX_FMT_GBRP:
112
+        s->bg_color = black_gbrp_color;
113
+        break;
114
+    default:
115
+        s->bg_color = black_yuva_color;
116
+    }
117
+
118
+    return 0;
119
+}
120
+
121
+static int config_output(AVFilterLink *outlink)
122
+{
123
+    AVFilterContext *ctx = outlink->src;
124
+    AVFilterLink *inlink = ctx->inputs[0];
125
+    WaveformContext *s = ctx->priv;
126
+    int comp = 0, i, j = 0, p, size, shift;
127
+
128
+    for (i = 0; i < s->ncomp; i++) {
129
+        if ((1 << i) & s->pcomp)
130
+            comp++;
131
+    }
132
+
133
+    for (p = 0; p < 4; p++) {
134
+        av_freep(&s->emax[p]);
135
+        av_freep(&s->emin[p]);
136
+    }
137
+
138
+    if (s->mode) {
139
+        outlink->h = 256 * FFMAX(comp * s->display, 1);
140
+        size = inlink->w * sizeof(int);
141
+    } else {
142
+        outlink->w = 256 * FFMAX(comp * s->display, 1);
143
+        size = inlink->h * sizeof(int);
144
+    }
145
+
146
+    for (p = 0; p < 4; p++) {
147
+        const int is_chroma = (p == 1 || p == 2);
148
+        const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);
149
+        const int shift_h = (is_chroma ? s->desc->log2_chroma_h : 0);
150
+        const int plane = s->desc->comp[p].plane;
151
+        int offset;
152
+
153
+        if (!((1 << p) & s->pcomp))
154
+            continue;
155
+
156
+        shift = s->mode ? shift_h : shift_w;
157
+
158
+        s->emax[plane] = av_malloc(size);
159
+        s->emin[plane] = av_malloc(size);
160
+
161
+        if (!s->emin[plane] || !s->emax[plane])
162
+            return AVERROR(ENOMEM);
163
+
164
+        offset = j++ * 256 * s->display;
165
+        s->estart[plane] = offset >> shift;
166
+        s->eend[plane]   = (offset + 255) >> shift;
167
+        for (i = 0; i < size / sizeof(int); i++) {
168
+            s->emax[plane][i] = s->estart[plane];
169
+            s->emin[plane][i] = s->eend[plane];
170
+        }
171
+    }
172
+
173
+    outlink->sample_aspect_ratio = (AVRational){1,1};
174
+
175
+    return 0;
176
+}
177
+
178
+static void gen_waveform(WaveformContext *s, AVFrame *in, AVFrame *out,
179
+                         int component, int intensity, int offset, int col_mode)
180
+{
181
+    const int plane = s->desc->comp[component].plane;
182
+    const int mirror = s->mirror;
183
+    const int is_chroma = (component == 1 || component == 2);
184
+    const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);
185
+    const int shift_h = (is_chroma ? s->desc->log2_chroma_h : 0);
186
+    const int src_linesize = in->linesize[plane];
187
+    const int dst_linesize = out->linesize[plane];
188
+    const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
189
+    const int max = 255 - intensity;
190
+    const int src_h = FF_CEIL_RSHIFT(in->height, shift_h);
191
+    const int src_w = FF_CEIL_RSHIFT(in->width, shift_w);
192
+    const uint8_t *src_data = in->data[plane];
193
+    uint8_t *dst_data = out->data[plane] + (col_mode ? (offset >> shift_h) * dst_linesize : offset >> shift_w);
194
+    uint8_t * const dst_bottom_line = dst_data + dst_linesize * ((256 >> shift_h) - 1);
195
+    uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
196
+    const uint8_t *p;
197
+    uint8_t *dst;
198
+    int y;
199
+
200
+    if (!col_mode && mirror)
201
+        dst_data += 256 >> shift_w;
202
+    for (y = 0; y < src_h; y++) {
203
+        const uint8_t *src_data_end = src_data + src_w;
204
+        dst = dst_line;
205
+        for (p = src_data; p < src_data_end; p++) {
206
+            uint8_t *target;
207
+            if (col_mode) {
208
+                target = dst++ + dst_signed_linesize * (*p >> shift_h);
209
+            } else {
210
+                if (mirror)
211
+                    target = dst_data - (*p >> shift_w) - 1;
212
+                else
213
+                    target = dst_data + (*p >> shift_w);
214
+            }
215
+            if (*target <= max)
216
+                *target += intensity;
217
+            else
218
+                *target = 255;
219
+        }
220
+        src_data += src_linesize;
221
+        dst_data += dst_linesize;
222
+    }
223
+}
224
+
225
+static void gen_envelope_instant(WaveformContext *s, AVFrame *out, int component)
226
+{
227
+    const int plane = s->desc->comp[component].plane;
228
+    const int dst_linesize = out->linesize[plane];
229
+    const uint8_t bg = s->bg_color[plane];
230
+    const int is_chroma = (component == 1 || component == 2);
231
+    const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);
232
+    const int shift_h = (is_chroma ? s->desc->log2_chroma_h : 0);
233
+    const int dst_h = FF_CEIL_RSHIFT(out->height, shift_h);
234
+    const int dst_w = FF_CEIL_RSHIFT(out->width, shift_w);
235
+    const int start = s->estart[plane];
236
+    const int end = s->eend[plane];
237
+    uint8_t *dst;
238
+    int x, y;
239
+
240
+    if (!s->mode) {
241
+        for (y = 0; y < dst_h; y++) {
242
+            dst = out->data[plane] + y * dst_linesize;
243
+            for (x = start; x < end; x++) {
244
+                if (dst[x] != bg) {
245
+                    dst[x] = 255;
246
+                    break;
247
+                }
248
+            }
249
+            for (x = end - 1; x >= start; x--) {
250
+                if (dst[x] != bg) {
251
+                    dst[x] = 255;
252
+                    break;
253
+                }
254
+            }
255
+        }
256
+    } else {
257
+        for (x = 0; x < dst_w; x++) {
258
+            for (y = start; y < end; y++) {
259
+                dst = out->data[plane] + y * dst_linesize + x;
260
+                if (dst[0] != bg) {
261
+                    dst[0] = 255;
262
+                    break;
263
+                }
264
+            }
265
+            for (y = end - 1; y >= start; y--) {
266
+                dst = out->data[plane] + y * dst_linesize + x;
267
+                if (dst[0] != bg) {
268
+                    dst[0] = 255;
269
+                    break;
270
+                }
271
+            }
272
+        }
273
+    }
274
+}
275
+
276
+static void gen_envelope_peak(WaveformContext *s, AVFrame *out, int component)
277
+{
278
+    const int plane = s->desc->comp[component].plane;
279
+    const int dst_linesize = out->linesize[plane];
280
+    const uint8_t bg = s->bg_color[plane];
281
+    const int is_chroma = (component == 1 || component == 2);
282
+    const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);
283
+    const int shift_h = (is_chroma ? s->desc->log2_chroma_h : 0);
284
+    const int dst_h = FF_CEIL_RSHIFT(out->height, shift_h);
285
+    const int dst_w = FF_CEIL_RSHIFT(out->width, shift_w);
286
+    const int start = s->estart[plane];
287
+    const int end = s->eend[plane];
288
+    int *emax = s->emax[plane];
289
+    int *emin = s->emin[plane];
290
+    uint8_t *dst;
291
+    int x, y;
292
+
293
+    if (!s->mode) {
294
+        for (y = 0; y < dst_h; y++) {
295
+            dst = out->data[plane] + y * dst_linesize;
296
+            for (x = start; x < end && x < emin[y]; x++) {
297
+                if (dst[x] != bg) {
298
+                    emin[y] = x;
299
+                    break;
300
+                }
301
+            }
302
+            for (x = end - 1; x >= start && x >= emax[y]; x--) {
303
+                if (dst[x] != bg) {
304
+                    emax[y] = x;
305
+                    break;
306
+                }
307
+            }
308
+        }
309
+
310
+        if (s->envelope == 3)
311
+            gen_envelope_instant(s, out, component);
312
+
313
+        for (y = 0; y < dst_h; y++) {
314
+            dst = out->data[plane] + y * dst_linesize + emin[y];
315
+            dst[0] = 255;
316
+            dst = out->data[plane] + y * dst_linesize + emax[y];
317
+            dst[0] = 255;
318
+        }
319
+    } else {
320
+        for (x = 0; x < dst_w; x++) {
321
+            for (y = start; y < end && y < emin[x]; y++) {
322
+                dst = out->data[plane] + y * dst_linesize + x;
323
+                if (dst[0] != bg) {
324
+                    emin[x] = y;
325
+                    break;
326
+                }
327
+            }
328
+            for (y = end - 1; y >= start && y >= emax[x]; y--) {
329
+                dst = out->data[plane] + y * dst_linesize + x;
330
+                if (dst[0] != bg) {
331
+                    emax[x] = y;
332
+                    break;
333
+                }
334
+            }
335
+        }
336
+
337
+        if (s->envelope == 3)
338
+            gen_envelope_instant(s, out, component);
339
+
340
+        for (x = 0; x < dst_w; x++) {
341
+            dst = out->data[plane] + emin[x] * dst_linesize + x;
342
+            dst[0] = 255;
343
+            dst = out->data[plane] + emax[x] * dst_linesize + x;
344
+            dst[0] = 255;
345
+        }
346
+    }
347
+}
348
+
349
+static void gen_envelope(WaveformContext *s, AVFrame *out, int component)
350
+{
351
+    if (s->envelope == 0) {
352
+        return;
353
+    } else if (s->envelope == 1) {
354
+        gen_envelope_instant(s, out, component);
355
+    } else {
356
+        gen_envelope_peak(s, out, component);
357
+    }
358
+}
359
+
360
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
361
+{
362
+    AVFilterContext *ctx  = inlink->dst;
363
+    WaveformContext *s    = ctx->priv;
364
+    AVFilterLink *outlink = ctx->outputs[0];
365
+    AVFrame *out;
366
+    int i,  k;
367
+
368
+    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
369
+    if (!out) {
370
+        av_frame_free(&in);
371
+        return AVERROR(ENOMEM);
372
+    }
373
+    out->pts = in->pts;
374
+
375
+    for (k = 0; k < s->ncomp; k++) {
376
+        const int is_chroma = (k == 1 || k == 2);
377
+        const int dst_h = FF_CEIL_RSHIFT(outlink->h, (is_chroma ? s->desc->log2_chroma_h : 0));
378
+        const int dst_w = FF_CEIL_RSHIFT(outlink->w, (is_chroma ? s->desc->log2_chroma_w : 0));
379
+        for (i = 0; i < dst_h ; i++)
380
+            memset(out->data[s->desc->comp[k].plane] +
381
+                   i * out->linesize[s->desc->comp[k].plane],
382
+                   s->bg_color[k], dst_w);
383
+    }
384
+
385
+    for (k = 0, i = 0; k < s->ncomp; k++) {
386
+        if ((1 << k) & s->pcomp) {
387
+            const int offset = i++ * 256 * s->display;
388
+            gen_waveform(s, in, out, k, s->intensity, offset, s->mode);
389
+            gen_envelope(s, out, k);
390
+        }
391
+    }
392
+
393
+    av_frame_free(&in);
394
+    return ff_filter_frame(outlink, out);
395
+}
396
+
397
+static av_cold void uninit(AVFilterContext *ctx)
398
+{
399
+    WaveformContext *s = ctx->priv;
400
+    int p;
401
+
402
+    for (p = 0; p < 4; p++) {
403
+        av_freep(&s->emax[p]);
404
+        av_freep(&s->emin[p]);
405
+    }
406
+}
407
+
408
+static const AVFilterPad inputs[] = {
409
+    {
410
+        .name         = "default",
411
+        .type         = AVMEDIA_TYPE_VIDEO,
412
+        .filter_frame = filter_frame,
413
+        .config_props = config_input,
414
+    },
415
+    { NULL }
416
+};
417
+
418
+static const AVFilterPad outputs[] = {
419
+    {
420
+        .name         = "default",
421
+        .type         = AVMEDIA_TYPE_VIDEO,
422
+        .config_props = config_output,
423
+    },
424
+    { NULL }
425
+};
426
+
427
+AVFilter ff_vf_waveform = {
428
+    .name          = "waveform",
429
+    .description   = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
430
+    .priv_size     = sizeof(WaveformContext),
431
+    .priv_class    = &waveform_class,
432
+    .query_formats = query_formats,
433
+    .uninit        = uninit,
434
+    .inputs        = inputs,
435
+    .outputs       = outputs,
436
+};