avf_showspectrum.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. /*
  2. * Copyright (c) 2012-2013 Clément Bœsch
  3. * Copyright (c) 2013 Rudolf Polzer <divverent@xonotic.org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * audio to spectrum (video) transmedia filter, based on ffplay rdft showmode
  24. * (by Michael Niedermayer) and lavfi/avf_showwaves (by Stefano Sabatini).
  25. */
  26. #include <math.h>
  27. #include "libavcodec/avfft.h"
  28. #include "libavutil/avassert.h"
  29. #include "libavutil/channel_layout.h"
  30. #include "libavutil/opt.h"
  31. #include "avfilter.h"
  32. #include "internal.h"
  33. enum DisplayMode { COMBINED, SEPARATE, NB_MODES };
  34. enum DisplayScale { LINEAR, SQRT, CBRT, LOG, NB_SCALES };
  35. enum ColorMode { CHANNEL, INTENSITY, NB_CLMODES };
  36. enum WindowFunc { WFUNC_NONE, WFUNC_HANN, WFUNC_HAMMING, WFUNC_BLACKMAN, NB_WFUNC };
  37. enum SlideMode { REPLACE, SCROLL, FULLFRAME, NB_SLIDES };
  38. typedef struct {
  39. const AVClass *class;
  40. int w, h;
  41. AVFrame *outpicref;
  42. int req_fullfilled;
  43. int nb_display_channels;
  44. int channel_height;
  45. int sliding; ///< 1 if sliding mode, 0 otherwise
  46. enum DisplayMode mode; ///< channel display mode
  47. enum ColorMode color_mode; ///< display color scheme
  48. enum DisplayScale scale;
  49. float saturation; ///< color saturation multiplier
  50. int xpos; ///< x position (current column)
  51. RDFTContext *rdft; ///< Real Discrete Fourier Transform context
  52. int rdft_bits; ///< number of bits (RDFT window size = 1<<rdft_bits)
  53. FFTSample **rdft_data; ///< bins holder for each (displayed) channels
  54. float *window_func_lut; ///< Window function LUT
  55. enum WindowFunc win_func;
  56. float *combine_buffer; ///< color combining buffer (3 * h items)
  57. } ShowSpectrumContext;
  58. #define OFFSET(x) offsetof(ShowSpectrumContext, x)
  59. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  60. static const AVOption showspectrum_options[] = {
  61. { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x512"}, 0, 0, FLAGS },
  62. { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x512"}, 0, 0, FLAGS },
  63. { "slide", "set sliding mode", OFFSET(sliding), AV_OPT_TYPE_INT, {.i64 = 0}, 0, NB_SLIDES, FLAGS, "slide" },
  64. { "replace", "replace old columns with new", 0, AV_OPT_TYPE_CONST, {.i64=REPLACE}, 0, 0, FLAGS, "slide" },
  65. { "scroll", "scroll from right to left", 0, AV_OPT_TYPE_CONST, {.i64=SCROLL}, 0, 0, FLAGS, "slide" },
  66. { "fullframe", "return full frames", 0, AV_OPT_TYPE_CONST, {.i64=FULLFRAME}, 0, 0, FLAGS, "slide" },
  67. { "mode", "set channel display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=COMBINED}, COMBINED, NB_MODES-1, FLAGS, "mode" },
  68. { "combined", "combined mode", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "mode" },
  69. { "separate", "separate mode", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "mode" },
  70. { "color", "set channel coloring", OFFSET(color_mode), AV_OPT_TYPE_INT, {.i64=CHANNEL}, CHANNEL, NB_CLMODES-1, FLAGS, "color" },
  71. { "channel", "separate color for each channel", 0, AV_OPT_TYPE_CONST, {.i64=CHANNEL}, 0, 0, FLAGS, "color" },
  72. { "intensity", "intensity based coloring", 0, AV_OPT_TYPE_CONST, {.i64=INTENSITY}, 0, 0, FLAGS, "color" },
  73. { "scale", "set display scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=SQRT}, LINEAR, NB_SCALES-1, FLAGS, "scale" },
  74. { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SQRT}, 0, 0, FLAGS, "scale" },
  75. { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=CBRT}, 0, 0, FLAGS, "scale" },
  76. { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=LOG}, 0, 0, FLAGS, "scale" },
  77. { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "scale" },
  78. { "saturation", "color saturation multiplier", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl = 1}, -10, 10, FLAGS },
  79. { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANN}, 0, NB_WFUNC-1, FLAGS, "win_func" },
  80. { "hann", "Hann window", 0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_HANN}, 0, 0, FLAGS, "win_func" },
  81. { "hamming", "Hamming window", 0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_HAMMING}, 0, 0, FLAGS, "win_func" },
  82. { "blackman", "Blackman window", 0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
  83. { NULL }
  84. };
  85. AVFILTER_DEFINE_CLASS(showspectrum);
  86. static const struct {
  87. float a, y, u, v;
  88. } intensity_color_table[] = {
  89. { 0, 0, 0, 0 },
  90. { 0.13, .03587126228984074, .1573300977624594, -.02548747583751842 },
  91. { 0.30, .18572281794568020, .1772436246393981, .17475554840414750 },
  92. { 0.60, .28184980583656130, -.1593064119945782, .47132074554608920 },
  93. { 0.73, .65830621175547810, -.3716070802232764, .24352759331252930 },
  94. { 0.78, .76318535758242900, -.4307467689263783, .16866496622310430 },
  95. { 0.91, .95336363636363640, -.2045454545454546, .03313636363636363 },
  96. { 1, 1, 0, 0 }
  97. };
  98. static av_cold void uninit(AVFilterContext *ctx)
  99. {
  100. ShowSpectrumContext *s = ctx->priv;
  101. int i;
  102. av_freep(&s->combine_buffer);
  103. av_rdft_end(s->rdft);
  104. for (i = 0; i < s->nb_display_channels; i++)
  105. av_freep(&s->rdft_data[i]);
  106. av_freep(&s->rdft_data);
  107. av_freep(&s->window_func_lut);
  108. av_frame_free(&s->outpicref);
  109. }
  110. static int query_formats(AVFilterContext *ctx)
  111. {
  112. AVFilterFormats *formats = NULL;
  113. AVFilterChannelLayouts *layouts = NULL;
  114. AVFilterLink *inlink = ctx->inputs[0];
  115. AVFilterLink *outlink = ctx->outputs[0];
  116. static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE };
  117. static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE };
  118. /* set input audio formats */
  119. formats = ff_make_format_list(sample_fmts);
  120. if (!formats)
  121. return AVERROR(ENOMEM);
  122. ff_formats_ref(formats, &inlink->out_formats);
  123. layouts = ff_all_channel_layouts();
  124. if (!layouts)
  125. return AVERROR(ENOMEM);
  126. ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
  127. formats = ff_all_samplerates();
  128. if (!formats)
  129. return AVERROR(ENOMEM);
  130. ff_formats_ref(formats, &inlink->out_samplerates);
  131. /* set output video format */
  132. formats = ff_make_format_list(pix_fmts);
  133. if (!formats)
  134. return AVERROR(ENOMEM);
  135. ff_formats_ref(formats, &outlink->in_formats);
  136. return 0;
  137. }
  138. static int config_output(AVFilterLink *outlink)
  139. {
  140. AVFilterContext *ctx = outlink->src;
  141. AVFilterLink *inlink = ctx->inputs[0];
  142. ShowSpectrumContext *s = ctx->priv;
  143. int i, rdft_bits, win_size, h;
  144. outlink->w = s->w;
  145. outlink->h = s->h;
  146. h = (s->mode == COMBINED) ? outlink->h : outlink->h / inlink->channels;
  147. s->channel_height = h;
  148. /* RDFT window size (precision) according to the requested output frame height */
  149. for (rdft_bits = 1; 1 << rdft_bits < 2 * h; rdft_bits++);
  150. win_size = 1 << rdft_bits;
  151. /* (re-)configuration if the video output changed (or first init) */
  152. if (rdft_bits != s->rdft_bits) {
  153. size_t rdft_size, rdft_listsize;
  154. AVFrame *outpicref;
  155. av_rdft_end(s->rdft);
  156. s->rdft = av_rdft_init(rdft_bits, DFT_R2C);
  157. if (!s->rdft) {
  158. av_log(ctx, AV_LOG_ERROR, "Unable to create RDFT context. "
  159. "The window size might be too high.\n");
  160. return AVERROR(EINVAL);
  161. }
  162. s->rdft_bits = rdft_bits;
  163. /* RDFT buffers: x2 for each (display) channel buffer.
  164. * Note: we use free and malloc instead of a realloc-like function to
  165. * make sure the buffer is aligned in memory for the FFT functions. */
  166. for (i = 0; i < s->nb_display_channels; i++)
  167. av_freep(&s->rdft_data[i]);
  168. av_freep(&s->rdft_data);
  169. s->nb_display_channels = inlink->channels;
  170. if (av_size_mult(sizeof(*s->rdft_data),
  171. s->nb_display_channels, &rdft_listsize) < 0)
  172. return AVERROR(EINVAL);
  173. if (av_size_mult(sizeof(**s->rdft_data),
  174. win_size, &rdft_size) < 0)
  175. return AVERROR(EINVAL);
  176. s->rdft_data = av_malloc(rdft_listsize);
  177. if (!s->rdft_data)
  178. return AVERROR(ENOMEM);
  179. for (i = 0; i < s->nb_display_channels; i++) {
  180. s->rdft_data[i] = av_malloc(rdft_size);
  181. if (!s->rdft_data[i])
  182. return AVERROR(ENOMEM);
  183. }
  184. /* pre-calc windowing function */
  185. s->window_func_lut =
  186. av_realloc_f(s->window_func_lut, win_size,
  187. sizeof(*s->window_func_lut));
  188. if (!s->window_func_lut)
  189. return AVERROR(ENOMEM);
  190. switch (s->win_func) {
  191. case WFUNC_NONE:
  192. for (i = 0; i < win_size; i++)
  193. s->window_func_lut[i] = 1.;
  194. break;
  195. case WFUNC_HANN:
  196. for (i = 0; i < win_size; i++)
  197. s->window_func_lut[i] = .5f * (1 - cos(2*M_PI*i / (win_size-1)));
  198. break;
  199. case WFUNC_HAMMING:
  200. for (i = 0; i < win_size; i++)
  201. s->window_func_lut[i] = .54f - .46f * cos(2*M_PI*i / (win_size-1));
  202. break;
  203. case WFUNC_BLACKMAN: {
  204. for (i = 0; i < win_size; i++)
  205. s->window_func_lut[i] = .42f - .5f*cos(2*M_PI*i / (win_size-1)) + .08f*cos(4*M_PI*i / (win_size-1));
  206. break;
  207. }
  208. default:
  209. av_assert0(0);
  210. }
  211. /* prepare the initial picref buffer (black frame) */
  212. av_frame_free(&s->outpicref);
  213. s->outpicref = outpicref =
  214. ff_get_video_buffer(outlink, outlink->w, outlink->h);
  215. if (!outpicref)
  216. return AVERROR(ENOMEM);
  217. outlink->sample_aspect_ratio = (AVRational){1,1};
  218. for (i = 0; i < outlink->h; i++) {
  219. memset(outpicref->data[0] + i * outpicref->linesize[0], 0, outlink->w);
  220. memset(outpicref->data[1] + i * outpicref->linesize[1], 128, outlink->w);
  221. memset(outpicref->data[2] + i * outpicref->linesize[2], 128, outlink->w);
  222. }
  223. }
  224. if (s->xpos >= outlink->w)
  225. s->xpos = 0;
  226. outlink->frame_rate = av_make_q(inlink->sample_rate, win_size);
  227. if (s->sliding == FULLFRAME)
  228. outlink->frame_rate.den *= outlink->w;
  229. inlink->min_samples = inlink->max_samples = inlink->partial_buf_size =
  230. win_size;
  231. s->combine_buffer =
  232. av_realloc_f(s->combine_buffer, outlink->h * 3,
  233. sizeof(*s->combine_buffer));
  234. av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d RDFT window size:%d\n",
  235. s->w, s->h, win_size);
  236. return 0;
  237. }
  238. static int request_frame(AVFilterLink *outlink)
  239. {
  240. ShowSpectrumContext *s = outlink->src->priv;
  241. AVFilterLink *inlink = outlink->src->inputs[0];
  242. unsigned i;
  243. int ret;
  244. s->req_fullfilled = 0;
  245. do {
  246. ret = ff_request_frame(inlink);
  247. if (ret == AVERROR_EOF && s->sliding == FULLFRAME && s->xpos > 0 &&
  248. s->outpicref) {
  249. for (i = 0; i < outlink->h; i++) {
  250. memset(s->outpicref->data[0] + i * s->outpicref->linesize[0] + s->xpos, 0, outlink->w - s->xpos);
  251. memset(s->outpicref->data[1] + i * s->outpicref->linesize[1] + s->xpos, 128, outlink->w - s->xpos);
  252. memset(s->outpicref->data[2] + i * s->outpicref->linesize[2] + s->xpos, 128, outlink->w - s->xpos);
  253. }
  254. ret = ff_filter_frame(outlink, s->outpicref);
  255. s->outpicref = NULL;
  256. s->req_fullfilled = 1;
  257. }
  258. } while (!s->req_fullfilled && ret >= 0);
  259. return ret;
  260. }
  261. static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
  262. {
  263. int ret;
  264. AVFilterContext *ctx = inlink->dst;
  265. AVFilterLink *outlink = ctx->outputs[0];
  266. ShowSpectrumContext *s = ctx->priv;
  267. AVFrame *outpicref = s->outpicref;
  268. /* nb_freq contains the power of two superior or equal to the output image
  269. * height (or half the RDFT window size) */
  270. const int nb_freq = 1 << (s->rdft_bits - 1);
  271. const int win_size = nb_freq << 1;
  272. const double w = 1. / (sqrt(nb_freq) * 32768.);
  273. int h = s->channel_height;
  274. int ch, plane, n, y;
  275. av_assert0(insamples->nb_samples == win_size);
  276. /* fill RDFT input with the number of samples available */
  277. for (ch = 0; ch < s->nb_display_channels; ch++) {
  278. const int16_t *p = (int16_t *)insamples->extended_data[ch];
  279. for (n = 0; n < win_size; n++)
  280. s->rdft_data[ch][n] = p[n] * s->window_func_lut[n];
  281. }
  282. /* TODO reindent */
  283. /* run RDFT on each samples set */
  284. for (ch = 0; ch < s->nb_display_channels; ch++)
  285. av_rdft_calc(s->rdft, s->rdft_data[ch]);
  286. /* fill a new spectrum column */
  287. #define RE(y, ch) s->rdft_data[ch][2 * (y) + 0]
  288. #define IM(y, ch) s->rdft_data[ch][2 * (y) + 1]
  289. #define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
  290. /* initialize buffer for combining to black */
  291. for (y = 0; y < outlink->h; y++) {
  292. s->combine_buffer[3 * y ] = 0;
  293. s->combine_buffer[3 * y + 1] = 127.5;
  294. s->combine_buffer[3 * y + 2] = 127.5;
  295. }
  296. for (ch = 0; ch < s->nb_display_channels; ch++) {
  297. float yf, uf, vf;
  298. /* decide color range */
  299. switch (s->mode) {
  300. case COMBINED:
  301. // reduce range by channel count
  302. yf = 256.0f / s->nb_display_channels;
  303. switch (s->color_mode) {
  304. case INTENSITY:
  305. uf = yf;
  306. vf = yf;
  307. break;
  308. case CHANNEL:
  309. /* adjust saturation for mixed UV coloring */
  310. /* this factor is correct for infinite channels, an approximation otherwise */
  311. uf = yf * M_PI;
  312. vf = yf * M_PI;
  313. break;
  314. default:
  315. av_assert0(0);
  316. }
  317. break;
  318. case SEPARATE:
  319. // full range
  320. yf = 256.0f;
  321. uf = 256.0f;
  322. vf = 256.0f;
  323. break;
  324. default:
  325. av_assert0(0);
  326. }
  327. if (s->color_mode == CHANNEL) {
  328. if (s->nb_display_channels > 1) {
  329. uf *= 0.5 * sin((2 * M_PI * ch) / s->nb_display_channels);
  330. vf *= 0.5 * cos((2 * M_PI * ch) / s->nb_display_channels);
  331. } else {
  332. uf = 0.0f;
  333. vf = 0.0f;
  334. }
  335. }
  336. uf *= s->saturation;
  337. vf *= s->saturation;
  338. /* draw the channel */
  339. for (y = 0; y < h; y++) {
  340. int row = (s->mode == COMBINED) ? y : ch * h + y;
  341. float *out = &s->combine_buffer[3 * row];
  342. /* get magnitude */
  343. float a = w * MAGNITUDE(y, ch);
  344. /* apply scale */
  345. switch (s->scale) {
  346. case LINEAR:
  347. break;
  348. case SQRT:
  349. a = sqrt(a);
  350. break;
  351. case CBRT:
  352. a = cbrt(a);
  353. break;
  354. case LOG:
  355. a = 1 - log(FFMAX(FFMIN(1, a), 1e-6)) / log(1e-6); // zero = -120dBFS
  356. break;
  357. default:
  358. av_assert0(0);
  359. }
  360. if (s->color_mode == INTENSITY) {
  361. float y, u, v;
  362. int i;
  363. for (i = 1; i < sizeof(intensity_color_table) / sizeof(*intensity_color_table) - 1; i++)
  364. if (intensity_color_table[i].a >= a)
  365. break;
  366. // i now is the first item >= the color
  367. // now we know to interpolate between item i - 1 and i
  368. if (a <= intensity_color_table[i - 1].a) {
  369. y = intensity_color_table[i - 1].y;
  370. u = intensity_color_table[i - 1].u;
  371. v = intensity_color_table[i - 1].v;
  372. } else if (a >= intensity_color_table[i].a) {
  373. y = intensity_color_table[i].y;
  374. u = intensity_color_table[i].u;
  375. v = intensity_color_table[i].v;
  376. } else {
  377. float start = intensity_color_table[i - 1].a;
  378. float end = intensity_color_table[i].a;
  379. float lerpfrac = (a - start) / (end - start);
  380. y = intensity_color_table[i - 1].y * (1.0f - lerpfrac)
  381. + intensity_color_table[i].y * lerpfrac;
  382. u = intensity_color_table[i - 1].u * (1.0f - lerpfrac)
  383. + intensity_color_table[i].u * lerpfrac;
  384. v = intensity_color_table[i - 1].v * (1.0f - lerpfrac)
  385. + intensity_color_table[i].v * lerpfrac;
  386. }
  387. out[0] += y * yf;
  388. out[1] += u * uf;
  389. out[2] += v * vf;
  390. } else {
  391. out[0] += a * yf;
  392. out[1] += a * uf;
  393. out[2] += a * vf;
  394. }
  395. }
  396. }
  397. /* copy to output */
  398. if (s->sliding == SCROLL) {
  399. for (plane = 0; plane < 3; plane++) {
  400. for (y = 0; y < outlink->h; y++) {
  401. uint8_t *p = outpicref->data[plane] +
  402. y * outpicref->linesize[plane];
  403. memmove(p, p + 1, outlink->w - 1);
  404. }
  405. }
  406. s->xpos = outlink->w - 1;
  407. }
  408. for (plane = 0; plane < 3; plane++) {
  409. uint8_t *p = outpicref->data[plane] +
  410. (outlink->h - 1) * outpicref->linesize[plane] +
  411. s->xpos;
  412. for (y = 0; y < outlink->h; y++) {
  413. *p = rint(FFMAX(0, FFMIN(s->combine_buffer[3 * y + plane], 255)));
  414. p -= outpicref->linesize[plane];
  415. }
  416. }
  417. if (s->sliding != FULLFRAME || s->xpos == 0)
  418. outpicref->pts = insamples->pts;
  419. s->xpos++;
  420. if (s->xpos >= outlink->w)
  421. s->xpos = 0;
  422. if (s->sliding != FULLFRAME || s->xpos == 0) {
  423. s->req_fullfilled = 1;
  424. ret = ff_filter_frame(outlink, av_frame_clone(s->outpicref));
  425. if (ret < 0)
  426. return ret;
  427. }
  428. return win_size;
  429. }
  430. static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
  431. {
  432. AVFilterContext *ctx = inlink->dst;
  433. ShowSpectrumContext *s = ctx->priv;
  434. unsigned win_size = 1 << s->rdft_bits;
  435. int ret = 0;
  436. av_assert0(insamples->nb_samples <= win_size);
  437. if (insamples->nb_samples == win_size)
  438. ret = plot_spectrum_column(inlink, insamples);
  439. av_frame_free(&insamples);
  440. return ret;
  441. }
  442. static const AVFilterPad showspectrum_inputs[] = {
  443. {
  444. .name = "default",
  445. .type = AVMEDIA_TYPE_AUDIO,
  446. .filter_frame = filter_frame,
  447. },
  448. { NULL }
  449. };
  450. static const AVFilterPad showspectrum_outputs[] = {
  451. {
  452. .name = "default",
  453. .type = AVMEDIA_TYPE_VIDEO,
  454. .config_props = config_output,
  455. .request_frame = request_frame,
  456. },
  457. { NULL }
  458. };
  459. AVFilter ff_avf_showspectrum = {
  460. .name = "showspectrum",
  461. .description = NULL_IF_CONFIG_SMALL("Convert input audio to a spectrum video output."),
  462. .uninit = uninit,
  463. .query_formats = query_formats,
  464. .priv_size = sizeof(ShowSpectrumContext),
  465. .inputs = showspectrum_inputs,
  466. .outputs = showspectrum_outputs,
  467. .priv_class = &showspectrum_class,
  468. };