FFmpeg
avf_showfreqs.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Paul B Mahol
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 <float.h>
22 #include <math.h>
23 
24 #include "libavutil/tx.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/avstring.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/parseutils.h"
31 #include "audio.h"
32 #include "filters.h"
33 #include "video.h"
34 #include "avfilter.h"
35 #include "internal.h"
36 #include "window_func.h"
37 
43 
44 typedef struct ShowFreqsContext {
45  const AVClass *class;
46  int w, h;
47  int mode;
48  int data_mode;
49  int cmode;
50  int fft_size;
51  int ascale, fscale;
52  int avg;
53  int win_func;
55  uint8_t *bypass;
62  float **avg_data;
64  float overlap;
65  float minamp;
66  int hop_size;
69  int nb_freq;
70  int win_size;
71  float scale;
72  char *colors;
73  int64_t pts;
74  int64_t old_pts;
77 
78 #define OFFSET(x) offsetof(ShowFreqsContext, x)
79 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
80 
81 static const AVOption showfreqs_options[] = {
82  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "1024x512"}, 0, 0, FLAGS },
83  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "1024x512"}, 0, 0, FLAGS },
84  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
85  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
86  { "mode", "set display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=BAR}, 0, NB_MODES-1, FLAGS, "mode" },
87  { "line", "show lines", 0, AV_OPT_TYPE_CONST, {.i64=LINE}, 0, 0, FLAGS, "mode" },
88  { "bar", "show bars", 0, AV_OPT_TYPE_CONST, {.i64=BAR}, 0, 0, FLAGS, "mode" },
89  { "dot", "show dots", 0, AV_OPT_TYPE_CONST, {.i64=DOT}, 0, 0, FLAGS, "mode" },
90  { "ascale", "set amplitude scale", OFFSET(ascale), AV_OPT_TYPE_INT, {.i64=AS_LOG}, 0, NB_ASCALES-1, FLAGS, "ascale" },
91  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=AS_LINEAR}, 0, 0, FLAGS, "ascale" },
92  { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=AS_SQRT}, 0, 0, FLAGS, "ascale" },
93  { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=AS_CBRT}, 0, 0, FLAGS, "ascale" },
94  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=AS_LOG}, 0, 0, FLAGS, "ascale" },
95  { "fscale", "set frequency scale", OFFSET(fscale), AV_OPT_TYPE_INT, {.i64=FS_LINEAR}, 0, NB_FSCALES-1, FLAGS, "fscale" },
96  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=FS_LINEAR}, 0, 0, FLAGS, "fscale" },
97  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=FS_LOG}, 0, 0, FLAGS, "fscale" },
98  { "rlog", "reverse logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=FS_RLOG}, 0, 0, FLAGS, "fscale" },
99  { "win_size", "set window size", OFFSET(fft_size), AV_OPT_TYPE_INT, {.i64=2048}, 16, 65536, FLAGS },
100  WIN_FUNC_OPTION("win_func", OFFSET(win_func), FLAGS, WFUNC_HANNING),
101  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1.}, 0., 1., FLAGS },
102  { "averaging", "set time averaging", OFFSET(avg), AV_OPT_TYPE_INT, {.i64=1}, 0, INT32_MAX, FLAGS },
103  { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
104  { "cmode", "set channel mode", OFFSET(cmode), AV_OPT_TYPE_INT, {.i64=COMBINED}, 0, NB_CMODES-1, FLAGS, "cmode" },
105  { "combined", "show all channels in same window", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "cmode" },
106  { "separate", "show each channel in own window", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "cmode" },
107  { "minamp", "set minimum amplitude", OFFSET(minamp), AV_OPT_TYPE_FLOAT, {.dbl=1e-6}, FLT_MIN, 1e-6, FLAGS },
108  { "data", "set data mode", OFFSET(data_mode), AV_OPT_TYPE_INT, {.i64=MAGNITUDE}, 0, NB_DATA-1, FLAGS, "data" },
109  { "magnitude", "show magnitude", 0, AV_OPT_TYPE_CONST, {.i64=MAGNITUDE}, 0, 0, FLAGS, "data" },
110  { "phase", "show phase", 0, AV_OPT_TYPE_CONST, {.i64=PHASE}, 0, 0, FLAGS, "data" },
111  { "delay", "show group delay",0, AV_OPT_TYPE_CONST, {.i64=DELAY}, 0, 0, FLAGS, "data" },
112  { "channels", "set channels to draw", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS },
113  { NULL }
114 };
115 
116 AVFILTER_DEFINE_CLASS(showfreqs);
117 
119 {
122  AVFilterLink *inlink = ctx->inputs[0];
123  AVFilterLink *outlink = ctx->outputs[0];
125  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
126  int ret;
127 
128  /* set input audio formats */
130  if ((ret = ff_formats_ref(formats, &inlink->outcfg.formats)) < 0)
131  return ret;
132 
134  if ((ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts)) < 0)
135  return ret;
136 
138  if ((ret = ff_formats_ref(formats, &inlink->outcfg.samplerates)) < 0)
139  return ret;
140 
141  /* set output video format */
143  if ((ret = ff_formats_ref(formats, &outlink->incfg.formats)) < 0)
144  return ret;
145 
146  return 0;
147 }
148 
149 static int config_output(AVFilterLink *outlink)
150 {
151  AVFilterContext *ctx = outlink->src;
152  AVFilterLink *inlink = ctx->inputs[0];
153  ShowFreqsContext *s = ctx->priv;
154  float overlap, scale = 1.f;
155  int i, ret;
156 
157  s->old_pts = AV_NOPTS_VALUE;
158  s->nb_freq = s->fft_size / 2;
159  s->win_size = s->fft_size;
160  av_tx_uninit(&s->fft);
161  ret = av_tx_init(&s->fft, &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_size, &scale, 0);
162  if (ret < 0) {
163  av_log(ctx, AV_LOG_ERROR, "Unable to create FFT context. "
164  "The window size might be too high.\n");
165  return ret;
166  }
167 
168  /* FFT buffers: x2 for each (display) channel buffer.
169  * Note: we use free and malloc instead of a realloc-like function to
170  * make sure the buffer is aligned in memory for the FFT functions. */
171  for (i = 0; i < s->nb_channels; i++) {
172  av_freep(&s->fft_input[i]);
173  av_freep(&s->fft_data[i]);
174  av_freep(&s->avg_data[i]);
175  }
176  av_freep(&s->bypass);
177  av_freep(&s->fft_input);
178  av_freep(&s->fft_data);
179  av_freep(&s->avg_data);
180  s->nb_channels = inlink->ch_layout.nb_channels;
181 
182  s->bypass = av_calloc(s->nb_channels, sizeof(*s->bypass));
183  if (!s->bypass)
184  return AVERROR(ENOMEM);
185  s->fft_input = av_calloc(s->nb_channels, sizeof(*s->fft_input));
186  if (!s->fft_input)
187  return AVERROR(ENOMEM);
188  s->fft_data = av_calloc(s->nb_channels, sizeof(*s->fft_data));
189  if (!s->fft_data)
190  return AVERROR(ENOMEM);
191  s->avg_data = av_calloc(s->nb_channels, sizeof(*s->avg_data));
192  if (!s->avg_data)
193  return AVERROR(ENOMEM);
194  for (i = 0; i < s->nb_channels; i++) {
195  s->fft_input[i] = av_calloc(FFALIGN(s->win_size, 512), sizeof(**s->fft_input));
196  s->fft_data[i] = av_calloc(FFALIGN(s->win_size, 512), sizeof(**s->fft_data));
197  s->avg_data[i] = av_calloc(s->nb_freq, sizeof(**s->avg_data));
198  if (!s->fft_data[i] || !s->avg_data[i] || !s->fft_input[i])
199  return AVERROR(ENOMEM);
200  }
201 
202  /* pre-calc windowing function */
203  s->window_func_lut = av_realloc_f(s->window_func_lut, s->win_size,
204  sizeof(*s->window_func_lut));
205  if (!s->window_func_lut)
206  return AVERROR(ENOMEM);
207  generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
208  if (s->overlap == 1.)
209  s->overlap = overlap;
210  s->hop_size = (1. - s->overlap) * s->win_size;
211  if (s->hop_size < 1) {
212  av_log(ctx, AV_LOG_ERROR, "overlap %f too big\n", s->overlap);
213  return AVERROR(EINVAL);
214  }
215 
216  for (s->scale = 0, i = 0; i < s->win_size; i++) {
217  s->scale += s->window_func_lut[i] * s->window_func_lut[i];
218  }
219 
220  s->window = ff_get_audio_buffer(inlink, s->win_size * 2);
221  if (!s->window)
222  return AVERROR(ENOMEM);
223 
224  outlink->frame_rate = s->frame_rate;
225  outlink->time_base = av_inv_q(outlink->frame_rate);
226  outlink->sample_aspect_ratio = (AVRational){1,1};
227  outlink->w = s->w;
228  outlink->h = s->h;
229 
230  ret = av_channel_layout_copy(&s->ch_layout, &inlink->ch_layout);
231  if (ret < 0)
232  return ret;
233  s->nb_draw_channels = s->nb_channels;
234 
235  if (strcmp(s->ch_layout_str, "all")) {
236  int nb_draw_channels = 0;
237  av_channel_layout_from_string(&s->ch_layout,
238  s->ch_layout_str);
239 
240  for (int ch = 0; ch < s->nb_channels; ch++) {
241  const enum AVChannel channel = av_channel_layout_channel_from_index(&inlink->ch_layout, ch);
242 
243  s->bypass[ch] = av_channel_layout_index_from_channel(&s->ch_layout, channel) < 0;
244  nb_draw_channels += s->bypass[ch] == 0;
245  }
246 
247  s->nb_draw_channels = nb_draw_channels;
248  }
249 
250  return 0;
251 }
252 
253 static inline void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
254 {
255 
256  uint32_t color = AV_RL32(out->data[0] + y * out->linesize[0] + x * 4);
257 
258  if ((color & 0xffffff) != 0)
259  AV_WL32(out->data[0] + y * out->linesize[0] + x * 4, AV_RL32(fg) | color);
260  else
261  AV_WL32(out->data[0] + y * out->linesize[0] + x * 4, AV_RL32(fg));
262 }
263 
264 static int get_sx(ShowFreqsContext *s, int f)
265 {
266  switch (s->fscale) {
267  case FS_LINEAR:
268  return (s->w/(float)s->nb_freq)*f;
269  case FS_LOG:
270  return s->w-pow(s->w, (s->nb_freq-f-1)/(s->nb_freq-1.));
271  case FS_RLOG:
272  return pow(s->w, f/(s->nb_freq-1.));
273  }
274 
275  return 0;
276 }
277 
278 static float get_bsize(ShowFreqsContext *s, int f)
279 {
280  switch (s->fscale) {
281  case FS_LINEAR:
282  return s->w/(float)s->nb_freq;
283  case FS_LOG:
284  return pow(s->w, (s->nb_freq-f-1)/(s->nb_freq-1.))-
285  pow(s->w, (s->nb_freq-f-2)/(s->nb_freq-1.));
286  case FS_RLOG:
287  return pow(s->w, (f+1)/(s->nb_freq-1.))-
288  pow(s->w, f /(s->nb_freq-1.));
289  }
290 
291  return 1.;
292 }
293 
294 static inline void plot_freq(ShowFreqsContext *s, int ch,
295  double a, int f, uint8_t fg[4], int *prev_y,
296  AVFrame *out, AVFilterLink *outlink)
297 {
298  const int w = s->w;
299  const float min = s->minamp;
300  const float avg = s->avg_data[ch][f];
301  const float bsize = get_bsize(s, f);
302  const int sx = get_sx(s, f);
303  int end = outlink->h;
304  int x, y, i;
305 
306  switch(s->ascale) {
307  case AS_SQRT:
308  a = 1.0 - sqrt(a);
309  break;
310  case AS_CBRT:
311  a = 1.0 - cbrt(a);
312  break;
313  case AS_LOG:
314  a = log(av_clipd(a, min, 1)) / log(min);
315  break;
316  case AS_LINEAR:
317  a = 1.0 - a;
318  break;
319  }
320 
321  switch (s->cmode) {
322  case COMBINED:
323  y = a * outlink->h - 1;
324  break;
325  case SEPARATE:
326  end = (outlink->h / s->nb_draw_channels) * (ch + 1);
327  y = (outlink->h / s->nb_draw_channels) * ch + a * (outlink->h / s->nb_draw_channels) - 1;
328  break;
329  default:
330  av_assert0(0);
331  }
332  if (y < 0)
333  return;
334 
335  switch (s->avg) {
336  case 0:
337  y = s->avg_data[ch][f] = !outlink->frame_count_in ? y : FFMIN(0, y);
338  break;
339  case 1:
340  break;
341  default:
342  s->avg_data[ch][f] = avg + y * (y - avg) / (FFMIN(outlink->frame_count_in + 1, s->avg) * (float)y);
343  y = av_clip(s->avg_data[ch][f], 0, outlink->h - 1);
344  break;
345  }
346 
347  switch(s->mode) {
348  case LINE:
349  if (*prev_y == -1) {
350  *prev_y = y;
351  }
352  if (y <= *prev_y) {
353  for (x = sx + 1; x < sx + bsize && x < w; x++)
354  draw_dot(out, x, y, fg);
355  for (i = y; i <= *prev_y; i++)
356  draw_dot(out, sx, i, fg);
357  } else {
358  for (i = *prev_y; i <= y; i++)
359  draw_dot(out, sx, i, fg);
360  for (x = sx + 1; x < sx + bsize && x < w; x++)
361  draw_dot(out, x, i - 1, fg);
362  }
363  *prev_y = y;
364  break;
365  case BAR:
366  for (x = sx; x < sx + bsize && x < w; x++)
367  for (i = y; i < end; i++)
368  draw_dot(out, x, i, fg);
369  break;
370  case DOT:
371  for (x = sx; x < sx + bsize && x < w; x++)
372  draw_dot(out, x, y, fg);
373  break;
374  }
375 }
376 
377 static int plot_freqs(AVFilterLink *inlink, int64_t pts)
378 {
379  AVFilterContext *ctx = inlink->dst;
380  AVFilterLink *outlink = ctx->outputs[0];
381  ShowFreqsContext *s = ctx->priv;
382  AVFrame *in = s->window;
383  const int win_size = s->win_size;
384  char *colors, *color, *saveptr = NULL;
385  AVFrame *out;
386  int ch, n;
387 
388  /* fill FFT input with the number of samples available */
389  for (ch = 0; ch < s->nb_channels; ch++) {
390  const float *p = (float *)in->extended_data[ch];
391 
392  if (s->bypass[ch])
393  continue;
394 
395  for (n = 0; n < win_size; n++) {
396  s->fft_input[ch][n].re = p[n] * s->window_func_lut[n];
397  s->fft_input[ch][n].im = 0;
398  }
399  }
400 
401  /* run FFT on each samples set */
402  for (ch = 0; ch < s->nb_channels; ch++) {
403  if (s->bypass[ch])
404  continue;
405 
406  s->tx_fn(s->fft, s->fft_data[ch], s->fft_input[ch], sizeof(AVComplexFloat));
407  }
408 
409  s->pts = av_rescale_q(pts, inlink->time_base, outlink->time_base);
410  if (s->old_pts >= s->pts)
411  return 0;
412  s->old_pts = s->pts;
413 
414 #define RE(x, ch) s->fft_data[ch][x].re
415 #define IM(x, ch) s->fft_data[ch][x].im
416 #define M(a, b) (sqrt((a) * (a) + (b) * (b)))
417 #define P(a, b) (atan2((b), (a)))
418 
419  colors = av_strdup(s->colors);
420  if (!colors)
421  return AVERROR(ENOMEM);
422 
423  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
424  if (!out) {
425  av_free(colors);
426  return AVERROR(ENOMEM);
427  }
428 
429  for (n = 0; n < outlink->h; n++)
430  memset(out->data[0] + out->linesize[0] * n, 0, outlink->w * 4);
431 
432  for (ch = 0; ch < s->nb_channels; ch++) {
433  uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
434  int prev_y = -1, f;
435  double a;
436 
437  color = av_strtok(ch == 0 ? colors : NULL, " |", &saveptr);
438  if (color)
439  av_parse_color(fg, color, -1, ctx);
440 
441  if (s->bypass[ch])
442  continue;
443 
444  switch (s->data_mode) {
445  case MAGNITUDE:
446  for (f = 0; f < s->nb_freq; f++) {
447  a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1);
448 
449  plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
450  }
451  break;
452  case PHASE:
453  for (f = 0; f < s->nb_freq; f++) {
454  a = av_clipd((M_PI + P(RE(f, ch), IM(f, ch))) / (2. * M_PI), 0, 1);
455 
456  plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
457  }
458  break;
459  case DELAY:
460  for (f = 0; f < s->nb_freq; f++) {
461  a = av_clipd((M_PI - P(IM(f, ch) * RE(f-1, ch) - IM(f-1, ch) * RE(f, ch),
462  RE(f, ch) * RE(f-1, ch) + IM(f, ch) * IM(f-1, ch))) / (2. * M_PI), 0, 1);
463 
464  plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
465  }
466  break;
467  }
468  }
469 
470  av_free(colors);
471  out->pts = s->pts;
472  out->duration = 1;
473  out->sample_aspect_ratio = (AVRational){1,1};
474  return ff_filter_frame(outlink, out);
475 }
476 
478 {
479  AVFilterContext *ctx = inlink->dst;
480  ShowFreqsContext *s = ctx->priv;
481  const int offset = s->win_size - s->hop_size;
482  int64_t pts = in->pts;
483 
484  for (int ch = 0; ch < in->ch_layout.nb_channels; ch++) {
485  float *dst = (float *)s->window->extended_data[ch];
486 
487  memmove(dst, &dst[s->hop_size], offset * sizeof(float));
488  memcpy(&dst[offset], in->extended_data[ch], in->nb_samples * sizeof(float));
489  memset(&dst[offset + in->nb_samples], 0, (s->hop_size - in->nb_samples) * sizeof(float));
490  }
491 
492  av_frame_free(&in);
493 
494  return plot_freqs(inlink, pts);
495 }
496 
498 {
499  AVFilterLink *inlink = ctx->inputs[0];
500  AVFilterLink *outlink = ctx->outputs[0];
501  ShowFreqsContext *s = ctx->priv;
502  AVFrame *in;
503  int ret;
504 
506 
507  ret = ff_inlink_consume_samples(inlink, s->hop_size, s->hop_size, &in);
508  if (ret < 0)
509  return ret;
510 
511  if (ret > 0)
512  ret = filter_frame(inlink, in);
513  if (ret < 0)
514  return ret;
515 
516  if (ff_inlink_queued_samples(inlink) >= s->hop_size) {
518  return 0;
519  }
520 
523 
524  return FFERROR_NOT_READY;
525 }
526 
528 {
529  ShowFreqsContext *s = ctx->priv;
530  int i;
531 
532  av_channel_layout_uninit(&s->ch_layout);
533  av_tx_uninit(&s->fft);
534  for (i = 0; i < s->nb_channels; i++) {
535  if (s->fft_input)
536  av_freep(&s->fft_input[i]);
537  if (s->fft_data)
538  av_freep(&s->fft_data[i]);
539  if (s->avg_data)
540  av_freep(&s->avg_data[i]);
541  }
542  av_freep(&s->bypass);
543  av_freep(&s->fft_input);
544  av_freep(&s->fft_data);
545  av_freep(&s->avg_data);
546  av_freep(&s->window_func_lut);
547  av_frame_free(&s->window);
548 }
549 
550 static const AVFilterPad showfreqs_inputs[] = {
551  {
552  .name = "default",
553  .type = AVMEDIA_TYPE_AUDIO,
554  },
555 };
556 
557 static const AVFilterPad showfreqs_outputs[] = {
558  {
559  .name = "default",
560  .type = AVMEDIA_TYPE_VIDEO,
561  .config_props = config_output,
562  },
563 };
564 
566  .name = "showfreqs",
567  .description = NULL_IF_CONFIG_SMALL("Convert input audio to a frequencies video output."),
568  .uninit = uninit,
569  .priv_size = sizeof(ShowFreqsContext),
570  .activate = activate,
574  .priv_class = &showfreqs_class,
575 };
formats
formats
Definition: signature.h:48
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:101
ShowFreqsContext::tx_fn
av_tx_fn tx_fn
Definition: avf_showfreqs.c:58
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:100
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
ShowFreqsContext::fscale
int fscale
Definition: avf_showfreqs.c:51
av_clip
#define av_clip
Definition: common.h:95
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:380
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
out
FILE * out
Definition: movenc.c:54
M
#define M(a, b)
ShowFreqsContext::win_func
int win_func
Definition: avf_showfreqs.c:53
color
Definition: vf_paletteuse.c:509
ShowFreqsContext::old_pts
int64_t old_pts
Definition: avf_showfreqs.c:74
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:969
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:947
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:591
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:326
ShowFreqsContext::scale
float scale
Definition: avf_showfreqs.c:71
av_parse_color
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition: parseutils.c:356
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:238
AVTXContext
Definition: tx_priv.h:228
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
NB_CMODES
@ NB_CMODES
Definition: avf_showfreqs.c:40
LINE
@ LINE
Definition: avf_showfreqs.c:39
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:99
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:566
ShowFreqsContext::nb_draw_channels
int nb_draw_channels
Definition: avf_showfreqs.c:68
RE
#define RE(x, ch)
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:437
w
uint8_t w
Definition: llviddspenc.c:38
draw_dot
static void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
Definition: avf_showfreqs.c:253
av_channel_layout_channel_from_index
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
Definition: channel_layout.c:796
ShowFreqsContext::fft
AVTXContext * fft
Definition: avf_showfreqs.c:57
showfreqs_inputs
static const AVFilterPad showfreqs_inputs[]
Definition: avf_showfreqs.c:550
DELAY
@ DELAY
Definition: avf_showfreqs.c:38
AVOption
AVOption.
Definition: opt.h:251
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:171
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: avf_showfreqs.c:118
NB_ASCALES
@ NB_ASCALES
Definition: avf_showfreqs.c:42
float.h
AVComplexFloat
Definition: tx.h:27
WIN_FUNC_OPTION
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
Definition: window_func.h:37
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:165
ff_avf_showfreqs
const AVFilter ff_avf_showfreqs
Definition: avf_showfreqs.c:565
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
P
#define P(a, b)
video.h
ShowFreqsContext::w
int w
Definition: avf_showfreqs.c:46
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:883
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
ShowFreqsContext::frame_rate
AVRational frame_rate
Definition: avf_showfreqs.c:75
OFFSET
#define OFFSET(x)
Definition: avf_showfreqs.c:78
ShowFreqsContext::fft_data
AVComplexFloat ** fft_data
Definition: avf_showfreqs.c:60
ShowFreqsContext::h
int h
Definition: avf_showfreqs.c:46
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:723
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
pts
static int64_t pts
Definition: transcode_aac.c:653
FS_LOG
@ FS_LOG
Definition: avf_showfreqs.c:41
ChannelMode
ChannelMode
Definition: avf_showfreqs.c:40
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
cbrt
#define cbrt
Definition: tablegen.h:35
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AmplitudeScale
AmplitudeScale
Definition: avf_ahistogram.c:32
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:127
BAR
@ BAR
Definition: avf_showfreqs.c:39
float
float
Definition: af_crystalizer.c:122
ShowFreqsContext::window
AVFrame * window
Definition: avf_showfreqs.c:61
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
ShowFreqsContext::nb_channels
int nb_channels
Definition: avf_showfreqs.c:67
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_showfreqs.c:149
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:596
av_strtok
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition: avstring.c:179
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
AV_TX_FLOAT_FFT
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
Definition: tx.h:47
ShowFreqsContext::colors
char * colors
Definition: avf_showfreqs.c:72
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
FS_LINEAR
@ FS_LINEAR
Definition: avf_showfreqs.c:41
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:194
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
ShowFreqsContext::fft_size
int fft_size
Definition: avf_showfreqs.c:50
if
if(ret)
Definition: filter_design.txt:179
SEPARATE
@ SEPARATE
Definition: avf_showfreqs.c:40
ShowFreqsContext::nb_freq
int nb_freq
Definition: avf_showfreqs.c:69
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:32
FLAGS
#define FLAGS
Definition: avf_showfreqs.c:79
ShowFreqsContext::fft_input
AVComplexFloat ** fft_input
Definition: avf_showfreqs.c:59
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1383
NULL
#define NULL
Definition: coverity.c:32
ShowFreqsContext::cmode
int cmode
Definition: avf_showfreqs.c:49
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
parseutils.h
ShowFreqsContext::minamp
float minamp
Definition: avf_showfreqs.c:65
generate_window_func
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
Definition: window_func.h:76
WFUNC_HANNING
@ WFUNC_HANNING
Definition: window_func.h:29
ShowFreqsContext::ascale
int ascale
Definition: avf_showfreqs.c:51
ShowFreqsContext::ch_layout_str
char * ch_layout_str
Definition: avf_showfreqs.c:54
ShowFreqsContext::avg_data
float ** avg_data
Definition: avf_showfreqs.c:62
f
f
Definition: af_crystalizer.c:122
ShowFreqsContext::hop_size
int hop_size
Definition: avf_showfreqs.c:66
DataMode
DataMode
Definition: avf_showfreqs.c:38
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:115
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:301
activate
static int activate(AVFilterContext *ctx)
Definition: avf_showfreqs.c:497
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
ShowFreqsContext::mode
int mode
Definition: avf_showfreqs.c:47
ShowFreqsContext::bypass
uint8_t * bypass
Definition: avf_showfreqs.c:55
avg
#define avg(a, b, c, d)
Definition: colorspacedsp_template.c:28
IM
#define IM(x, ch)
ShowFreqsContext
Definition: avf_showfreqs.c:44
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
FrequencyScale
FrequencyScale
Definition: avf_showcwt.c:37
MAGNITUDE
@ MAGNITUDE
Definition: avf_showfreqs.c:38
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
M_PI
#define M_PI
Definition: mathematics.h:52
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
AVChannel
AVChannel
Definition: channel_layout.h:47
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:404
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:410
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AS_LINEAR
@ AS_LINEAR
Definition: avf_showfreqs.c:42
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:391
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FS_RLOG
@ FS_RLOG
Definition: avf_showfreqs.c:41
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
get_sx
static int get_sx(ShowFreqsContext *s, int f)
Definition: avf_showfreqs.c:264
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: avf_showfreqs.c:477
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
ff_inlink_queued_samples
int ff_inlink_queued_samples(AVFilterLink *link)
Definition: avfilter.c:1343
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
AVFilter
Filter definition.
Definition: avfilter.h:161
NB_MODES
@ NB_MODES
Definition: avf_showfreqs.c:39
ret
ret
Definition: filter_design.txt:187
plot_freq
static void plot_freq(ShowFreqsContext *s, int ch, double a, int f, uint8_t fg[4], int *prev_y, AVFrame *out, AVFilterLink *outlink)
Definition: avf_showfreqs.c:294
showfreqs_outputs
static const AVFilterPad showfreqs_outputs[]
Definition: avf_showfreqs.c:557
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
ShowFreqsContext::window_func_lut
float * window_func_lut
Definition: avf_showfreqs.c:63
window_func.h
NB_FSCALES
@ NB_FSCALES
Definition: avf_showfreqs.c:41
ShowFreqsContext::pts
int64_t pts
Definition: avf_showfreqs.c:73
showfreqs_options
static const AVOption showfreqs_options[]
Definition: avf_showfreqs.c:81
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:551
channel_layout.h
av_channel_layout_index_from_channel
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
Definition: channel_layout.c:836
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:632
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showfreqs.c:527
ShowFreqsContext::data_mode
int data_mode
Definition: avf_showfreqs.c:48
AVFilterContext
An instance of a filter.
Definition: avfilter.h:392
ShowFreqsContext::win_size
int win_size
Definition: avf_showfreqs.c:70
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:639
DisplayMode
DisplayMode
Definition: avf_ahistogram.c:34
ShowFreqsContext::avg
int avg
Definition: avf_showfreqs.c:52
get_bsize
static float get_bsize(ShowFreqsContext *s, int f)
Definition: avf_showfreqs.c:278
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ShowFreqsContext::ch_layout
AVChannelLayout ch_layout
Definition: avf_showfreqs.c:56
audio.h
NB_DATA
@ NB_DATA
Definition: avf_showfreqs.c:38
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:496
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
FF_FILTER_FORWARD_STATUS
FF_FILTER_FORWARD_STATUS(inlink, outlink)
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
AS_CBRT
@ AS_CBRT
Definition: avf_showfreqs.c:42
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
COMBINED
@ COMBINED
Definition: avf_showfreqs.c:40
PHASE
@ PHASE
Definition: avf_showfreqs.c:38
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
DOT
@ DOT
Definition: avf_showfreqs.c:39
avstring.h
plot_freqs
static int plot_freqs(AVFilterLink *inlink, int64_t pts)
Definition: avf_showfreqs.c:377
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(showfreqs)
AS_LOG
@ AS_LOG
Definition: avf_showfreqs.c:42
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
channel
channel
Definition: ebur128.h:39
ShowFreqsContext::overlap
float overlap
Definition: avf_showfreqs.c:64
AS_SQRT
@ AS_SQRT
Definition: avf_showfreqs.c:42
av_clipd
av_clipd
Definition: af_crystalizer.c:132
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:204
tx.h
min
float min
Definition: vorbis_enc_data.h:429