]> git.sesse.net Git - ffmpeg/blob - libavfilter/avf_showspectrum.c
lavfi/avf_showspectrum: replace pow(x, 0.25) by sqrt(sqrt(x))
[ffmpeg] / libavfilter / avf_showspectrum.c
1 /*
2  * Copyright (c) 2012-2013 Clément Bœsch
3  * Copyright (c) 2013 Rudolf Polzer <divverent@xonotic.org>
4  * Copyright (c) 2015 Paul B Mahol
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 /**
24  * @file
25  * audio to spectrum (video) transmedia filter, based on ffplay rdft showmode
26  * (by Michael Niedermayer) and lavfi/avf_showwaves (by Stefano Sabatini).
27  */
28
29 #include <math.h>
30
31 #include "libavcodec/avfft.h"
32 #include "libavutil/audio_fifo.h"
33 #include "libavutil/avassert.h"
34 #include "libavutil/channel_layout.h"
35 #include "libavutil/opt.h"
36 #include "audio.h"
37 #include "video.h"
38 #include "avfilter.h"
39 #include "internal.h"
40 #include "window_func.h"
41
42 enum DisplayMode  { COMBINED, SEPARATE, NB_MODES };
43 enum DisplayScale { LINEAR, SQRT, CBRT, LOG, FOURTHRT, FIFTHRT, NB_SCALES };
44 enum ColorMode    { CHANNEL, INTENSITY, RAINBOW, MORELAND, NEBULAE, FIRE, FIERY, FRUIT, NB_CLMODES };
45 enum SlideMode    { REPLACE, SCROLL, FULLFRAME, RSCROLL, NB_SLIDES };
46 enum Orientation  { VERTICAL, HORIZONTAL, NB_ORIENTATIONS };
47
48 typedef struct {
49     const AVClass *class;
50     int w, h;
51     AVFrame *outpicref;
52     int nb_display_channels;
53     int orientation;
54     int channel_width;
55     int channel_height;
56     int sliding;                ///< 1 if sliding mode, 0 otherwise
57     int mode;                   ///< channel display mode
58     int color_mode;             ///< display color scheme
59     int scale;
60     float saturation;           ///< color saturation multiplier
61     int xpos;                   ///< x position (current column)
62     FFTContext *fft;            ///< Fast Fourier Transform context
63     int fft_bits;               ///< number of bits (FFT window size = 1<<fft_bits)
64     FFTComplex **fft_data;      ///< bins holder for each (displayed) channels
65     float *window_func_lut;     ///< Window function LUT
66     float **magnitudes;
67     int win_func;
68     int win_size;
69     double win_scale;
70     float overlap;
71     float gain;
72     int skip_samples;
73     float *combine_buffer;      ///< color combining buffer (3 * h items)
74     AVAudioFifo *fifo;
75     int64_t pts;
76     int single_pic;
77 } ShowSpectrumContext;
78
79 #define OFFSET(x) offsetof(ShowSpectrumContext, x)
80 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
81
82 static const AVOption showspectrum_options[] = {
83     { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x512"}, 0, 0, FLAGS },
84     { "s",    "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x512"}, 0, 0, FLAGS },
85     { "slide", "set sliding mode", OFFSET(sliding), AV_OPT_TYPE_INT, {.i64 = 0}, 0, NB_SLIDES-1, FLAGS, "slide" },
86         { "replace", "replace old columns with new", 0, AV_OPT_TYPE_CONST, {.i64=REPLACE}, 0, 0, FLAGS, "slide" },
87         { "scroll", "scroll from right to left", 0, AV_OPT_TYPE_CONST, {.i64=SCROLL}, 0, 0, FLAGS, "slide" },
88         { "rscroll", "scroll from left to right", 0, AV_OPT_TYPE_CONST, {.i64=RSCROLL}, 0, 0, FLAGS, "slide" },
89         { "fullframe", "return full frames", 0, AV_OPT_TYPE_CONST, {.i64=FULLFRAME}, 0, 0, FLAGS, "slide" },
90     { "mode", "set channel display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=COMBINED}, COMBINED, NB_MODES-1, FLAGS, "mode" },
91         { "combined", "combined mode", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "mode" },
92         { "separate", "separate mode", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "mode" },
93     { "color", "set channel coloring", OFFSET(color_mode), AV_OPT_TYPE_INT, {.i64=CHANNEL}, CHANNEL, NB_CLMODES-1, FLAGS, "color" },
94         { "channel",   "separate color for each channel", 0, AV_OPT_TYPE_CONST, {.i64=CHANNEL},   0, 0, FLAGS, "color" },
95         { "intensity", "intensity based coloring",        0, AV_OPT_TYPE_CONST, {.i64=INTENSITY}, 0, 0, FLAGS, "color" },
96         { "rainbow",   "rainbow based coloring",          0, AV_OPT_TYPE_CONST, {.i64=RAINBOW},   0, 0, FLAGS, "color" },
97         { "moreland",  "moreland based coloring",         0, AV_OPT_TYPE_CONST, {.i64=MORELAND},  0, 0, FLAGS, "color" },
98         { "nebulae",   "nebulae based coloring",          0, AV_OPT_TYPE_CONST, {.i64=NEBULAE},   0, 0, FLAGS, "color" },
99         { "fire",      "fire based coloring",             0, AV_OPT_TYPE_CONST, {.i64=FIRE},      0, 0, FLAGS, "color" },
100         { "fiery",     "fiery based coloring",            0, AV_OPT_TYPE_CONST, {.i64=FIERY},     0, 0, FLAGS, "color" },
101         { "fruit",     "fruit based coloring",            0, AV_OPT_TYPE_CONST, {.i64=FRUIT},     0, 0, FLAGS, "color" },
102     { "scale", "set display scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=SQRT}, LINEAR, NB_SCALES-1, FLAGS, "scale" },
103         { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SQRT},   0, 0, FLAGS, "scale" },
104         { "cbrt", "cubic root",  0, AV_OPT_TYPE_CONST, {.i64=CBRT},   0, 0, FLAGS, "scale" },
105         { "4thrt","4th root",    0, AV_OPT_TYPE_CONST, {.i64=FOURTHRT}, 0, 0, FLAGS, "scale" },
106         { "5thrt","5th root",    0, AV_OPT_TYPE_CONST, {.i64=FIFTHRT},  0, 0, FLAGS, "scale" },
107         { "log",  "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=LOG},    0, 0, FLAGS, "scale" },
108         { "lin",  "linear",      0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "scale" },
109     { "saturation", "color saturation multiplier", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl = 1}, -10, 10, FLAGS },
110     { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func" },
111         { "rect",     "Rectangular",      0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT},     0, 0, FLAGS, "win_func" },
112         { "bartlett", "Bartlett",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
113         { "hann",     "Hann",             0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING},  0, 0, FLAGS, "win_func" },
114         { "hanning",  "Hanning",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING},  0, 0, FLAGS, "win_func" },
115         { "hamming",  "Hamming",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING},  0, 0, FLAGS, "win_func" },
116         { "blackman", "Blackman",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
117         { "welch",    "Welch",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_WELCH},    0, 0, FLAGS, "win_func" },
118         { "flattop",  "Flat-top",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_FLATTOP},  0, 0, FLAGS, "win_func" },
119         { "bharris",  "Blackman-Harris",  0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHARRIS},  0, 0, FLAGS, "win_func" },
120         { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
121         { "bhann",    "Bartlett-Hann",    0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHANN},    0, 0, FLAGS, "win_func" },
122         { "sine",     "Sine",             0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE},     0, 0, FLAGS, "win_func" },
123         { "nuttall",  "Nuttall",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL},  0, 0, FLAGS, "win_func" },
124         { "lanczos",  "Lanczos",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS},  0, 0, FLAGS, "win_func" },
125         { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
126         { "tukey",    "Tukey",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY},    0, 0, FLAGS, "win_func" },
127     { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
128         { "vertical",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL},   0, 0, FLAGS, "orientation" },
129         { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
130     { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl = 0}, 0, 1, FLAGS },
131     { "gain", "set scale gain", OFFSET(gain), AV_OPT_TYPE_FLOAT, {.dbl = 1}, 0, 128, FLAGS },
132     { NULL }
133 };
134
135 AVFILTER_DEFINE_CLASS(showspectrum);
136
137 static const struct ColorTable {
138     float a, y, u, v;
139 } color_table[][8] = {
140     [INTENSITY] = {
141     {    0,                  0,                  0,                   0 },
142     { 0.13, .03587126228984074,  .1573300977624594, -.02548747583751842 },
143     { 0.30, .18572281794568020,  .1772436246393981,  .17475554840414750 },
144     { 0.60, .28184980583656130, -.1593064119945782,  .47132074554608920 },
145     { 0.73, .65830621175547810, -.3716070802232764,  .24352759331252930 },
146     { 0.78, .76318535758242900, -.4307467689263783,  .16866496622310430 },
147     { 0.91, .95336363636363640, -.2045454545454546,  .03313636363636363 },
148     {    1,                  1,                  0,                   0 }},
149     [RAINBOW] = {
150     {    0,                  0,                  0,                   0 },
151     { 0.13,            44/256.,     (189-128)/256.,      (138-128)/256. },
152     { 0.25,            29/256.,     (186-128)/256.,      (119-128)/256. },
153     { 0.38,           119/256.,     (194-128)/256.,       (53-128)/256. },
154     { 0.60,           111/256.,      (73-128)/256.,       (59-128)/256. },
155     { 0.73,           205/256.,      (19-128)/256.,      (149-128)/256. },
156     { 0.86,           135/256.,      (83-128)/256.,      (200-128)/256. },
157     {    1,            73/256.,      (95-128)/256.,      (225-128)/256. }},
158     [MORELAND] = {
159     {    0,            44/256.,     (181-128)/256.,      (112-128)/256. },
160     { 0.13,           126/256.,     (177-128)/256.,      (106-128)/256. },
161     { 0.25,           164/256.,     (163-128)/256.,      (109-128)/256. },
162     { 0.38,           200/256.,     (140-128)/256.,      (120-128)/256. },
163     { 0.60,           201/256.,     (117-128)/256.,      (141-128)/256. },
164     { 0.73,           177/256.,     (103-128)/256.,      (165-128)/256. },
165     { 0.86,           136/256.,     (100-128)/256.,      (183-128)/256. },
166     {    1,            68/256.,     (117-128)/256.,      (203-128)/256. }},
167     [NEBULAE] = {
168     {    0,            10/256.,     (134-128)/256.,      (132-128)/256. },
169     { 0.23,            21/256.,     (137-128)/256.,      (130-128)/256. },
170     { 0.45,            35/256.,     (134-128)/256.,      (134-128)/256. },
171     { 0.57,            51/256.,     (130-128)/256.,      (139-128)/256. },
172     { 0.67,           104/256.,     (116-128)/256.,      (162-128)/256. },
173     { 0.77,           120/256.,     (105-128)/256.,      (188-128)/256. },
174     { 0.87,           140/256.,     (105-128)/256.,      (188-128)/256. },
175     {    1,                  1,                  0,                   0 }},
176     [FIRE] = {
177     {    0,                  0,                  0,                   0 },
178     { 0.23,            44/256.,     (132-128)/256.,      (127-128)/256. },
179     { 0.45,            62/256.,     (116-128)/256.,      (140-128)/256. },
180     { 0.57,            75/256.,     (105-128)/256.,      (152-128)/256. },
181     { 0.67,            95/256.,      (91-128)/256.,      (166-128)/256. },
182     { 0.77,           126/256.,      (74-128)/256.,      (172-128)/256. },
183     { 0.87,           164/256.,      (73-128)/256.,      (162-128)/256. },
184     {    1,                  1,                  0,                   0 }},
185     [FIERY] = {
186     {    0,                  0,                  0,                   0 },
187     { 0.23,            36/256.,     (116-128)/256.,      (163-128)/256. },
188     { 0.45,            52/256.,     (102-128)/256.,      (200-128)/256. },
189     { 0.57,           116/256.,      (84-128)/256.,      (196-128)/256. },
190     { 0.67,           157/256.,      (67-128)/256.,      (181-128)/256. },
191     { 0.77,           193/256.,      (40-128)/256.,      (155-128)/256. },
192     { 0.87,           221/256.,     (101-128)/256.,      (134-128)/256. },
193     {    1,                  1,                  0,                   0 }},
194     [FRUIT] = {
195     {    0,                  0,                  0,                   0 },
196     { 0.20,            29/256.,     (136-128)/256.,      (119-128)/256. },
197     { 0.30,            60/256.,     (119-128)/256.,       (90-128)/256. },
198     { 0.40,            85/256.,      (91-128)/256.,       (85-128)/256. },
199     { 0.50,           116/256.,      (70-128)/256.,      (105-128)/256. },
200     { 0.60,           151/256.,      (50-128)/256.,      (146-128)/256. },
201     { 0.70,           191/256.,      (63-128)/256.,      (178-128)/256. },
202     {    1,            98/256.,      (80-128)/256.,      (221-128)/256. }},
203 };
204
205 static av_cold void uninit(AVFilterContext *ctx)
206 {
207     ShowSpectrumContext *s = ctx->priv;
208     int i;
209
210     av_freep(&s->combine_buffer);
211     av_fft_end(s->fft);
212     if (s->fft_data) {
213         for (i = 0; i < s->nb_display_channels; i++)
214             av_freep(&s->fft_data[i]);
215     }
216     av_freep(&s->fft_data);
217     av_freep(&s->window_func_lut);
218     if (s->magnitudes) {
219         for (i = 0; i < s->nb_display_channels; i++)
220             av_freep(&s->magnitudes[i]);
221     }
222     av_freep(&s->magnitudes);
223     av_frame_free(&s->outpicref);
224     av_audio_fifo_free(s->fifo);
225 }
226
227 static int query_formats(AVFilterContext *ctx)
228 {
229     AVFilterFormats *formats = NULL;
230     AVFilterChannelLayouts *layouts = NULL;
231     AVFilterLink *inlink = ctx->inputs[0];
232     AVFilterLink *outlink = ctx->outputs[0];
233     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE };
234     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE };
235     int ret;
236
237     /* set input audio formats */
238     formats = ff_make_format_list(sample_fmts);
239     if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
240         return ret;
241
242     layouts = ff_all_channel_layouts();
243     if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
244         return ret;
245
246     formats = ff_all_samplerates();
247     if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
248         return ret;
249
250     /* set output video format */
251     formats = ff_make_format_list(pix_fmts);
252     if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
253         return ret;
254
255     return 0;
256 }
257
258 static int config_output(AVFilterLink *outlink)
259 {
260     AVFilterContext *ctx = outlink->src;
261     AVFilterLink *inlink = ctx->inputs[0];
262     ShowSpectrumContext *s = ctx->priv;
263     int i, fft_bits, h, w;
264     float overlap;
265
266     if (!strcmp(ctx->filter->name, "showspectrumpic"))
267         s->single_pic = 1;
268
269     outlink->w = s->w;
270     outlink->h = s->h;
271
272     h = (s->mode == COMBINED || s->orientation == HORIZONTAL) ? outlink->h : outlink->h / inlink->channels;
273     w = (s->mode == COMBINED || s->orientation == VERTICAL)   ? outlink->w : outlink->w / inlink->channels;
274     s->channel_height = h;
275     s->channel_width  = w;
276
277     if (s->orientation == VERTICAL) {
278         /* FFT window size (precision) according to the requested output frame height */
279         for (fft_bits = 1; 1 << fft_bits < 2 * h; fft_bits++);
280     } else {
281         /* FFT window size (precision) according to the requested output frame width */
282         for (fft_bits = 1; 1 << fft_bits < 2 * w; fft_bits++);
283     }
284     s->win_size = 1 << fft_bits;
285
286     /* (re-)configuration if the video output changed (or first init) */
287     if (fft_bits != s->fft_bits) {
288         AVFrame *outpicref;
289
290         av_fft_end(s->fft);
291         s->fft = av_fft_init(fft_bits, 0);
292         if (!s->fft) {
293             av_log(ctx, AV_LOG_ERROR, "Unable to create FFT context. "
294                    "The window size might be too high.\n");
295             return AVERROR(EINVAL);
296         }
297         s->fft_bits = fft_bits;
298
299         /* FFT buffers: x2 for each (display) channel buffer.
300          * Note: we use free and malloc instead of a realloc-like function to
301          * make sure the buffer is aligned in memory for the FFT functions. */
302         for (i = 0; i < s->nb_display_channels; i++)
303             av_freep(&s->fft_data[i]);
304         av_freep(&s->fft_data);
305         s->nb_display_channels = inlink->channels;
306
307         s->magnitudes = av_calloc(s->nb_display_channels, sizeof(*s->magnitudes));
308         if (!s->magnitudes)
309             return AVERROR(ENOMEM);
310         for (i = 0; i < s->nb_display_channels; i++) {
311             s->magnitudes[i] = av_calloc(s->orientation == VERTICAL ? s->h : s->w, sizeof(**s->magnitudes));
312             if (!s->magnitudes[i])
313                 return AVERROR(ENOMEM);
314         }
315
316         s->fft_data = av_calloc(s->nb_display_channels, sizeof(*s->fft_data));
317         if (!s->fft_data)
318             return AVERROR(ENOMEM);
319         for (i = 0; i < s->nb_display_channels; i++) {
320             s->fft_data[i] = av_calloc(s->win_size, sizeof(**s->fft_data));
321             if (!s->fft_data[i])
322                 return AVERROR(ENOMEM);
323         }
324
325         /* pre-calc windowing function */
326         s->window_func_lut =
327             av_realloc_f(s->window_func_lut, s->win_size,
328                          sizeof(*s->window_func_lut));
329         if (!s->window_func_lut)
330             return AVERROR(ENOMEM);
331         ff_generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
332         if (s->overlap == 1)
333             s->overlap = overlap;
334         s->skip_samples = (1. - s->overlap) * s->win_size;
335         if (s->skip_samples < 1) {
336             av_log(ctx, AV_LOG_ERROR, "overlap %f too big\n", s->overlap);
337             return AVERROR(EINVAL);
338         }
339
340         for (s->win_scale = 0, i = 0; i < s->win_size; i++) {
341             s->win_scale += s->window_func_lut[i] * s->window_func_lut[i];
342         }
343         s->win_scale = 1. / sqrt(s->win_scale);
344
345         /* prepare the initial picref buffer (black frame) */
346         av_frame_free(&s->outpicref);
347         s->outpicref = outpicref =
348             ff_get_video_buffer(outlink, outlink->w, outlink->h);
349         if (!outpicref)
350             return AVERROR(ENOMEM);
351         outlink->sample_aspect_ratio = (AVRational){1,1};
352         for (i = 0; i < outlink->h; i++) {
353             memset(outpicref->data[0] + i * outpicref->linesize[0],   0, outlink->w);
354             memset(outpicref->data[1] + i * outpicref->linesize[1], 128, outlink->w);
355             memset(outpicref->data[2] + i * outpicref->linesize[2], 128, outlink->w);
356         }
357     }
358
359     if ((s->orientation == VERTICAL   && s->xpos >= outlink->w) ||
360         (s->orientation == HORIZONTAL && s->xpos >= outlink->h))
361         s->xpos = 0;
362
363     outlink->frame_rate = av_make_q(inlink->sample_rate, s->win_size * (1.-s->overlap));
364     if (s->orientation == VERTICAL && s->sliding == FULLFRAME)
365         outlink->frame_rate.den *= outlink->w;
366     if (s->orientation == HORIZONTAL && s->sliding == FULLFRAME)
367         outlink->frame_rate.den *= outlink->h;
368
369     if (s->orientation == VERTICAL) {
370         s->combine_buffer =
371             av_realloc_f(s->combine_buffer, outlink->h * 3,
372                          sizeof(*s->combine_buffer));
373     } else {
374         s->combine_buffer =
375             av_realloc_f(s->combine_buffer, outlink->w * 3,
376                          sizeof(*s->combine_buffer));
377     }
378
379     av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d FFT window size:%d\n",
380            s->w, s->h, s->win_size);
381
382     av_audio_fifo_free(s->fifo);
383     s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->win_size);
384     if (!s->fifo)
385         return AVERROR(ENOMEM);
386     return 0;
387 }
388
389 static void run_fft(ShowSpectrumContext *s, AVFrame *fin)
390 {
391     int ch, n;
392
393     /* fill FFT input with the number of samples available */
394     for (ch = 0; ch < s->nb_display_channels; ch++) {
395         const float *p = (float *)fin->extended_data[ch];
396
397         for (n = 0; n < s->win_size; n++) {
398             s->fft_data[ch][n].re = p[n] * s->window_func_lut[n];
399             s->fft_data[ch][n].im = 0;
400         }
401     }
402
403     /* run FFT on each samples set */
404     for (ch = 0; ch < s->nb_display_channels; ch++) {
405         av_fft_permute(s->fft, s->fft_data[ch]);
406         av_fft_calc(s->fft, s->fft_data[ch]);
407     }
408 }
409
410 #define RE(y, ch) s->fft_data[ch][y].re
411 #define IM(y, ch) s->fft_data[ch][y].im
412 #define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
413
414 static void calc_magnitudes(ShowSpectrumContext *s)
415 {
416     int ch, y, h = s->orientation == VERTICAL ? s->h : s->w;
417
418     for (ch = 0; ch < s->nb_display_channels; ch++) {
419         float *magnitudes = s->magnitudes[ch];
420
421         for (y = 0; y < h; y++)
422             magnitudes[y] = MAGNITUDE(y, ch);
423     }
424 }
425
426 static void acalc_magnitudes(ShowSpectrumContext *s)
427 {
428     int ch, y, h = s->orientation == VERTICAL ? s->h : s->w;
429
430     for (ch = 0; ch < s->nb_display_channels; ch++) {
431         float *magnitudes = s->magnitudes[ch];
432
433         for (y = 0; y < h; y++)
434             magnitudes[y] += MAGNITUDE(y, ch);
435     }
436 }
437
438 static void scale_magnitudes(ShowSpectrumContext *s, float scale)
439 {
440     int ch, y, h = s->orientation == VERTICAL ? s->h : s->w;
441
442     for (ch = 0; ch < s->nb_display_channels; ch++) {
443         float *magnitudes = s->magnitudes[ch];
444
445         for (y = 0; y < h; y++)
446             magnitudes[y] *= scale;
447     }
448 }
449
450 static void pick_color(ShowSpectrumContext *s,
451                        float yf, float uf, float vf,
452                        float a, float *out)
453 {
454     if (s->color_mode > CHANNEL) {
455         const int cm = s->color_mode;
456         float y, u, v;
457         int i;
458
459         for (i = 1; i < FF_ARRAY_ELEMS(color_table[cm]) - 1; i++)
460             if (color_table[cm][i].a >= a)
461                 break;
462         // i now is the first item >= the color
463         // now we know to interpolate between item i - 1 and i
464         if (a <= color_table[cm][i - 1].a) {
465             y = color_table[cm][i - 1].y;
466             u = color_table[cm][i - 1].u;
467             v = color_table[cm][i - 1].v;
468         } else if (a >= color_table[cm][i].a) {
469             y = color_table[cm][i].y;
470             u = color_table[cm][i].u;
471             v = color_table[cm][i].v;
472         } else {
473             float start = color_table[cm][i - 1].a;
474             float end = color_table[cm][i].a;
475             float lerpfrac = (a - start) / (end - start);
476             y = color_table[cm][i - 1].y * (1.0f - lerpfrac)
477               + color_table[cm][i].y * lerpfrac;
478             u = color_table[cm][i - 1].u * (1.0f - lerpfrac)
479               + color_table[cm][i].u * lerpfrac;
480             v = color_table[cm][i - 1].v * (1.0f - lerpfrac)
481               + color_table[cm][i].v * lerpfrac;
482         }
483
484         out[0] += y * yf;
485         out[1] += u * uf;
486         out[2] += v * vf;
487     } else {
488         out[0] += a * yf;
489         out[1] += a * uf;
490         out[2] += a * vf;
491     }
492 }
493
494 static void clear_combine_buffer(ShowSpectrumContext *s, int size)
495 {
496     int y;
497
498     for (y = 0; y < size; y++) {
499         s->combine_buffer[3 * y    ] = 0;
500         s->combine_buffer[3 * y + 1] = 127.5;
501         s->combine_buffer[3 * y + 2] = 127.5;
502     }
503 }
504
505 static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
506 {
507     int ret;
508     AVFilterContext *ctx = inlink->dst;
509     AVFilterLink *outlink = ctx->outputs[0];
510     ShowSpectrumContext *s = ctx->priv;
511     AVFrame *outpicref = s->outpicref;
512     const double w = s->win_scale;
513     const float g = s->gain;
514     int h = s->orientation == VERTICAL ? s->channel_height : s->channel_width;
515
516     int ch, plane, x, y;
517
518     /* fill a new spectrum column */
519     /* initialize buffer for combining to black */
520     clear_combine_buffer(s, s->orientation == VERTICAL ? outlink->h : outlink->w);
521
522     for (ch = 0; ch < s->nb_display_channels; ch++) {
523         float *magnitudes = s->magnitudes[ch];
524         float yf, uf, vf;
525
526         /* decide color range */
527         switch (s->mode) {
528         case COMBINED:
529             // reduce range by channel count
530             yf = 256.0f / s->nb_display_channels;
531             switch (s->color_mode) {
532             case RAINBOW:
533             case MORELAND:
534             case NEBULAE:
535             case FIRE:
536             case FIERY:
537             case FRUIT:
538             case INTENSITY:
539                 uf = yf;
540                 vf = yf;
541                 break;
542             case CHANNEL:
543                 /* adjust saturation for mixed UV coloring */
544                 /* this factor is correct for infinite channels, an approximation otherwise */
545                 uf = yf * M_PI;
546                 vf = yf * M_PI;
547                 break;
548             default:
549                 av_assert0(0);
550             }
551             break;
552         case SEPARATE:
553             // full range
554             yf = 256.0f;
555             uf = 256.0f;
556             vf = 256.0f;
557             break;
558         default:
559             av_assert0(0);
560         }
561
562         if (s->color_mode == CHANNEL) {
563             if (s->nb_display_channels > 1) {
564                 uf *= 0.5 * sin((2 * M_PI * ch) / s->nb_display_channels);
565                 vf *= 0.5 * cos((2 * M_PI * ch) / s->nb_display_channels);
566             } else {
567                 uf = 0.0f;
568                 vf = 0.0f;
569             }
570         }
571         uf *= s->saturation;
572         vf *= s->saturation;
573
574         /* draw the channel */
575         for (y = 0; y < h; y++) {
576             int row = (s->mode == COMBINED) ? y : ch * h + y;
577             float *out = &s->combine_buffer[3 * row];
578
579             /* get magnitude */
580             float a = g * w * magnitudes[y];
581
582             /* apply scale */
583             switch (s->scale) {
584             case LINEAR:
585                 break;
586             case SQRT:
587                 a = sqrt(a);
588                 break;
589             case CBRT:
590                 a = cbrt(a);
591                 break;
592             case FOURTHRT:
593                 a = sqrt(sqrt(a));
594                 break;
595             case FIFTHRT:
596                 a = pow(a, 0.20);
597                 break;
598             case LOG:
599                 a = 1 + log10(av_clipd(a * w, 1e-6, 1)) / 6; // zero = -120dBFS
600                 break;
601             default:
602                 av_assert0(0);
603             }
604
605             pick_color(s, yf, uf, vf, a, out);
606         }
607     }
608
609     av_frame_make_writable(s->outpicref);
610     /* copy to output */
611     if (s->orientation == VERTICAL) {
612         if (s->sliding == SCROLL) {
613             for (plane = 0; plane < 3; plane++) {
614                 for (y = 0; y < outlink->h; y++) {
615                     uint8_t *p = outpicref->data[plane] +
616                                  y * outpicref->linesize[plane];
617                     memmove(p, p + 1, outlink->w - 1);
618                 }
619             }
620             s->xpos = outlink->w - 1;
621         } else if (s->sliding == RSCROLL) {
622             for (plane = 0; plane < 3; plane++) {
623                 for (y = 0; y < outlink->h; y++) {
624                     uint8_t *p = outpicref->data[plane] +
625                                  y * outpicref->linesize[plane];
626                     memmove(p + 1, p, outlink->w - 1);
627                 }
628             }
629             s->xpos = 0;
630         }
631         for (plane = 0; plane < 3; plane++) {
632             uint8_t *p = outpicref->data[plane] +
633                          (outlink->h - 1) * outpicref->linesize[plane] +
634                          s->xpos;
635             for (y = 0; y < outlink->h; y++) {
636                 *p = lrintf(av_clipf(s->combine_buffer[3 * y + plane], 0, 255));
637                 p -= outpicref->linesize[plane];
638             }
639         }
640     } else {
641         if (s->sliding == SCROLL) {
642             for (plane = 0; plane < 3; plane++) {
643                 for (y = 1; y < outlink->h; y++) {
644                     memmove(outpicref->data[plane] + (y-1) * outpicref->linesize[plane],
645                             outpicref->data[plane] + (y  ) * outpicref->linesize[plane],
646                             outlink->w);
647                 }
648             }
649             s->xpos = outlink->h - 1;
650         } else if (s->sliding == RSCROLL) {
651             for (plane = 0; plane < 3; plane++) {
652                 for (y = outlink->h - 1; y >= 1; y--) {
653                     memmove(outpicref->data[plane] + (y  ) * outpicref->linesize[plane],
654                             outpicref->data[plane] + (y-1) * outpicref->linesize[plane],
655                             outlink->w);
656                 }
657             }
658             s->xpos = 0;
659         }
660         for (plane = 0; plane < 3; plane++) {
661             uint8_t *p = outpicref->data[plane] +
662                          s->xpos * outpicref->linesize[plane];
663             for (x = 0; x < outlink->w; x++) {
664                 *p = lrintf(av_clipf(s->combine_buffer[3 * x + plane], 0, 255));
665                 p++;
666             }
667         }
668     }
669
670     if (s->sliding != FULLFRAME || s->xpos == 0)
671         outpicref->pts = insamples->pts;
672
673     s->xpos++;
674     if (s->orientation == VERTICAL && s->xpos >= outlink->w)
675         s->xpos = 0;
676     if (s->orientation == HORIZONTAL && s->xpos >= outlink->h)
677         s->xpos = 0;
678     if (!s->single_pic && (s->sliding != FULLFRAME || s->xpos == 0)) {
679         ret = ff_filter_frame(outlink, av_frame_clone(s->outpicref));
680         if (ret < 0)
681             return ret;
682     }
683
684     return s->win_size;
685 }
686
687 #if CONFIG_SHOWSPECTRUM_FILTER
688
689 static int request_frame(AVFilterLink *outlink)
690 {
691     ShowSpectrumContext *s = outlink->src->priv;
692     AVFilterLink *inlink = outlink->src->inputs[0];
693     unsigned i;
694     int ret;
695
696     ret = ff_request_frame(inlink);
697     if (ret == AVERROR_EOF && s->sliding == FULLFRAME && s->xpos > 0 &&
698         s->outpicref) {
699         if (s->orientation == VERTICAL) {
700             for (i = 0; i < outlink->h; i++) {
701                 memset(s->outpicref->data[0] + i * s->outpicref->linesize[0] + s->xpos,   0, outlink->w - s->xpos);
702                 memset(s->outpicref->data[1] + i * s->outpicref->linesize[1] + s->xpos, 128, outlink->w - s->xpos);
703                 memset(s->outpicref->data[2] + i * s->outpicref->linesize[2] + s->xpos, 128, outlink->w - s->xpos);
704             }
705         } else {
706             for (i = s->xpos; i < outlink->h; i++) {
707                 memset(s->outpicref->data[0] + i * s->outpicref->linesize[0],   0, outlink->w);
708                 memset(s->outpicref->data[1] + i * s->outpicref->linesize[1], 128, outlink->w);
709                 memset(s->outpicref->data[2] + i * s->outpicref->linesize[2], 128, outlink->w);
710             }
711         }
712         ret = ff_filter_frame(outlink, s->outpicref);
713         s->outpicref = NULL;
714     }
715
716     return ret;
717 }
718
719 static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
720 {
721     AVFilterContext *ctx = inlink->dst;
722     ShowSpectrumContext *s = ctx->priv;
723     AVFrame *fin = NULL;
724     int ret = 0;
725
726     av_audio_fifo_write(s->fifo, (void **)insamples->extended_data, insamples->nb_samples);
727     av_frame_free(&insamples);
728     while (av_audio_fifo_size(s->fifo) >= s->win_size) {
729         fin = ff_get_audio_buffer(inlink, s->win_size);
730         if (!fin) {
731             ret = AVERROR(ENOMEM);
732             goto fail;
733         }
734
735         fin->pts = s->pts;
736         s->pts += s->skip_samples;
737         ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
738         if (ret < 0)
739             goto fail;
740
741         av_assert0(fin->nb_samples == s->win_size);
742
743         run_fft(s, fin);
744         calc_magnitudes(s);
745
746         ret = plot_spectrum_column(inlink, fin);
747         av_frame_free(&fin);
748         av_audio_fifo_drain(s->fifo, s->skip_samples);
749         if (ret < 0)
750             goto fail;
751     }
752
753 fail:
754     av_frame_free(&fin);
755     return ret;
756 }
757
758 static const AVFilterPad showspectrum_inputs[] = {
759     {
760         .name         = "default",
761         .type         = AVMEDIA_TYPE_AUDIO,
762         .filter_frame = filter_frame,
763     },
764     { NULL }
765 };
766
767 static const AVFilterPad showspectrum_outputs[] = {
768     {
769         .name          = "default",
770         .type          = AVMEDIA_TYPE_VIDEO,
771         .config_props  = config_output,
772         .request_frame = request_frame,
773     },
774     { NULL }
775 };
776
777 AVFilter ff_avf_showspectrum = {
778     .name          = "showspectrum",
779     .description   = NULL_IF_CONFIG_SMALL("Convert input audio to a spectrum video output."),
780     .uninit        = uninit,
781     .query_formats = query_formats,
782     .priv_size     = sizeof(ShowSpectrumContext),
783     .inputs        = showspectrum_inputs,
784     .outputs       = showspectrum_outputs,
785     .priv_class    = &showspectrum_class,
786 };
787 #endif // CONFIG_SHOWSPECTRUM_FILTER
788
789 #if CONFIG_SHOWSPECTRUMPIC_FILTER
790
791 static const AVOption showspectrumpic_options[] = {
792     { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "4096x2048"}, 0, 0, FLAGS },
793     { "s",    "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "4096x2048"}, 0, 0, FLAGS },
794     { "mode", "set channel display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=COMBINED}, 0, NB_MODES-1, FLAGS, "mode" },
795         { "combined", "combined mode", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "mode" },
796         { "separate", "separate mode", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "mode" },
797     { "color", "set channel coloring", OFFSET(color_mode), AV_OPT_TYPE_INT, {.i64=INTENSITY}, 0, NB_CLMODES-1, FLAGS, "color" },
798         { "channel",   "separate color for each channel", 0, AV_OPT_TYPE_CONST, {.i64=CHANNEL},   0, 0, FLAGS, "color" },
799         { "intensity", "intensity based coloring",        0, AV_OPT_TYPE_CONST, {.i64=INTENSITY}, 0, 0, FLAGS, "color" },
800         { "rainbow",   "rainbow based coloring",          0, AV_OPT_TYPE_CONST, {.i64=RAINBOW},   0, 0, FLAGS, "color" },
801         { "moreland",  "moreland based coloring",         0, AV_OPT_TYPE_CONST, {.i64=MORELAND},  0, 0, FLAGS, "color" },
802         { "nebulae",   "nebulae based coloring",          0, AV_OPT_TYPE_CONST, {.i64=NEBULAE},   0, 0, FLAGS, "color" },
803         { "fire",      "fire based coloring",             0, AV_OPT_TYPE_CONST, {.i64=FIRE},      0, 0, FLAGS, "color" },
804         { "fiery",     "fiery based coloring",            0, AV_OPT_TYPE_CONST, {.i64=FIERY},     0, 0, FLAGS, "color" },
805         { "fruit",     "fruit based coloring",            0, AV_OPT_TYPE_CONST, {.i64=FRUIT},     0, 0, FLAGS, "color" },
806     { "scale", "set display scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=LOG}, 0, NB_SCALES-1, FLAGS, "scale" },
807         { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SQRT},   0, 0, FLAGS, "scale" },
808         { "cbrt", "cubic root",  0, AV_OPT_TYPE_CONST, {.i64=CBRT},   0, 0, FLAGS, "scale" },
809         { "4thrt","4th root",    0, AV_OPT_TYPE_CONST, {.i64=FOURTHRT}, 0, 0, FLAGS, "scale" },
810         { "5thrt","5th root",    0, AV_OPT_TYPE_CONST, {.i64=FIFTHRT},  0, 0, FLAGS, "scale" },
811         { "log",  "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=LOG},    0, 0, FLAGS, "scale" },
812         { "lin",  "linear",      0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "scale" },
813     { "saturation", "color saturation multiplier", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl = 1}, -10, 10, FLAGS },
814     { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func" },
815         { "rect",     "Rectangular",      0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT},     0, 0, FLAGS, "win_func" },
816         { "bartlett", "Bartlett",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
817         { "hann",     "Hann",             0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING},  0, 0, FLAGS, "win_func" },
818         { "hanning",  "Hanning",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING},  0, 0, FLAGS, "win_func" },
819         { "hamming",  "Hamming",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING},  0, 0, FLAGS, "win_func" },
820         { "blackman", "Blackman",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
821         { "welch",    "Welch",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_WELCH},    0, 0, FLAGS, "win_func" },
822         { "flattop",  "Flat-top",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_FLATTOP},  0, 0, FLAGS, "win_func" },
823         { "bharris",  "Blackman-Harris",  0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHARRIS},  0, 0, FLAGS, "win_func" },
824         { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
825         { "bhann",    "Bartlett-Hann",    0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHANN},    0, 0, FLAGS, "win_func" },
826         { "sine",     "Sine",             0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE},     0, 0, FLAGS, "win_func" },
827         { "nuttall",  "Nuttall",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL},  0, 0, FLAGS, "win_func" },
828         { "lanczos",  "Lanczos",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS},  0, 0, FLAGS, "win_func" },
829         { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
830         { "tukey",    "Tukey",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY},    0, 0, FLAGS, "win_func" },
831     { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
832         { "vertical",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL},   0, 0, FLAGS, "orientation" },
833         { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
834     { "gain", "set scale gain", OFFSET(gain), AV_OPT_TYPE_FLOAT, {.dbl = 1}, 0, 128, FLAGS },
835     { NULL }
836 };
837
838 AVFILTER_DEFINE_CLASS(showspectrumpic);
839
840 static int showspectrumpic_request_frame(AVFilterLink *outlink)
841 {
842     ShowSpectrumContext *s = outlink->src->priv;
843     AVFilterLink *inlink = outlink->src->inputs[0];
844     int ret;
845
846     ret = ff_request_frame(inlink);
847     if (ret == AVERROR_EOF && s->outpicref) {
848         int samples = av_audio_fifo_size(s->fifo);
849         int consumed = 0;
850         int x = 0, sz = s->orientation == VERTICAL ? s->w : s->h;
851         int ch, spf, spb;
852         AVFrame *fin;
853
854         spf = s->win_size * (samples / ((s->win_size * sz) * ceil(samples / (float)(s->win_size * sz))));
855         spb = (samples / (spf * sz)) * spf;
856
857         fin = ff_get_audio_buffer(inlink, s->win_size);
858         if (!fin)
859             return AVERROR(ENOMEM);
860
861         while (x < sz) {
862             ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
863             if (ret < 0) {
864                 av_frame_free(&fin);
865                 return ret;
866             }
867
868             av_audio_fifo_drain(s->fifo, spf);
869
870             if (ret < s->win_size) {
871                 for (ch = 0; ch < s->nb_display_channels; ch++) {
872                     memset(fin->extended_data[ch] + ret * sizeof(float), 0,
873                            (s->win_size - ret) * sizeof(float));
874                 }
875             }
876
877             run_fft(s, fin);
878             acalc_magnitudes(s);
879
880             consumed += spf;
881             if (consumed >= spb) {
882                 int h = s->orientation == VERTICAL ? s->h : s->w;
883
884                 scale_magnitudes(s, 1. / (consumed / spf));
885                 plot_spectrum_column(inlink, fin);
886                 consumed = 0;
887                 x++;
888                 for (ch = 0; ch < s->nb_display_channels; ch++)
889                     memset(s->magnitudes[ch], 0, h * sizeof(float));
890             }
891         }
892
893         av_frame_free(&fin);
894         s->outpicref->pts = 0;
895         ret = ff_filter_frame(outlink, s->outpicref);
896         s->outpicref = NULL;
897     }
898
899     return ret;
900 }
901
902 static int showspectrumpic_filter_frame(AVFilterLink *inlink, AVFrame *insamples)
903 {
904     AVFilterContext *ctx = inlink->dst;
905     ShowSpectrumContext *s = ctx->priv;
906     int ret;
907
908     ret = av_audio_fifo_write(s->fifo, (void **)insamples->extended_data, insamples->nb_samples);
909     av_frame_free(&insamples);
910     return ret;
911 }
912
913 static const AVFilterPad showspectrumpic_inputs[] = {
914     {
915         .name         = "default",
916         .type         = AVMEDIA_TYPE_AUDIO,
917         .filter_frame = showspectrumpic_filter_frame,
918     },
919     { NULL }
920 };
921
922 static const AVFilterPad showspectrumpic_outputs[] = {
923     {
924         .name          = "default",
925         .type          = AVMEDIA_TYPE_VIDEO,
926         .config_props  = config_output,
927         .request_frame = showspectrumpic_request_frame,
928     },
929     { NULL }
930 };
931
932 AVFilter ff_avf_showspectrumpic = {
933     .name          = "showspectrumpic",
934     .description   = NULL_IF_CONFIG_SMALL("Convert input audio to a spectrum video output single picture."),
935     .uninit        = uninit,
936     .query_formats = query_formats,
937     .priv_size     = sizeof(ShowSpectrumContext),
938     .inputs        = showspectrumpic_inputs,
939     .outputs       = showspectrumpic_outputs,
940     .priv_class    = &showspectrumpic_class,
941 };
942
943 #endif // CONFIG_SHOWSPECTRUMPIC_FILTER