FFmpeg
avf_showcwt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 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/cpu.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/parseutils.h"
31 #include "audio.h"
32 #include "video.h"
33 #include "avfilter.h"
34 #include "filters.h"
35 #include "internal.h"
36 
44 };
45 
52 };
53 
54 enum SlideMode {
59 };
60 
61 typedef struct ShowCWTContext {
62  const AVClass *class;
63  int w, h;
64  int mode;
65  char *rate_str;
76  int pos;
77  int64_t in_pts;
78  int64_t old_pts;
79  int64_t eof_pts;
82  unsigned *index;
95  int pps;
96  int eof;
97  int slide;
98  int new_frame;
99  int direction;
100  int hop_size;
113  float deviation;
115 
116 #define OFFSET(x) offsetof(ShowCWTContext, x)
117 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
118 
119 static const AVOption showcwt_options[] = {
120  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x512"}, 0, 0, FLAGS },
121  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x512"}, 0, 0, FLAGS },
122  { "rate", "set video rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
123  { "r", "set video rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
124  { "scale", "set frequency scale", OFFSET(frequency_scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FSCALE-1, FLAGS, "scale" },
125  { "linear", "linear", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_LINEAR}, 0, 0, FLAGS, "scale" },
126  { "log2", "logarithmic", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_LOG2}, 0, 0, FLAGS, "scale" },
127  { "bark", "bark", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_BARK}, 0, 0, FLAGS, "scale" },
128  { "mel", "mel", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_MEL}, 0, 0, FLAGS, "scale" },
129  { "erbs", "erbs", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_ERBS}, 0, 0, FLAGS, "scale" },
130  { "min", "set minimum frequency", OFFSET(minimum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20.}, 1, 2000, FLAGS },
131  { "max", "set maximum frequency", OFFSET(maximum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20000.}, 0, 192000, FLAGS },
132  { "logb", "set logarithmic basis", OFFSET(logarithmic_basis), AV_OPT_TYPE_FLOAT, {.dbl = 0.0001}, 0, 1, FLAGS },
133  { "deviation", "set frequency deviation", OFFSET(deviation), AV_OPT_TYPE_FLOAT, {.dbl = 1.}, 0, 10, FLAGS },
134  { "pps", "set pixels per second", OFFSET(pps), AV_OPT_TYPE_INT, {.i64 = 64}, 1, 1024, FLAGS },
135  { "mode", "set output mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "mode" },
136  { "magnitude", "magnitude", 0, AV_OPT_TYPE_CONST,{.i64=0}, 0, 0, FLAGS, "mode" },
137  { "phase", "phase", 0, AV_OPT_TYPE_CONST,{.i64=1}, 0, 0, FLAGS, "mode" },
138  { "magphase", "magnitude+phase", 0, AV_OPT_TYPE_CONST,{.i64=2}, 0, 0, FLAGS, "mode" },
139  { "channel", "color per channel", 0, AV_OPT_TYPE_CONST,{.i64=3}, 0, 0, FLAGS, "mode" },
140  { "stereo", "stereo difference", 0, AV_OPT_TYPE_CONST,{.i64=4}, 0, 0, FLAGS, "mode" },
141  { "slide", "set slide mode", OFFSET(slide), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SLIDE-1, FLAGS, "slide" },
142  { "replace", "replace", 0, AV_OPT_TYPE_CONST,{.i64=SLIDE_REPLACE},0, 0, FLAGS, "slide" },
143  { "scroll", "scroll", 0, AV_OPT_TYPE_CONST,{.i64=SLIDE_SCROLL}, 0, 0, FLAGS, "slide" },
144  { "frame", "frame", 0, AV_OPT_TYPE_CONST,{.i64=SLIDE_FRAME}, 0, 0, FLAGS, "slide" },
145  { "direction", "set direction mode", OFFSET(direction), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_DIRECTION-1, FLAGS, "direction" },
146  { "lr", "left to right", 0, AV_OPT_TYPE_CONST,{.i64=DIRECTION_LR}, 0, 0, FLAGS, "direction" },
147  { "rl", "right to left", 0, AV_OPT_TYPE_CONST,{.i64=DIRECTION_RL}, 0, 0, FLAGS, "direction" },
148  { "ud", "up to down", 0, AV_OPT_TYPE_CONST,{.i64=DIRECTION_UD}, 0, 0, FLAGS, "direction" },
149  { "du", "down to up", 0, AV_OPT_TYPE_CONST,{.i64=DIRECTION_DU}, 0, 0, FLAGS, "direction" },
150  { NULL }
151 };
152 
153 AVFILTER_DEFINE_CLASS(showcwt);
154 
156 {
157  ShowCWTContext *s = ctx->priv;
158 
159  av_freep(&s->frequency_band);
160  av_freep(&s->kernel_start);
161  av_freep(&s->kernel_stop);
162  av_freep(&s->index);
163 
164  av_frame_free(&s->kernel);
165  av_frame_free(&s->cache[0]);
166  av_frame_free(&s->cache[1]);
167  av_frame_free(&s->outpicref);
168  av_frame_free(&s->fft_in);
169  av_frame_free(&s->fft_out);
170  av_frame_free(&s->ifft_in);
171  av_frame_free(&s->ifft_out);
172  av_frame_free(&s->ch_out);
173 
174  if (s->fft) {
175  for (int n = 0; n < s->nb_threads; n++)
176  av_tx_uninit(&s->fft[n]);
177  av_freep(&s->fft);
178  }
179 
180  if (s->ifft) {
181  for (int n = 0; n < s->nb_threads; n++)
182  av_tx_uninit(&s->ifft[n]);
183  av_freep(&s->ifft);
184  }
185 }
186 
188 {
191  AVFilterLink *inlink = ctx->inputs[0];
192  AVFilterLink *outlink = ctx->outputs[0];
195  int ret;
196 
198  if ((ret = ff_formats_ref(formats, &inlink->outcfg.formats)) < 0)
199  return ret;
200 
202  if ((ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts)) < 0)
203  return ret;
204 
206  if ((ret = ff_formats_ref(formats, &inlink->outcfg.samplerates)) < 0)
207  return ret;
208 
210  if ((ret = ff_formats_ref(formats, &outlink->incfg.formats)) < 0)
211  return ret;
212 
213  return 0;
214 }
215 
216 static void frequency_band(float *frequency_band,
217  int frequency_band_count,
218  float frequency_range,
219  float frequency_offset,
220  int frequency_scale, float deviation)
221 {
222  deviation *= sqrtf(1.f / (4.f * M_PI)); // Heisenberg Gabor Limit
223  for (int y = 0; y < frequency_band_count; y++) {
224  float frequency = frequency_range * (1.f - (float)y / frequency_band_count) + frequency_offset;
225  float frequency_derivative = frequency_range / frequency_band_count;
226 
227  switch (frequency_scale) {
228  case FSCALE_LOG2:
229  frequency = powf(2.f, frequency);
230  frequency_derivative *= logf(2.f) * frequency;
231  break;
232  case FSCALE_BARK:
233  frequency = 600.f * sinhf(frequency / 6.f);
234  frequency_derivative *= sqrtf(frequency * frequency + 360000.f) / 6.f;
235  break;
236  case FSCALE_MEL:
237  frequency = 700.f * (powf(10.f, frequency / 2595.f) - 1.f);
238  frequency_derivative *= (frequency + 700.f) * logf(10.f) / 2595.f;
239  break;
240  case FSCALE_ERBS:
241  frequency = 676170.4f / (47.06538f - expf(frequency * 0.08950404f)) - 14678.49f;
242  frequency_derivative *= (frequency * frequency + 14990.4 * frequency + 4577850.f) / 160514.f;
243  break;
244  }
245 
246  frequency_band[y*2 ] = frequency;
247  frequency_band[y*2+1] = frequency_derivative * deviation;
248  }
249 }
250 
251 static float remap_log(float value, float log_factor)
252 {
253  float sign = (0 < value) - (value < 0);
254 
255  value = logf(value * sign) * log_factor;
256 
257  return 1.f - av_clipf(value, 0.f, 1.f);
258 }
259 
260 static int run_channel_cwt_prepare(AVFilterContext *ctx, void *arg, int jobnr, int ch)
261 {
262  ShowCWTContext *s = ctx->priv;
263  const int hop_size = s->hop_size;
264  AVFrame *fin = arg;
265  float *cache0 = (float *)s->cache[0]->extended_data[ch];
266  float *cache = (float *)s->cache[1]->extended_data[ch];
267  AVComplexFloat *src = (AVComplexFloat *)s->fft_in->extended_data[ch];
268  AVComplexFloat *dst = (AVComplexFloat *)s->fft_out->extended_data[ch];
269 
270  if (fin) {
271  const int offset = s->hop_index;
272  const float *input = (const float *)fin->extended_data[ch];
273 
274  memcpy(&cache[offset], input,
275  fin->nb_samples * sizeof(float));
276  }
277 
278  if (fin == NULL) {
279  memset(&cache[s->hop_index], 0,
280  (hop_size - s->hop_index) * sizeof(float));
281  } else if (s->hop_index + fin->nb_samples < hop_size) {
282  return 0;
283  }
284 
285  for (int n = 0; n < hop_size; n++) {
286  src[n].re = cache0[n];
287  src[n].im = 0.f;
288  src[n + hop_size].re = cache[n];
289  src[n + hop_size].im = 0.f;
290  }
291 
292  s->tx_fn(s->fft[jobnr], dst, src, sizeof(*src));
293 
294  return 0;
295 }
296 
297 static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
298 {
299  ShowCWTContext *s = ctx->priv;
300  const ptrdiff_t ylinesize = s->outpicref->linesize[0];
301  const ptrdiff_t ulinesize = s->outpicref->linesize[1];
302  const ptrdiff_t vlinesize = s->outpicref->linesize[2];
303  const ptrdiff_t alinesize = s->outpicref->linesize[3];
304  const float log_factor = 1.f/logf(s->logarithmic_basis);
305  const int count = s->frequency_band_count;
306  const int start = (count * jobnr) / nb_jobs;
307  const int end = (count * (jobnr+1)) / nb_jobs;
308  const int ihop_index = s->ihop_index;
309  const int ihop_size = s->ihop_size;
310  const int direction = s->direction;
311  uint8_t *dstY, *dstU, *dstV, *dstA;
312  const int mode = s->mode;
313  const int w_1 = s->w - 1;
314  const int x = s->pos;
315  float Y, U, V;
316 
317  for (int y = start; y < end; y++) {
318  const AVComplexFloat *src = ((const AVComplexFloat *)s->ch_out->extended_data[0]) +
319  y * ihop_size + ihop_index;
320 
321  switch (direction) {
322  case DIRECTION_LR:
323  case DIRECTION_RL:
324  dstY = s->outpicref->data[0] + y * ylinesize;
325  dstU = s->outpicref->data[1] + y * ulinesize;
326  dstV = s->outpicref->data[2] + y * vlinesize;
327  dstA = s->outpicref->data[3] ? s->outpicref->data[3] + y * alinesize : NULL;
328  break;
329  case DIRECTION_UD:
330  case DIRECTION_DU:
331  dstY = s->outpicref->data[0] + x * ylinesize + w_1 - y;
332  dstU = s->outpicref->data[1] + x * ulinesize + w_1 - y;
333  dstV = s->outpicref->data[2] + x * vlinesize + w_1 - y;
334  dstA = s->outpicref->data[3] ? s->outpicref->data[3] + x * alinesize + w_1 - y : NULL;
335  break;
336  }
337 
338  switch (s->slide) {
339  case SLIDE_REPLACE:
340  case SLIDE_FRAME:
341  /* nothing to do here */
342  break;
343  case SLIDE_SCROLL:
344  switch (s->direction) {
345  case DIRECTION_RL:
346  memmove(dstY, dstY + 1, w_1);
347  memmove(dstU, dstU + 1, w_1);
348  memmove(dstV, dstV + 1, w_1);
349  if (dstA != NULL)
350  memmove(dstA, dstA + 1, w_1);
351  break;
352  case DIRECTION_LR:
353  memmove(dstY + 1, dstY, w_1);
354  memmove(dstU + 1, dstU, w_1);
355  memmove(dstV + 1, dstV, w_1);
356  if (dstA != NULL)
357  memmove(dstA + 1, dstA, w_1);
358  break;
359  }
360  break;
361  }
362 
363  if (direction == DIRECTION_RL ||
364  direction == DIRECTION_LR) {
365  dstY += x;
366  dstU += x;
367  dstV += x;
368  if (dstA != NULL)
369  dstA += x;
370  }
371 
372  switch (mode) {
373  case 4:
374  {
375  const AVComplexFloat *src2 = ((const AVComplexFloat *)s->ch_out->extended_data[FFMIN(1, s->nb_channels - 1)]) +
376  y * ihop_size + ihop_index;
377  float z, u, v;
378 
379  z = hypotf(src[0].re + src2[0].re, src[0].im + src2[0].im);
380  u = hypotf(src[0].re, src[0].im);
381  v = hypotf(src2[0].re, src2[0].im);
382 
383  z = remap_log(z, log_factor);
384  u = remap_log(u, log_factor);
385  v = remap_log(v, log_factor);
386 
387  Y = z;
388  U = 0.5f + z * sinf((v - u) * M_PI_2);
389  V = 0.5f + z * sinf((u - v) * M_PI_2);
390 
391  dstY[0] = av_clip_uint8(lrintf(Y * 255.f));
392  dstU[0] = av_clip_uint8(lrintf(U * 255.f));
393  dstV[0] = av_clip_uint8(lrintf(V * 255.f));
394  if (dstA)
395  dstA[0] = dstY[0];
396  }
397  break;
398  case 3:
399  {
400  const int nb_channels = s->nb_channels;
401  const float yf = 1.f / nb_channels;
402 
403  Y = 0.f;
404  U = V = 0.5f;
405  for (int ch = 0; ch < nb_channels; ch++) {
406  const AVComplexFloat *src = ((const AVComplexFloat *)s->ch_out->extended_data[ch]) +
407  y * ihop_size + ihop_index;
408  float z;
409 
410  z = hypotf(src[0].re, src[0].im);
411  z = remap_log(z, log_factor);
412 
413  Y += z * yf;
414  U += z * yf * sinf(2.f * M_PI * ch * yf);
415  V += z * yf * cosf(2.f * M_PI * ch * yf);
416  }
417 
418  dstY[0] = av_clip_uint8(lrintf(Y * 255.f));
419  dstU[0] = av_clip_uint8(lrintf(U * 255.f));
420  dstV[0] = av_clip_uint8(lrintf(V * 255.f));
421  if (dstA)
422  dstA[0] = dstY[0];
423  }
424  break;
425  case 2:
426  Y = hypotf(src[0].re, src[0].im);
427  Y = remap_log(Y, log_factor);
428  U = atan2f(src[0].im, src[0].re);
429  U = 0.5f + 0.5f * U * Y / M_PI;
430  V = 1.f - U;
431 
432  dstY[0] = av_clip_uint8(lrintf(Y * 255.f));
433  dstU[0] = av_clip_uint8(lrintf(U * 255.f));
434  dstV[0] = av_clip_uint8(lrintf(V * 255.f));
435  if (dstA)
436  dstA[0] = dstY[0];
437  break;
438  case 1:
439  Y = atan2f(src[0].im, src[0].re);
440  Y = 0.5f + 0.5f * Y / M_PI;
441 
442  dstY[0] = av_clip_uint8(lrintf(Y * 255.f));
443  if (dstA)
444  dstA[0] = dstY[0];
445  break;
446  case 0:
447  Y = hypotf(src[0].re, src[0].im);
448  Y = remap_log(Y, log_factor);
449 
450  dstY[0] = av_clip_uint8(lrintf(Y * 255.f));
451  if (dstA)
452  dstA[0] = dstY[0];
453  break;
454  }
455  }
456 
457  return 0;
458 }
459 
460 static int run_channel_cwt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
461 {
462  ShowCWTContext *s = ctx->priv;
463  const int ch = *(int *)arg;
464  AVComplexFloat *dst = (AVComplexFloat *)s->fft_out->extended_data[ch];
465  const int output_sample_count = s->output_sample_count;
466  const int ihop_size = s->ihop_size;
467  const int ioffset = (s->output_padding_size - ihop_size) >> 1;
468  const int count = s->frequency_band_count;
469  const int start = (count * jobnr) / nb_jobs;
470  const int end = (count * (jobnr+1)) / nb_jobs;
471 
472  for (int y = start; y < end; y++) {
473  AVComplexFloat *isrc = (AVComplexFloat *)s->ifft_in->extended_data[y];
474  AVComplexFloat *idst = (AVComplexFloat *)s->ifft_out->extended_data[y];
475  AVComplexFloat *chout = ((AVComplexFloat *)s->ch_out->extended_data[ch]) + y * ihop_size;
476  const float *kernel = (const float *)s->kernel->extended_data[y];
477  const unsigned *index = (const unsigned *)s->index;
478  const int kernel_start = s->kernel_start[y];
479  const int kernel_stop = s->kernel_stop[y];
480 
481  memset(isrc, 0, sizeof(*isrc) * output_sample_count);
482  for (int i = kernel_start; i < kernel_stop; i++) {
483  const unsigned n = index[i];
484  const float ff = kernel[i];
485 
486  isrc[n].re += ff * dst[i].re;
487  isrc[n].im += ff * dst[i].im;
488  }
489 
490  s->itx_fn(s->ifft[jobnr], idst, isrc, sizeof(*isrc));
491 
492  memcpy(chout, idst + ioffset, sizeof(*chout) * ihop_size);
493  }
494 
495  return 0;
496 }
497 
499 {
500  ShowCWTContext *s = ctx->priv;
501  const int size = s->input_sample_count;
502  const float scale_factor = 1.f/(float)size;
503  const int output_sample_count = s->output_sample_count;
504  const int fsize = s->frequency_band_count;
505  unsigned *index = s->index;
506 
507  for (int y = 0; y < fsize; y++) {
508  float *kernel = (float *)s->kernel->extended_data[y];
509  int *kernel_start = s->kernel_start;
510  int *kernel_stop = s->kernel_stop;
511  float frequency = s->frequency_band[y*2];
512  float deviation = 1.f / (s->frequency_band[y*2+1] *
513  output_sample_count);
514 
515  for (int n = 0; n < size; n++) {
516  float ff, f = fabsf(n-frequency);
517 
518  f = size - fabsf(f - size);
519  ff = expf(-f*f*deviation) * scale_factor;
520  kernel[n] = ff;
521  }
522 
523  for (int n = 0; n < size; n++) {
524  if (kernel[n] != 0.f) {
525  kernel_start[y] = n;
526  break;
527  }
528  }
529 
530  for (int n = 0; n < size; n++) {
531  if (kernel[size - n - 1] != 0.f) {
532  kernel_stop[y] = size - n;
533  break;
534  }
535  }
536  }
537 
538  for (int n = 0; n < size; n++)
539  index[n] = n % output_sample_count;
540 }
541 
542 static int config_output(AVFilterLink *outlink)
543 {
544  AVFilterContext *ctx = outlink->src;
545  AVFilterLink *inlink = ctx->inputs[0];
546  ShowCWTContext *s = ctx->priv;
547  float maximum_frequency = fminf(s->maximum_frequency, inlink->sample_rate * 0.5f);
548  float minimum_frequency = s->minimum_frequency;
549  float scale = 1.f, factor;
550  int ret;
551 
552  uninit(ctx);
553 
554  switch (s->direction) {
555  case DIRECTION_LR:
556  case DIRECTION_RL:
557  s->frequency_band_count = s->h;
558  break;
559  case DIRECTION_UD:
560  case DIRECTION_DU:
561  s->frequency_band_count = s->w;
562  break;
563  }
564 
565  s->new_frame = 1;
566  s->nb_threads = FFMIN(s->frequency_band_count, ff_filter_get_nb_threads(ctx));
567  s->nb_channels = inlink->ch_layout.nb_channels;
568  s->old_pts = AV_NOPTS_VALUE;
569  s->eof_pts = AV_NOPTS_VALUE;
570  s->nb_consumed_samples = 65536;
571 
572  s->input_sample_count = s->nb_consumed_samples;
573  s->hop_size = s->nb_consumed_samples >> 1;
574  s->input_padding_size = 65536;
575  s->output_padding_size = FFMAX(16, s->input_padding_size * s->pps / inlink->sample_rate);
576 
577  outlink->w = s->w;
578  outlink->h = s->h;
579  outlink->sample_aspect_ratio = (AVRational){1,1};
580 
581  s->fft_in_size = FFALIGN(s->input_padding_size, av_cpu_max_align());
582  s->fft_out_size = FFALIGN(s->input_padding_size, av_cpu_max_align());
583 
584  s->output_sample_count = s->output_padding_size;
585 
586  s->ifft_in_size = FFALIGN(s->output_padding_size, av_cpu_max_align());
587  s->ifft_out_size = FFALIGN(s->output_padding_size, av_cpu_max_align());
588  s->ihop_size = s->output_padding_size >> 1;
589 
590  s->fft = av_calloc(s->nb_threads, sizeof(*s->fft));
591  if (!s->fft)
592  return AVERROR(ENOMEM);
593 
594  for (int n = 0; n < s->nb_threads; n++) {
595  ret = av_tx_init(&s->fft[n], &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->input_padding_size, &scale, 0);
596  if (ret < 0)
597  return ret;
598  }
599 
600  s->ifft = av_calloc(s->nb_threads, sizeof(*s->ifft));
601  if (!s->ifft)
602  return AVERROR(ENOMEM);
603 
604  for (int n = 0; n < s->nb_threads; n++) {
605  ret = av_tx_init(&s->ifft[n], &s->itx_fn, AV_TX_FLOAT_FFT, 1, s->output_padding_size, &scale, 0);
606  if (ret < 0)
607  return ret;
608  }
609 
610  s->frequency_band = av_calloc(s->frequency_band_count,
611  sizeof(*s->frequency_band) * 2);
612  s->outpicref = ff_get_video_buffer(outlink, outlink->w, outlink->h);
613  s->fft_in = ff_get_audio_buffer(inlink, s->fft_in_size * 2);
614  s->fft_out = ff_get_audio_buffer(inlink, s->fft_out_size * 2);
615  s->cache[0] = ff_get_audio_buffer(inlink, s->hop_size);
616  s->cache[1] = ff_get_audio_buffer(inlink, s->hop_size);
617  s->ch_out = ff_get_audio_buffer(inlink, s->frequency_band_count * 2 * s->ihop_size);
618  s->ifft_in = av_frame_alloc();
619  s->ifft_out = av_frame_alloc();
620  s->kernel = av_frame_alloc();
621  s->index = av_calloc(s->input_padding_size, sizeof(*s->index));
622  s->kernel_start = av_calloc(s->frequency_band_count, sizeof(*s->kernel_start));
623  s->kernel_stop = av_calloc(s->frequency_band_count, sizeof(*s->kernel_stop));
624  if (!s->outpicref || !s->fft_in || !s->fft_out ||
625  !s->ifft_in || !s->ifft_out || !s->kernel_start || !s->kernel_stop ||
626  !s->frequency_band || !s->kernel || !s->cache[0] || !s->cache[1] || !s->index)
627  return AVERROR(ENOMEM);
628 
629  s->ifft_in->format = inlink->format;
630  s->ifft_in->nb_samples = s->ifft_in_size * 2;
631  s->ifft_in->ch_layout.nb_channels = s->frequency_band_count;
632  ret = av_frame_get_buffer(s->ifft_in, 0);
633  if (ret < 0)
634  return ret;
635 
636  s->ifft_out->format = inlink->format;
637  s->ifft_out->nb_samples = s->ifft_out_size * 2;
638  s->ifft_out->ch_layout.nb_channels = s->frequency_band_count;
639  ret = av_frame_get_buffer(s->ifft_out, 0);
640  if (ret < 0)
641  return ret;
642 
643  s->kernel->format = inlink->format;
644  s->kernel->nb_samples = s->input_padding_size;
645  s->kernel->ch_layout.nb_channels = s->frequency_band_count;
646  ret = av_frame_get_buffer(s->kernel, 0);
647  if (ret < 0)
648  return ret;
649 
650  s->outpicref->sample_aspect_ratio = (AVRational){1,1};
651 
652  for (int y = 0; y < outlink->h; y++) {
653  memset(s->outpicref->data[0] + y * s->outpicref->linesize[0], 0, outlink->w);
654  memset(s->outpicref->data[1] + y * s->outpicref->linesize[1], 128, outlink->w);
655  memset(s->outpicref->data[2] + y * s->outpicref->linesize[2], 128, outlink->w);
656  if (s->outpicref->data[3])
657  memset(s->outpicref->data[3] + y * s->outpicref->linesize[3], 0, outlink->w);
658  }
659 
660  s->outpicref->color_range = AVCOL_RANGE_JPEG;
661 
662  factor = s->nb_consumed_samples / (float)inlink->sample_rate;
663  minimum_frequency *= factor;
664  maximum_frequency *= factor;
665 
666  switch (s->frequency_scale) {
667  case FSCALE_LOG2:
668  minimum_frequency = logf(minimum_frequency) / logf(2.f);
669  maximum_frequency = logf(maximum_frequency) / logf(2.f);
670  break;
671  case FSCALE_BARK:
672  minimum_frequency = 6.f * asinhf(minimum_frequency / 600.f);
673  maximum_frequency = 6.f * asinhf(maximum_frequency / 600.f);
674  break;
675  case FSCALE_MEL:
676  minimum_frequency = 2595.f * log10f(1.f + minimum_frequency / 700.f);
677  maximum_frequency = 2595.f * log10f(1.f + maximum_frequency / 700.f);
678  break;
679  case FSCALE_ERBS:
680  minimum_frequency = 11.17268f * log(1.f + (46.06538f * minimum_frequency) / (minimum_frequency + 14678.49f));
681  maximum_frequency = 11.17268f * log(1.f + (46.06538f * maximum_frequency) / (maximum_frequency + 14678.49f));
682  break;
683  }
684 
685  frequency_band(s->frequency_band,
686  s->frequency_band_count, maximum_frequency - minimum_frequency,
687  minimum_frequency, s->frequency_scale, s->deviation);
688 
689  av_log(ctx, AV_LOG_DEBUG, "input_sample_count: %d\n", s->input_sample_count);
690  av_log(ctx, AV_LOG_DEBUG, "output_sample_count: %d\n", s->output_sample_count);
691 
692  switch (s->direction) {
693  case DIRECTION_LR:
694  s->pos = 0;
695  break;
696  case DIRECTION_RL:
697  s->pos = s->w - 1;
698  break;
699  case DIRECTION_UD:
700  s->pos = 0;
701  break;
702  case DIRECTION_DU:
703  s->pos = s->h - 1;
704  break;
705  }
706 
707  s->auto_frame_rate = av_make_q(inlink->sample_rate, s->hop_size);
708  if (strcmp(s->rate_str, "auto")) {
709  ret = av_parse_video_rate(&s->frame_rate, s->rate_str);
710  } else {
711  s->frame_rate = s->auto_frame_rate;
712  }
713  outlink->frame_rate = s->frame_rate;
714  outlink->time_base = av_inv_q(outlink->frame_rate);
715 
717 
718  return 0;
719 }
720 
722 {
723  AVFilterLink *outlink = ctx->outputs[0];
724  AVFilterLink *inlink = ctx->inputs[0];
725  ShowCWTContext *s = ctx->priv;
726  const int nb_planes = 3 + (s->outpicref->data[3] != NULL);
727  int ret;
728 
729  switch (s->slide) {
730  case SLIDE_SCROLL:
731  switch (s->direction) {
732  case DIRECTION_UD:
733  for (int p = 0; p < nb_planes; p++) {
734  ptrdiff_t linesize = s->outpicref->linesize[p];
735 
736  for (int y = s->h - 1; y > 0; y--) {
737  uint8_t *dst = s->outpicref->data[p] + y * linesize;
738 
739  memmove(dst, dst - linesize, s->w);
740  }
741  }
742  break;
743  case DIRECTION_DU:
744  for (int p = 0; p < nb_planes; p++) {
745  ptrdiff_t linesize = s->outpicref->linesize[p];
746 
747  for (int y = 0; y < s->h - 1; y++) {
748  uint8_t *dst = s->outpicref->data[p] + y * linesize;
749 
750  memmove(dst, dst + linesize, s->w);
751  }
752  }
753  break;
754  }
755  break;
756  }
757 
758  ff_filter_execute(ctx, draw, NULL, NULL, s->nb_threads);
759 
760  switch (s->slide) {
761  case SLIDE_REPLACE:
762  case SLIDE_FRAME:
763  switch (s->direction) {
764  case DIRECTION_LR:
765  s->pos++;
766  if (s->pos >= s->w) {
767  s->pos = 0;
768  s->new_frame = 1;
769  }
770  break;
771  case DIRECTION_RL:
772  s->pos--;
773  if (s->pos < 0) {
774  s->pos = s->w - 1;
775  s->new_frame = 1;
776  }
777  break;
778  case DIRECTION_UD:
779  s->pos++;
780  if (s->pos >= s->h) {
781  s->pos = 0;
782  s->new_frame = 1;
783  }
784  break;
785  case DIRECTION_DU:
786  s->pos--;
787  if (s->pos < 0) {
788  s->pos = s->h - 1;
789  s->new_frame = 1;
790  }
791  break;
792  }
793  break;
794  case SLIDE_SCROLL:
795  switch (s->direction) {
796  case DIRECTION_UD:
797  case DIRECTION_LR:
798  s->pos = 0;
799  break;
800  case DIRECTION_RL:
801  s->pos = s->w - 1;
802  break;
803  case DIRECTION_DU:
804  s->pos = s->h - 1;
805  break;
806  }
807  break;
808  }
809 
810  if (s->slide == SLIDE_FRAME && s->eof) {
811  switch (s->direction) {
812  case DIRECTION_LR:
813  for (int p = 0; p < nb_planes; p++) {
814  ptrdiff_t linesize = s->outpicref->linesize[p];
815  const int size = s->w - s->pos;
816  const int fill = p > 0 && p < 3 ? 128 : 0;
817  const int x = s->pos;
818 
819  for (int y = 0; y < s->h; y++) {
820  uint8_t *dst = s->outpicref->data[p] + y * linesize + x;
821 
822  memset(dst, fill, size);
823  }
824  }
825  break;
826  case DIRECTION_RL:
827  for (int p = 0; p < nb_planes; p++) {
828  ptrdiff_t linesize = s->outpicref->linesize[p];
829  const int size = s->w - s->pos;
830  const int fill = p > 0 && p < 3 ? 128 : 0;
831 
832  for (int y = 0; y < s->h; y++) {
833  uint8_t *dst = s->outpicref->data[p] + y * linesize;
834 
835  memset(dst, fill, size);
836  }
837  }
838  break;
839  case DIRECTION_UD:
840  for (int p = 0; p < nb_planes; p++) {
841  ptrdiff_t linesize = s->outpicref->linesize[p];
842  const int fill = p > 0 && p < 3 ? 128 : 0;
843 
844  for (int y = s->pos; y < s->h; y++) {
845  uint8_t *dst = s->outpicref->data[p] + y * linesize;
846 
847  memset(dst, fill, s->w);
848  }
849  }
850  break;
851  case DIRECTION_DU:
852  for (int p = 0; p < nb_planes; p++) {
853  ptrdiff_t linesize = s->outpicref->linesize[p];
854  const int fill = p > 0 && p < 3 ? 128 : 0;
855 
856  for (int y = s->h - s->pos; y >= 0; y--) {
857  uint8_t *dst = s->outpicref->data[p] + y * linesize;
858 
859  memset(dst, fill, s->w);
860  }
861  }
862  break;
863  }
864  }
865 
866  s->new_frame = s->slide == SLIDE_FRAME && (s->new_frame || s->eof);
867 
868  if (s->slide != SLIDE_FRAME || s->new_frame == 1) {
869  int64_t pts_offset = s->new_frame ? 0LL : av_rescale(s->ihop_index, s->hop_size, s->ihop_size);
870 
871  s->outpicref->pts = av_rescale_q(s->in_pts + pts_offset, inlink->time_base, outlink->time_base);
872  s->outpicref->duration = 1;
873  }
874 
875  s->ihop_index++;
876  if (s->ihop_index >= s->ihop_size)
877  s->ihop_index = 0;
878 
879  if (s->slide == SLIDE_FRAME && s->new_frame == 0)
880  return 1;
881 
882  if (s->old_pts < s->outpicref->pts) {
883  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
884  if (!out)
885  return AVERROR(ENOMEM);
886  ret = av_frame_copy_props(out, s->outpicref);
887  if (ret < 0)
888  goto fail;
889  ret = av_frame_copy(out, s->outpicref);
890  if (ret < 0)
891  goto fail;
892  s->old_pts = s->outpicref->pts;
893  s->new_frame = 0;
894  ret = ff_filter_frame(outlink, out);
895  if (ret <= 0)
896  return ret;
897 fail:
898  av_frame_free(&out);
899  return ret;
900  }
901 
902  return 1;
903 }
904 
905 static int run_channels_cwt_prepare(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
906 {
907  ShowCWTContext *s = ctx->priv;
908  const int count = s->nb_channels;
909  const int start = (count * jobnr) / nb_jobs;
910  const int end = (count * (jobnr+1)) / nb_jobs;
911 
912  for (int ch = start; ch < end; ch++)
913  run_channel_cwt_prepare(ctx, arg, jobnr, ch);
914 
915  return 0;
916 }
917 
919 {
920  AVFilterLink *inlink = ctx->inputs[0];
921  AVFilterLink *outlink = ctx->outputs[0];
922  ShowCWTContext *s = ctx->priv;
923  int ret = 0, status;
924  int64_t pts;
925 
927 
928  if (s->outpicref) {
929  AVFrame *fin = NULL;
930 
931  if (s->ihop_index == 0) {
932  if (!s->eof) {
933  ret = ff_inlink_consume_samples(inlink, 1, s->hop_size - s->hop_index, &fin);
934  if (ret < 0)
935  return ret;
936  }
937 
938  if (ret > 0 || s->eof) {
940  FFMIN(s->nb_threads, s->nb_channels));
941  if (fin) {
942  if ((s->hop_index == 0 && s->slide != SLIDE_FRAME) || s->new_frame) {
943  s->in_pts = fin->pts;
944  s->new_frame = 0;
945  }
946  s->hop_index += fin->nb_samples;
947  av_frame_free(&fin);
948  } else {
949  s->hop_index = s->hop_size;
950  }
951  }
952  }
953 
954  if (s->hop_index >= s->hop_size || s->ihop_index > 0) {
955  if (s->hop_index) {
956  FFSWAP(AVFrame *, s->cache[0], s->cache[1]);
957  s->hop_index = 0;
958  }
959 
960  for (int ch = 0; ch < s->nb_channels && s->ihop_index == 0; ch++) {
961  ff_filter_execute(ctx, run_channel_cwt, (void *)&ch, NULL,
962  s->nb_threads);
963  }
964 
965  ret = output_frame(ctx);
966  if (ret != 1)
967  return ret;
968  }
969  }
970 
971  if (s->eof && s->eof_pts != AV_NOPTS_VALUE &&
972  (s->old_pts + 1 >= s->eof_pts || (s->slide == SLIDE_FRAME))) {
973  if (s->slide == SLIDE_FRAME)
974  ret = output_frame(ctx);
975  ff_outlink_set_status(outlink, AVERROR_EOF, s->eof_pts);
976  return ret;
977  }
978 
979  if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
980  if (status == AVERROR_EOF) {
981  s->eof = 1;
983  s->eof_pts = av_rescale_q(pts, inlink->time_base, outlink->time_base);
984  return 0;
985  }
986  }
987 
988  if (ff_inlink_queued_samples(inlink) > 0 || s->ihop_index ||
989  s->hop_index >= s->hop_size || s->eof) {
991  return 0;
992  }
993 
994  if (ff_outlink_frame_wanted(outlink)) {
996  return 0;
997  }
998 
999  return FFERROR_NOT_READY;
1000 }
1001 
1002 static const AVFilterPad showcwt_inputs[] = {
1003  {
1004  .name = "default",
1005  .type = AVMEDIA_TYPE_AUDIO,
1006  },
1007 };
1008 
1009 static const AVFilterPad showcwt_outputs[] = {
1010  {
1011  .name = "default",
1012  .type = AVMEDIA_TYPE_VIDEO,
1013  .config_props = config_output,
1014  },
1015 };
1016 
1018  .name = "showcwt",
1019  .description = NULL_IF_CONFIG_SMALL("Convert input audio to a CWT (Continuous Wavelet Transform) spectrum video output."),
1020  .uninit = uninit,
1021  .priv_size = sizeof(ShowCWTContext),
1025  .activate = activate,
1026  .priv_class = &showcwt_class,
1027  .flags = AVFILTER_FLAG_SLICE_THREADS,
1028 };
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
FSCALE_LINEAR
@ FSCALE_LINEAR
Definition: avf_showcwt.c:38
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
ShowCWTContext::ifft_in_size
int ifft_in_size
Definition: avf_showcwt.c:74
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
ShowCWTContext::frequency_scale
int frequency_scale
Definition: avf_showcwt.c:110
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
DIRECTION_LR
@ DIRECTION_LR
Definition: avf_showcwt.c:47
out
FILE * out
Definition: movenc.c:54
run_channels_cwt_prepare
static int run_channels_cwt_prepare(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: avf_showcwt.c:905
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:259
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
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
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FSCALE_ERBS
@ FSCALE_ERBS
Definition: avf_showcwt.c:42
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AVTXContext
Definition: tx_priv.h:228
atan2f
#define atan2f(y, x)
Definition: libm.h:45
ShowCWTContext::input_sample_count
int input_sample_count
Definition: avf_showcwt.c:105
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
ShowCWTContext::rate_str
char * rate_str
Definition: avf_showcwt.c:65
ShowCWTContext::itx_fn
av_tx_fn itx_fn
Definition: avf_showcwt.c:71
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:116
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
im
float im
Definition: fft.c:79
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
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:661
M_PI_2
#define M_PI_2
Definition: mathematics.h:55
AVOption
AVOption.
Definition: opt.h:251
ShowCWTContext::slide
int slide
Definition: avf_showcwt.c:97
showcwt_options
static const AVOption showcwt_options[]
Definition: avf_showcwt.c:119
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:167
ShowCWTContext::nb_threads
int nb_threads
Definition: avf_showcwt.c:92
ShowCWTContext::kernel_stop
int * kernel_stop
Definition: avf_showcwt.c:84
expf
#define expf(x)
Definition: libm.h:283
FLAGS
#define FLAGS
Definition: avf_showcwt.c:117
float.h
AVComplexFloat
Definition: tx.h:27
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
ShowCWTContext::fft_out_size
int fft_out_size
Definition: avf_showcwt.c:73
output_frame
static int output_frame(AVFilterContext *ctx)
Definition: avf_showcwt.c:721
video.h
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
ShowCWTContext::index
unsigned * index
Definition: avf_showcwt.c:82
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
DIRECTION_RL
@ DIRECTION_RL
Definition: avf_showcwt.c:48
compute_kernel
static void compute_kernel(AVFilterContext *ctx)
Definition: avf_showcwt.c:498
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
ShowCWTContext::ifft
AVTXContext ** ifft
Definition: avf_showcwt.c:69
SLIDE_REPLACE
@ SLIDE_REPLACE
Definition: avf_showcwt.c:55
AVComplexFloat::im
float im
Definition: tx.h:28
ff_avf_showcwt
const AVFilter ff_avf_showcwt
Definition: avf_showcwt.c:1017
cosf
#define cosf(x)
Definition: libm.h:78
fail
#define fail()
Definition: checkasm.h:134
log10f
#define log10f(x)
Definition: libm.h:414
NB_FSCALE
@ NB_FSCALE
Definition: avf_showcwt.c:43
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showcwt.c:155
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:654
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
ShowCWTContext::kernel_start
int * kernel_start
Definition: avf_showcwt.c:83
ShowCWTContext::output_sample_count
int output_sample_count
Definition: avf_showcwt.c:107
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:104
ShowCWTContext::frequency_band
float * frequency_band
Definition: avf_showcwt.c:80
avassert.h
av_cold
#define av_cold
Definition: attributes.h:90
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
float
float
Definition: af_crystalizer.c:122
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1490
s
#define s(width, name)
Definition: cbs_vp9.c:256
ShowCWTContext::logarithmic_basis
float logarithmic_basis
Definition: avf_showcwt.c:109
ShowCWTContext::eof_pts
int64_t eof_pts
Definition: avf_showcwt.c:79
ShowCWTContext::frequency_band_count
int frequency_band_count
Definition: avf_showcwt.c:108
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
remap_log
static float remap_log(float value, float log_factor)
Definition: avf_showcwt.c:251
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:596
ShowCWTContext::nb_channels
int nb_channels
Definition: avf_showcwt.c:93
fminf
float fminf(float, float)
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
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ShowCWTContext::maximum_frequency
float maximum_frequency
Definition: avf_showcwt.c:112
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
ShowCWTContext::direction
int direction
Definition: avf_showcwt.c:99
ShowCWTContext
Definition: avf_showcwt.c:61
ShowCWTContext::fft_in
AVFrame * fft_in
Definition: avf_showcwt.c:87
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
ShowCWTContext::ifft_out
AVFrame * ifft_out
Definition: avf_showcwt.c:90
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
ShowCWTContext::fft
AVTXContext ** fft
Definition: avf_showcwt.c:68
arg
const char * arg
Definition: jacosubdec.c:67
ShowCWTContext::deviation
float deviation
Definition: avf_showcwt.c:113
ShowCWTContext::ch_out
AVFrame * ch_out
Definition: avf_showcwt.c:91
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:1392
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:607
ShowCWTContext::kernel
AVFrame * kernel
Definition: avf_showcwt.c:81
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
ShowCWTContext::ihop_size
int ihop_size
Definition: avf_showcwt.c:102
V
#define V
Definition: avdct.c:30
ShowCWTContext::outpicref
AVFrame * outpicref
Definition: avf_showcwt.c:86
parseutils.h
ShowCWTContext::ihop_index
int ihop_index
Definition: avf_showcwt.c:103
frequency_band
static void frequency_band(float *frequency_band, int frequency_band_count, float frequency_range, float frequency_offset, int frequency_scale, float deviation)
Definition: avf_showcwt.c:216
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
av_cpu_max_align
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
Definition: cpu.c:265
ShowCWTContext::h
int h
Definition: avf_showcwt.c:63
sinf
#define sinf(x)
Definition: libm.h:419
av_clipf
av_clipf
Definition: af_crystalizer.c:122
DIRECTION_DU
@ DIRECTION_DU
Definition: avf_showcwt.c:50
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1327
index
int index
Definition: gxfenc.c:89
ShowCWTContext::fft_out
AVFrame * fft_out
Definition: avf_showcwt.c:88
f
f
Definition: af_crystalizer.c:122
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
powf
#define powf(x, y)
Definition: libm.h:50
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:775
cpu.h
run_channel_cwt
static int run_channel_cwt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: avf_showcwt.c:460
ShowCWTContext::cache
AVFrame * cache[2]
Definition: avf_showcwt.c:85
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
size
int size
Definition: twinvq_data.h:10344
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
ShowCWTContext::in_pts
int64_t in_pts
Definition: avf_showcwt.c:77
AVComplexFloat::re
float re
Definition: tx.h:28
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
DIRECTION_UD
@ DIRECTION_UD
Definition: avf_showcwt.c:49
ShowCWTContext::mode
int mode
Definition: avf_showcwt.c:64
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: avf_showcwt.c:187
FrequencyScale
FrequencyScale
Definition: avf_showcwt.c:37
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:167
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
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
M_PI
#define M_PI
Definition: mathematics.h:52
Y
#define Y
Definition: boxblur.h:37
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
NB_DIRECTION
@ NB_DIRECTION
Definition: avf_showcwt.c:51
draw
static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: avf_showcwt.c:297
showcwt_inputs
static const AVFilterPad showcwt_inputs[]
Definition: avf_showcwt.c:1002
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
ShowCWTContext::fft_in_size
int fft_in_size
Definition: avf_showcwt.c:72
ShowCWTContext::nb_consumed_samples
int nb_consumed_samples
Definition: avf_showcwt.c:94
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
ShowCWTContext::output_padding_size
int output_padding_size
Definition: avf_showcwt.c:106
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:410
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
run_channel_cwt_prepare
static int run_channel_cwt_prepare(AVFilterContext *ctx, void *arg, int jobnr, int ch)
Definition: avf_showcwt.c:260
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:391
DirectionMode
DirectionMode
Definition: avf_showcwt.c:46
src2
const pixel * src2
Definition: h264pred_template.c:422
NB_SLIDE
@ NB_SLIDE
Definition: avf_showcwt.c:58
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:793
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
value
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 default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(showcwt)
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
ShowCWTContext::tx_fn
av_tx_fn tx_fn
Definition: avf_showcwt.c:70
OFFSET
#define OFFSET(x)
Definition: avf_showcwt.c:116
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:1352
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
ShowCWTContext::minimum_frequency
float minimum_frequency
Definition: avf_showcwt.c:111
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
activate
static int activate(AVFilterContext *ctx)
Definition: avf_showcwt.c:918
ShowCWTContext::auto_frame_rate
AVRational auto_frame_rate
Definition: avf_showcwt.c:66
ShowCWTContext::hop_index
int hop_index
Definition: avf_showcwt.c:101
AVFilter
Filter definition.
Definition: avfilter.h:171
ret
ret
Definition: filter_design.txt:187
ShowCWTContext::frame_rate
AVRational frame_rate
Definition: avf_showcwt.c:67
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
ShowCWTContext::pos
int pos
Definition: avf_showcwt.c:76
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_showcwt.c:542
U
#define U(x)
Definition: vpx_arith.h:37
SLIDE_SCROLL
@ SLIDE_SCROLL
Definition: avf_showcwt.c:56
ShowCWTContext::pps
int pps
Definition: avf_showcwt.c:95
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:551
ShowCWTContext::ifft_out_size
int ifft_out_size
Definition: avf_showcwt.c:75
channel_layout.h
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_clip_uint8
#define av_clip_uint8
Definition: common.h:101
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
factor
static const int factor[16]
Definition: vf_pp7.c:76
ShowCWTContext::old_pts
int64_t old_pts
Definition: avf_showcwt.c:78
ShowCWTContext::hop_size
int hop_size
Definition: avf_showcwt.c:100
ShowCWTContext::eof
int eof
Definition: avf_showcwt.c:96
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:127
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
audio.h
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:506
ShowCWTContext::w
int w
Definition: avf_showcwt.c:63
FSCALE_BARK
@ FSCALE_BARK
Definition: avf_showcwt.c:40
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
ShowCWTContext::new_frame
int new_frame
Definition: avf_showcwt.c:98
ShowCWTContext::input_padding_size
int input_padding_size
Definition: avf_showcwt.c:104
ShowCWTContext::ifft_in
AVFrame * ifft_in
Definition: avf_showcwt.c:89
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2038
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
FSCALE_MEL
@ FSCALE_MEL
Definition: avf_showcwt.c:41
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:142
showcwt_outputs
static const AVFilterPad showcwt_outputs[]
Definition: avf_showcwt.c:1009
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
FSCALE_LOG2
@ FSCALE_LOG2
Definition: avf_showcwt.c:39
SlideMode
SlideMode
Definition: avf_ahistogram.c:33
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:199
tx.h
re
float re
Definition: fft.c:79
SLIDE_FRAME
@ SLIDE_FRAME
Definition: avf_showcwt.c:57