FFmpeg
avf_showwaves.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Stefano Sabatini
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 /**
22  * @file
23  * audio to video multimedia filter
24  */
25 
26 #include "config_components.h"
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/avstring.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/parseutils.h"
34 #include "avfilter.h"
35 #include "filters.h"
36 #include "formats.h"
37 #include "audio.h"
38 #include "video.h"
39 #include "internal.h"
40 
47 };
48 
55 };
56 
61 };
62 
67 };
68 
69 struct frame_node {
71  struct frame_node *next;
72 };
73 
74 typedef struct ShowWavesContext {
75  const AVClass *class;
76  int w, h;
78  char *colors;
79  int buf_idx;
80  int16_t *buf_idy; /* y coordinate of previous sample for each channel */
81  int16_t *history;
86  int pixstep;
87  int mode; ///< ShowWavesMode
88  int scale; ///< ShowWavesScale
89  int draw_mode; ///< ShowWavesDrawMode
92  uint8_t *fg;
93 
94  int (*get_h)(int16_t sample, int height);
95  void (*draw_sample)(uint8_t *buf, int height, int linesize,
96  int16_t *prev_y, const uint8_t color[4], int h);
97 
98  /* single picture */
102  int64_t total_samples;
103  int64_t *sum; /* abs sum of the samples per channel */
105 
106 #define OFFSET(x) offsetof(ShowWavesContext, x)
107 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
108 
109 static const AVOption showwaves_options[] = {
110  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
111  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
112  { "mode", "select display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_POINT}, 0, MODE_NB-1, FLAGS, "mode"},
113  { "point", "draw a point for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_POINT}, .flags=FLAGS, .unit="mode"},
114  { "line", "draw a line for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_LINE}, .flags=FLAGS, .unit="mode"},
115  { "p2p", "draw a line between samples", 0, AV_OPT_TYPE_CONST, {.i64=MODE_P2P}, .flags=FLAGS, .unit="mode"},
116  { "cline", "draw a centered line for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_CENTERED_LINE}, .flags=FLAGS, .unit="mode"},
117  { "n", "set how many samples to show in the same point", OFFSET(n), AV_OPT_TYPE_RATIONAL, {.i64 = 0}, 0, INT_MAX, FLAGS },
118  { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
119  { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
120  { "split_channels", "draw channels separately", OFFSET(split_channels), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
121  { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
122  { "scale", "set amplitude scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, SCALE_NB-1, FLAGS, .unit="scale" },
123  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LIN}, .flags=FLAGS, .unit="scale"},
124  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LOG}, .flags=FLAGS, .unit="scale"},
125  { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_SQRT}, .flags=FLAGS, .unit="scale"},
126  { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_CBRT}, .flags=FLAGS, .unit="scale"},
127  { "draw", "set draw mode", OFFSET(draw_mode), AV_OPT_TYPE_INT, {.i64 = DRAW_SCALE}, 0, DRAW_NB-1, FLAGS, .unit="draw" },
128  { "scale", "scale pixel values for each drawn sample", 0, AV_OPT_TYPE_CONST, {.i64=DRAW_SCALE}, .flags=FLAGS, .unit="draw"},
129  { "full", "draw every pixel for sample directly", 0, AV_OPT_TYPE_CONST, {.i64=DRAW_FULL}, .flags=FLAGS, .unit="draw"},
130  { NULL }
131 };
132 
133 AVFILTER_DEFINE_CLASS(showwaves);
134 
136 {
137  ShowWavesContext *showwaves = ctx->priv;
138 
139  av_frame_free(&showwaves->outpicref);
140  av_freep(&showwaves->buf_idy);
141  av_freep(&showwaves->history);
142  av_freep(&showwaves->fg);
143 
144  if (showwaves->single_pic) {
145  struct frame_node *node = showwaves->audio_frames;
146  while (node) {
147  struct frame_node *tmp = node;
148 
149  node = node->next;
150  av_frame_free(&tmp->frame);
151  av_freep(&tmp);
152  }
153  av_freep(&showwaves->sum);
154  showwaves->last_frame = NULL;
155  }
156 }
157 
159 {
162  AVFilterLink *inlink = ctx->inputs[0];
163  AVFilterLink *outlink = ctx->outputs[0];
166  int ret;
167 
168  /* set input audio formats */
170  if ((ret = ff_formats_ref(formats, &inlink->outcfg.formats)) < 0)
171  return ret;
172 
174  if ((ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts)) < 0)
175  return ret;
176 
178  if ((ret = ff_formats_ref(formats, &inlink->outcfg.samplerates)) < 0)
179  return ret;
180 
181  /* set output video format */
183  if ((ret = ff_formats_ref(formats, &outlink->incfg.formats)) < 0)
184  return ret;
185 
186  return 0;
187 }
188 
189 static int get_lin_h(int16_t sample, int height)
190 {
191  return height/2 - av_rescale(sample, height/2, INT16_MAX);
192 }
193 
194 static int get_lin_h2(int16_t sample, int height)
195 {
196  return av_rescale(FFABS(sample), height, INT16_MAX);
197 }
198 
199 static int get_log_h(int16_t sample, int height)
200 {
201  return height/2 - FFSIGN(sample) * (log10(1 + FFABS(sample)) * (height/2) / log10(1 + INT16_MAX));
202 }
203 
204 static int get_log_h2(int16_t sample, int height)
205 {
206  return log10(1 + FFABS(sample)) * height / log10(1 + INT16_MAX);
207 }
208 
209 static int get_sqrt_h(int16_t sample, int height)
210 {
211  return height/2 - FFSIGN(sample) * (sqrt(FFABS(sample)) * (height/2) / sqrt(INT16_MAX));
212 }
213 
214 static int get_sqrt_h2(int16_t sample, int height)
215 {
216  return sqrt(FFABS(sample)) * height / sqrt(INT16_MAX);
217 }
218 
219 static int get_cbrt_h(int16_t sample, int height)
220 {
221  return height/2 - FFSIGN(sample) * (cbrt(FFABS(sample)) * (height/2) / cbrt(INT16_MAX));
222 }
223 
224 static int get_cbrt_h2(int16_t sample, int height)
225 {
226  return cbrt(FFABS(sample)) * height / cbrt(INT16_MAX);
227 }
228 
229 static void draw_sample_point_rgba_scale(uint8_t *buf, int height, int linesize,
230  int16_t *prev_y,
231  const uint8_t color[4], int h)
232 {
233  if (h >= 0 && h < height) {
234  buf[h * linesize + 0] += color[0];
235  buf[h * linesize + 1] += color[1];
236  buf[h * linesize + 2] += color[2];
237  buf[h * linesize + 3] += color[3];
238  }
239 }
240 
241 static void draw_sample_point_rgba_full(uint8_t *buf, int height, int linesize,
242  int16_t *prev_y,
243  const uint8_t color[4], int h)
244 {
245  uint32_t clr = AV_RN32(color);
246  if (h >= 0 && h < height)
247  AV_WN32(buf + h * linesize, clr);
248 }
249 
250 static void draw_sample_line_rgba_scale(uint8_t *buf, int height, int linesize,
251  int16_t *prev_y,
252  const uint8_t color[4], int h)
253 {
254  int start = height/2;
255  int end = av_clip(h, 0, height-1);
256  uint8_t *bufk;
257  if (start > end)
258  FFSWAP(int16_t, start, end);
259  bufk = buf + start * linesize;
260  for (int k = start; k < end; k++, bufk += linesize) {
261  bufk[0] += color[0];
262  bufk[1] += color[1];
263  bufk[2] += color[2];
264  bufk[3] += color[3];
265  }
266 }
267 
268 static void draw_sample_line_rgba_full(uint8_t *buf, int height, int linesize,
269  int16_t *prev_y,
270  const uint8_t color[4], int h)
271 {
272  int start = height/2;
273  int end = av_clip(h, 0, height-1);
274  uint32_t clr = AV_RN32(color);
275  uint8_t *bufk;
276  if (start > end)
277  FFSWAP(int16_t, start, end);
278  bufk = buf + start * linesize;
279  for (int k = start; k < end; k++, bufk += linesize)
280  AV_WN32(bufk, clr);
281 }
282 
283 static void draw_sample_p2p_rgba_scale(uint8_t *buf, int height, int linesize,
284  int16_t *prev_y,
285  const uint8_t color[4], int h)
286 {
287  if (h >= 0 && h < height) {
288  buf[h * linesize + 0] += color[0];
289  buf[h * linesize + 1] += color[1];
290  buf[h * linesize + 2] += color[2];
291  buf[h * linesize + 3] += color[3];
292  if (*prev_y && h != *prev_y) {
293  int start = *prev_y;
294  uint8_t *bufk;
295  int end = av_clip(h, 0, height-1);
296  if (start > end)
297  FFSWAP(int16_t, start, end);
298  bufk = buf + (start + 1) * linesize;
299  for (int k = start + 1; k < end; k++, bufk += linesize) {
300  bufk[0] += color[0];
301  bufk[1] += color[1];
302  bufk[2] += color[2];
303  bufk[3] += color[3];
304  }
305  }
306  }
307  *prev_y = h;
308 }
309 
310 static void draw_sample_p2p_rgba_full(uint8_t *buf, int height, int linesize,
311  int16_t *prev_y,
312  const uint8_t color[4], int h)
313 {
314  uint32_t clr = AV_RN32(color);
315  if (h >= 0 && h < height) {
316  AV_WN32(buf + h * linesize, clr);
317  if (*prev_y && h != *prev_y) {
318  int start = *prev_y;
319  uint8_t *bufk;
320  int end = av_clip(h, 0, height-1);
321  if (start > end)
322  FFSWAP(int16_t, start, end);
323  bufk = buf + (start + 1) * linesize;
324  for (int k = start + 1; k < end; k++, bufk += linesize)
325  AV_WN32(bufk, clr);
326  }
327  }
328  *prev_y = h;
329 }
330 
331 static void draw_sample_cline_rgba_scale(uint8_t *buf, int height, int linesize,
332  int16_t *prev_y,
333  const uint8_t color[4], int h)
334 {
335  const int start = (height - h) / 2;
336  const int end = start + h;
337  uint8_t *bufk = buf + start * linesize;
338  for (int k = start; k < end; k++, bufk += linesize) {
339  bufk[0] += color[0];
340  bufk[1] += color[1];
341  bufk[2] += color[2];
342  bufk[3] += color[3];
343  }
344 }
345 
346 static void draw_sample_cline_rgba_full(uint8_t *buf, int height, int linesize,
347  int16_t *prev_y,
348  const uint8_t color[4], int h)
349 {
350  uint32_t clr = AV_RN32(color);
351  const int start = (height - h) / 2;
352  const int end = start + h;
353  uint8_t *bufk = buf + start * linesize;
354  for (int k = start; k < end; k++, bufk += linesize)
355  AV_WN32(bufk, clr);
356 }
357 
358 static void draw_sample_point_gray(uint8_t *buf, int height, int linesize,
359  int16_t *prev_y,
360  const uint8_t color[4], int h)
361 {
362  if (h >= 0 && h < height)
363  buf[h * linesize] += color[0];
364 }
365 
366 static void draw_sample_line_gray(uint8_t *buf, int height, int linesize,
367  int16_t *prev_y,
368  const uint8_t color[4], int h)
369 {
370  int k;
371  int start = height/2;
372  int end = av_clip(h, 0, height-1);
373  if (start > end)
374  FFSWAP(int16_t, start, end);
375  for (k = start; k < end; k++)
376  buf[k * linesize] += color[0];
377 }
378 
379 static void draw_sample_p2p_gray(uint8_t *buf, int height, int linesize,
380  int16_t *prev_y,
381  const uint8_t color[4], int h)
382 {
383  int k;
384  if (h >= 0 && h < height) {
385  buf[h * linesize] += color[0];
386  if (*prev_y && h != *prev_y) {
387  int start = *prev_y;
388  int end = av_clip(h, 0, height-1);
389  if (start > end)
390  FFSWAP(int16_t, start, end);
391  for (k = start + 1; k < end; k++)
392  buf[k * linesize] += color[0];
393  }
394  }
395  *prev_y = h;
396 }
397 
398 static void draw_sample_cline_gray(uint8_t *buf, int height, int linesize,
399  int16_t *prev_y,
400  const uint8_t color[4], int h)
401 {
402  int k;
403  const int start = (height - h) / 2;
404  const int end = start + h;
405  for (k = start; k < end; k++)
406  buf[k * linesize] += color[0];
407 }
408 
409 static int config_output(AVFilterLink *outlink)
410 {
411  AVFilterContext *ctx = outlink->src;
412  AVFilterLink *inlink = ctx->inputs[0];
413  ShowWavesContext *showwaves = ctx->priv;
414  int nb_channels = inlink->ch_layout.nb_channels;
415  char *colors, *saveptr = NULL;
416  uint8_t x;
417  int ch;
418 
419  showwaves->q = av_make_q(0, 1);
420  showwaves->c = av_make_q(0, 1);
421 
422  if (showwaves->single_pic) {
423  showwaves->n = av_make_q(1, 1);
424  outlink->frame_rate = av_make_q(1, 1);
425  } else {
426  if (!showwaves->n.num || !showwaves->n.den) {
427  showwaves->n = av_mul_q(av_make_q(inlink->sample_rate,
428  showwaves->w), av_inv_q(showwaves->rate));
429  outlink->frame_rate = showwaves->rate;
430  } else {
431  outlink->frame_rate = av_div_q(av_make_q(inlink->sample_rate, showwaves->w), showwaves->n);
432  }
433  }
434 
435  showwaves->buf_idx = 0;
436  if (!FF_ALLOCZ_TYPED_ARRAY(showwaves->buf_idy, nb_channels)) {
437  av_log(ctx, AV_LOG_ERROR, "Could not allocate showwaves buffer\n");
438  return AVERROR(ENOMEM);
439  }
440 
441  showwaves->history_nb_samples = av_rescale(showwaves->w * nb_channels * 2,
442  showwaves->n.num, showwaves->n.den);
443  if (showwaves->history_nb_samples <= 0)
444  return AVERROR(EINVAL);
445  showwaves->history = av_calloc(showwaves->history_nb_samples,
446  sizeof(*showwaves->history));
447  if (!showwaves->history)
448  return AVERROR(ENOMEM);
449 
450  outlink->time_base = av_inv_q(outlink->frame_rate);
451  outlink->w = showwaves->w;
452  outlink->h = showwaves->h;
453  outlink->sample_aspect_ratio = (AVRational){1,1};
454 
455  av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d r:%f n:%f\n",
456  showwaves->w, showwaves->h, av_q2d(outlink->frame_rate), av_q2d(showwaves->n));
457 
458  switch (outlink->format) {
459  case AV_PIX_FMT_GRAY8:
460  switch (showwaves->mode) {
461  case MODE_POINT: showwaves->draw_sample = draw_sample_point_gray; break;
462  case MODE_LINE: showwaves->draw_sample = draw_sample_line_gray; break;
463  case MODE_P2P: showwaves->draw_sample = draw_sample_p2p_gray; break;
464  case MODE_CENTERED_LINE: showwaves->draw_sample = draw_sample_cline_gray; break;
465  default:
466  return AVERROR_BUG;
467  }
468  showwaves->pixstep = 1;
469  break;
470  case AV_PIX_FMT_RGBA:
471  switch (showwaves->mode) {
476  default:
477  return AVERROR_BUG;
478  }
479  showwaves->pixstep = 4;
480  break;
481  }
482 
483  switch (showwaves->scale) {
484  case SCALE_LIN:
485  switch (showwaves->mode) {
486  case MODE_POINT:
487  case MODE_LINE:
488  case MODE_P2P: showwaves->get_h = get_lin_h; break;
489  case MODE_CENTERED_LINE: showwaves->get_h = get_lin_h2; break;
490  default:
491  return AVERROR_BUG;
492  }
493  break;
494  case SCALE_LOG:
495  switch (showwaves->mode) {
496  case MODE_POINT:
497  case MODE_LINE:
498  case MODE_P2P: showwaves->get_h = get_log_h; break;
499  case MODE_CENTERED_LINE: showwaves->get_h = get_log_h2; break;
500  default:
501  return AVERROR_BUG;
502  }
503  break;
504  case SCALE_SQRT:
505  switch (showwaves->mode) {
506  case MODE_POINT:
507  case MODE_LINE:
508  case MODE_P2P: showwaves->get_h = get_sqrt_h; break;
509  case MODE_CENTERED_LINE: showwaves->get_h = get_sqrt_h2; break;
510  default:
511  return AVERROR_BUG;
512  }
513  break;
514  case SCALE_CBRT:
515  switch (showwaves->mode) {
516  case MODE_POINT:
517  case MODE_LINE:
518  case MODE_P2P: showwaves->get_h = get_cbrt_h; break;
519  case MODE_CENTERED_LINE: showwaves->get_h = get_cbrt_h2; break;
520  default:
521  return AVERROR_BUG;
522  }
523  break;
524  }
525 
526  showwaves->fg = av_malloc_array(nb_channels, 4 * sizeof(*showwaves->fg));
527  if (!showwaves->fg)
528  return AVERROR(ENOMEM);
529 
530  colors = av_strdup(showwaves->colors);
531  if (!colors)
532  return AVERROR(ENOMEM);
533 
534  if (showwaves->draw_mode == DRAW_SCALE) {
535  /* multiplication factor, pre-computed to avoid in-loop divisions */
536  x = (showwaves->n.den * 255) / ((showwaves->split_channels ? 1 : nb_channels) * showwaves->n.num);
537  } else {
538  x = 255;
539  }
540  if (outlink->format == AV_PIX_FMT_RGBA) {
541  uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
542 
543  for (ch = 0; ch < nb_channels; ch++) {
544  char *color;
545 
546  color = av_strtok(ch == 0 ? colors : NULL, " |", &saveptr);
547  if (color)
548  av_parse_color(fg, color, -1, ctx);
549  showwaves->fg[4*ch + 0] = fg[0] * x / 255.;
550  showwaves->fg[4*ch + 1] = fg[1] * x / 255.;
551  showwaves->fg[4*ch + 2] = fg[2] * x / 255.;
552  showwaves->fg[4*ch + 3] = fg[3] * x / 255.;
553  }
554  } else {
555  for (ch = 0; ch < nb_channels; ch++)
556  showwaves->fg[4 * ch + 0] = x;
557  }
558  av_free(colors);
559 
560  return 0;
561 }
562 
563 inline static int push_frame(AVFilterLink *outlink, int i, int64_t pts)
564 {
565  AVFilterContext *ctx = outlink->src;
566  AVFilterLink *inlink = ctx->inputs[0];
567  ShowWavesContext *showwaves = outlink->src->priv;
568  int nb_channels = inlink->ch_layout.nb_channels;
569  int ret;
570 
571  showwaves->outpicref->duration = 1;
572  showwaves->outpicref->pts = av_rescale_q(pts + i,
573  inlink->time_base,
574  outlink->time_base);
575 
576  ret = ff_filter_frame(outlink, showwaves->outpicref);
577  showwaves->outpicref = NULL;
578  showwaves->buf_idx = 0;
579  for (int i = 0; i < nb_channels; i++)
580  showwaves->buf_idy[i] = 0;
581  return ret;
582 }
583 
584 static int push_single_pic(AVFilterLink *outlink)
585 {
586  AVFilterContext *ctx = outlink->src;
587  AVFilterLink *inlink = ctx->inputs[0];
588  ShowWavesContext *showwaves = ctx->priv;
589  int64_t n = 0, column_max_samples = showwaves->total_samples / outlink->w;
590  int64_t remaining_samples = showwaves->total_samples - (column_max_samples * outlink->w);
591  int64_t last_column_samples = column_max_samples + remaining_samples;
592  AVFrame *out = showwaves->outpicref;
593  struct frame_node *node;
594  const int nb_channels = inlink->ch_layout.nb_channels;
595  const int ch_height = showwaves->split_channels ? outlink->h / nb_channels : outlink->h;
596  const int linesize = out->linesize[0];
597  const int pixstep = showwaves->pixstep;
598  int col = 0;
599  int64_t *sum = showwaves->sum;
600 
601  if (column_max_samples == 0) {
602  av_log(ctx, AV_LOG_ERROR, "Too few samples\n");
603  return AVERROR(EINVAL);
604  }
605 
606  av_log(ctx, AV_LOG_DEBUG, "Create frame averaging %"PRId64" samples per column\n", column_max_samples);
607 
608  memset(sum, 0, nb_channels * sizeof(*sum));
609 
610  for (node = showwaves->audio_frames; node; node = node->next) {
611  int i;
612  const AVFrame *frame = node->frame;
613  const int16_t *p = (const int16_t *)frame->data[0];
614 
615  for (i = 0; i < frame->nb_samples; i++) {
616  int64_t max_samples = col == outlink->w - 1 ? last_column_samples: column_max_samples;
617  int ch;
618 
619  switch (showwaves->filter_mode) {
620  case FILTER_AVERAGE:
621  for (ch = 0; ch < nb_channels; ch++)
622  sum[ch] += abs(p[ch + i*nb_channels]);
623  break;
624  case FILTER_PEAK:
625  for (ch = 0; ch < nb_channels; ch++)
626  sum[ch] = FFMAX(sum[ch], abs(p[ch + i*nb_channels]));
627  break;
628  }
629 
630  n++;
631  if (n == max_samples) {
632  for (ch = 0; ch < nb_channels; ch++) {
633  int16_t sample = sum[ch] / (showwaves->filter_mode == FILTER_AVERAGE ? max_samples : 1);
634  uint8_t *buf = out->data[0] + col * pixstep;
635  int h;
636 
637  if (showwaves->split_channels)
638  buf += ch*ch_height*linesize;
639  av_assert0(col < outlink->w);
640  h = showwaves->get_h(sample, ch_height);
641  showwaves->draw_sample(buf, ch_height, linesize, &showwaves->buf_idy[ch], &showwaves->fg[ch * 4], h);
642  sum[ch] = 0;
643  }
644  col++;
645  n = 0;
646  }
647  }
648  }
649 
650  return push_frame(outlink, 0, 0);
651 }
652 
653 
654 static int request_frame(AVFilterLink *outlink)
655 {
656  ShowWavesContext *showwaves = outlink->src->priv;
657  AVFilterLink *inlink = outlink->src->inputs[0];
658  int ret;
659 
661  if (ret == AVERROR_EOF && showwaves->outpicref) {
662  push_single_pic(outlink);
663  }
664 
665  return ret;
666 }
667 
668 static int alloc_out_frame(ShowWavesContext *showwaves,
669  AVFilterLink *outlink)
670 {
671  if (!showwaves->outpicref) {
672  AVFrame *out = showwaves->outpicref =
673  ff_get_video_buffer(outlink, outlink->w, outlink->h);
674  if (!out)
675  return AVERROR(ENOMEM);
676  out->width = outlink->w;
677  out->height = outlink->h;
678  for (int j = 0; j < outlink->h; j++)
679  memset(out->data[0] + j*out->linesize[0], 0, outlink->w * showwaves->pixstep);
680  }
681  return 0;
682 }
683 
685 {
686  ShowWavesContext *showwaves = ctx->priv;
687 
688  if (!strcmp(ctx->filter->name, "showwavespic")) {
689  showwaves->single_pic = 1;
690  showwaves->mode = MODE_CENTERED_LINE;
691  }
692 
693  return 0;
694 }
695 
696 #if CONFIG_SHOWWAVES_FILTER
697 
698 static int showwaves_filter_frame(AVFilterLink *inlink, AVFrame *insamples)
699 {
700  AVFilterContext *ctx = inlink->dst;
701  AVFilterLink *outlink = ctx->outputs[0];
702  ShowWavesContext *showwaves = ctx->priv;
703  const int nb_samples = insamples->nb_samples;
704  AVFrame *outpicref = showwaves->outpicref;
705  const int16_t *p = (const int16_t *)insamples->data[0];
706  int16_t *history = showwaves->history;
707  const int nb_channels = inlink->ch_layout.nb_channels;
708  int i, j, ret = 0, linesize;
709  const int pixstep = showwaves->pixstep;
710  const int ch_height = showwaves->split_channels ? outlink->h / nb_channels : outlink->h;
711  const int history_nb_samples = showwaves->history_nb_samples;
712  const int split_channels = showwaves->split_channels;
713  const AVRational i_n = av_inv_q(showwaves->n);
714  const AVRational u_q = av_make_q(1, 1);
715  const AVRational z_q = av_make_q(0, 1);
716  int16_t *buf_idy = showwaves->buf_idy;
717  int idx = showwaves->history_index;
718  int buf_idx = showwaves->buf_idx;
719  const uint8_t *fg = showwaves->fg;
720  const int w = showwaves->w;
721  uint8_t *dst;
722 
723  for (int n = 0; n < nb_samples * nb_channels; n++) {
724  history[idx++] = p[n];
725  if (idx >= history_nb_samples)
726  idx = 0;
727  }
728  showwaves->history_index = idx;
729 
730  ret = alloc_out_frame(showwaves, outlink);
731  if (ret < 0)
732  goto end;
733  outpicref = showwaves->outpicref;
734  linesize = outpicref->linesize[0];
735 
736  /* draw data in the buffer */
737  dst = outpicref->data[0];
738  for (i = 0; i < history_nb_samples; i++) {
739  for (j = 0; j < nb_channels; j++) {
740  uint8_t *buf = dst + buf_idx * pixstep;
741  int h;
742 
743  if (split_channels)
744  buf += j*ch_height*linesize;
745  h = showwaves->get_h(history[idx++], ch_height);
746  if (idx >= history_nb_samples)
747  idx = 0;
748  showwaves->draw_sample(buf, ch_height, linesize,
749  &buf_idy[j], &fg[j * 4], h);
750  }
751 
752  showwaves->c = av_add_q(showwaves->c, i_n);
753  if (av_cmp_q(showwaves->c, u_q) >= 0) {
754  showwaves->c = z_q;
755  buf_idx++;
756  }
757  if (buf_idx == w)
758  break;
759  }
760 
761  showwaves->buf_idx = buf_idx;
762 
763  if ((ret = push_frame(outlink, history_nb_samples - i - 1, insamples->pts)) < 0)
764  goto end;
765  outpicref = showwaves->outpicref;
766 end:
767  av_frame_free(&insamples);
768  return ret;
769 }
770 
771 static int activate(AVFilterContext *ctx)
772 {
773  AVFilterLink *inlink = ctx->inputs[0];
774  AVFilterLink *outlink = ctx->outputs[0];
775  ShowWavesContext *showwaves = ctx->priv;
776  AVRational q;
777  AVFrame *in;
778  int nb_samples;
779  int ret;
780 
782 
783  q = av_add_q(showwaves->q, av_mul_q(av_make_q(outlink->w, 1), showwaves->n));
784  nb_samples = (q.num + (q.den / 2)) / q.den;
785  ret = ff_inlink_consume_samples(inlink, nb_samples, nb_samples, &in);
786  if (ret < 0)
787  return ret;
788  if (ret > 0) {
789  showwaves->q = av_sub_q(q, av_make_q(nb_samples, 1));
790  return showwaves_filter_frame(inlink, in);
791  }
792 
795 
796  return FFERROR_NOT_READY;
797 }
798 
799 static const AVFilterPad showwaves_outputs[] = {
800  {
801  .name = "default",
802  .type = AVMEDIA_TYPE_VIDEO,
803  .config_props = config_output,
804  },
805 };
806 
807 const AVFilter ff_avf_showwaves = {
808  .name = "showwaves",
809  .description = NULL_IF_CONFIG_SMALL("Convert input audio to a video output."),
810  .init = init,
811  .uninit = uninit,
812  .priv_size = sizeof(ShowWavesContext),
814  .activate = activate,
815  FILTER_OUTPUTS(showwaves_outputs),
817  .priv_class = &showwaves_class,
818 };
819 
820 #endif // CONFIG_SHOWWAVES_FILTER
821 
822 #if CONFIG_SHOWWAVESPIC_FILTER
823 
824 #define OFFSET(x) offsetof(ShowWavesContext, x)
825 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
826 
827 static const AVOption showwavespic_options[] = {
828  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
829  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
830  { "split_channels", "draw channels separately", OFFSET(split_channels), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
831  { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
832  { "scale", "set amplitude scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, SCALE_NB-1, FLAGS, .unit="scale" },
833  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LIN}, .flags=FLAGS, .unit="scale"},
834  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LOG}, .flags=FLAGS, .unit="scale"},
835  { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_SQRT}, .flags=FLAGS, .unit="scale"},
836  { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_CBRT}, .flags=FLAGS, .unit="scale"},
837  { "draw", "set draw mode", OFFSET(draw_mode), AV_OPT_TYPE_INT, {.i64 = DRAW_SCALE}, 0, DRAW_NB-1, FLAGS, .unit="draw" },
838  { "scale", "scale pixel values for each drawn sample", 0, AV_OPT_TYPE_CONST, {.i64=DRAW_SCALE}, .flags=FLAGS, .unit="draw"},
839  { "full", "draw every pixel for sample directly", 0, AV_OPT_TYPE_CONST, {.i64=DRAW_FULL}, .flags=FLAGS, .unit="draw"},
840  { "filter", "set filter mode", OFFSET(filter_mode), AV_OPT_TYPE_INT, {.i64 = FILTER_AVERAGE}, 0, FILTER_NB-1, FLAGS, .unit="filter" },
841  { "average", "use average samples", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_AVERAGE}, .flags=FLAGS, .unit="filter"},
842  { "peak", "use peak samples", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_PEAK}, .flags=FLAGS, .unit="filter"},
843  { NULL }
844 };
845 
846 AVFILTER_DEFINE_CLASS(showwavespic);
847 
848 static int showwavespic_config_input(AVFilterLink *inlink)
849 {
850  AVFilterContext *ctx = inlink->dst;
851  ShowWavesContext *showwaves = ctx->priv;
852 
853  if (showwaves->single_pic) {
854  showwaves->sum = av_calloc(inlink->ch_layout.nb_channels, sizeof(*showwaves->sum));
855  if (!showwaves->sum)
856  return AVERROR(ENOMEM);
857  }
858 
859  return 0;
860 }
861 
862 static int showwavespic_filter_frame(AVFilterLink *inlink, AVFrame *insamples)
863 {
864  AVFilterContext *ctx = inlink->dst;
865  AVFilterLink *outlink = ctx->outputs[0];
866  ShowWavesContext *showwaves = ctx->priv;
867  int ret = 0;
868 
869  if (showwaves->single_pic) {
870  struct frame_node *f;
871 
872  ret = alloc_out_frame(showwaves, outlink);
873  if (ret < 0)
874  goto end;
875 
876  /* queue the audio frame */
877  f = av_malloc(sizeof(*f));
878  if (!f) {
879  ret = AVERROR(ENOMEM);
880  goto end;
881  }
882  f->frame = insamples;
883  f->next = NULL;
884  if (!showwaves->last_frame) {
885  showwaves->audio_frames =
886  showwaves->last_frame = f;
887  } else {
888  showwaves->last_frame->next = f;
889  showwaves->last_frame = f;
890  }
891  showwaves->total_samples += insamples->nb_samples;
892 
893  return 0;
894  }
895 
896 end:
897  av_frame_free(&insamples);
898  return ret;
899 }
900 
901 static const AVFilterPad showwavespic_inputs[] = {
902  {
903  .name = "default",
904  .type = AVMEDIA_TYPE_AUDIO,
905  .config_props = showwavespic_config_input,
906  .filter_frame = showwavespic_filter_frame,
907  },
908 };
909 
910 static const AVFilterPad showwavespic_outputs[] = {
911  {
912  .name = "default",
913  .type = AVMEDIA_TYPE_VIDEO,
914  .config_props = config_output,
915  .request_frame = request_frame,
916  },
917 };
918 
920  .name = "showwavespic",
921  .description = NULL_IF_CONFIG_SMALL("Convert input audio to a video output single picture."),
922  .init = init,
923  .uninit = uninit,
924  .priv_size = sizeof(ShowWavesContext),
925  FILTER_INPUTS(showwavespic_inputs),
926  FILTER_OUTPUTS(showwavespic_outputs),
928  .priv_class = &showwavespic_class,
929 };
930 
931 #endif // CONFIG_SHOWWAVESPIC_FILTER
FF_ALLOCZ_TYPED_ARRAY
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
Definition: internal.h:88
ShowWavesContext::c
AVRational c
Definition: avf_showwaves.c:85
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:108
SCALE_SQRT
@ SCALE_SQRT
Definition: avf_showwaves.c:52
DRAW_SCALE
@ DRAW_SCALE
Definition: avf_showwaves.c:58
FILTER_PEAK
@ FILTER_PEAK
Definition: avf_showwaves.c:65
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
FILTER_AVERAGE
@ FILTER_AVERAGE
Definition: avf_showwaves.c:64
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
av_clip
#define av_clip
Definition: common.h:96
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:401
get_cbrt_h
static int get_cbrt_h(int16_t sample, int height)
Definition: avf_showwaves.c:219
ShowWavesContext::history_nb_samples
int history_nb_samples
Definition: avf_showwaves.c:82
out
FILE * out
Definition: movenc.c:54
color
Definition: vf_paletteuse.c:511
ShowWavesContext::filter_mode
int filter_mode
Definition: avf_showwaves.c:91
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
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:807
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:612
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:326
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
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
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
frame_node::frame
AVFrame * frame
Definition: avf_showwaves.c:70
ShowWavesContext::get_h
int(* get_h)(int16_t sample, int height)
Definition: avf_showwaves.c:94
frame_node::next
struct frame_node * next
Definition: avf_showwaves.c:71
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
draw_sample_point_rgba_scale
static void draw_sample_point_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:229
ShowWavesContext::buf_idy
int16_t * buf_idy
Definition: avf_showwaves.c:80
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:452
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:251
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:169
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:431
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
get_cbrt_h2
static int get_cbrt_h2(int16_t sample, int height)
Definition: avf_showwaves.c:224
ShowWavesContext::buf_idx
int buf_idx
Definition: avf_showwaves.c:79
ShowWavesContext::w
int w
Definition: avf_showwaves.c:76
showwaves_options
static const AVOption showwaves_options[]
Definition: avf_showwaves.c:109
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(showwaves)
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
av_sub_q
AVRational av_sub_q(AVRational b, AVRational c)
Subtract one rational from another.
Definition: rational.c:101
frame_node
Definition: avf_showwaves.c:69
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:230
video.h
get_sqrt_h2
static int get_sqrt_h2(int16_t sample, int height)
Definition: avf_showwaves.c:214
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
DRAW_FULL
@ DRAW_FULL
Definition: avf_showwaves.c:59
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
draw_sample_line_rgba_scale
static void draw_sample_line_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:250
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
draw_sample_cline_rgba_full
static void draw_sample_cline_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:346
get_log_h2
static int get_log_h2(int16_t sample, int height)
Definition: avf_showwaves.c:204
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:412
MODE_NB
@ MODE_NB
Definition: avf_showwaves.c:46
FILTER_NB
@ FILTER_NB
Definition: avf_showwaves.c:66
get_sqrt_h
static int get_sqrt_h(int16_t sample, int height)
Definition: avf_showwaves.c:209
get_lin_h2
static int get_lin_h2(int16_t sample, int height)
Definition: avf_showwaves.c:194
FFSIGN
#define FFSIGN(a)
Definition: common.h:66
SCALE_CBRT
@ SCALE_CBRT
Definition: avf_showwaves.c:53
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:643
get_lin_h
static int get_lin_h(int16_t sample, int height)
Definition: avf_showwaves.c:189
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:47
cbrt
#define cbrt
Definition: tablegen.h:35
draw_sample_point_gray
static void draw_sample_point_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:358
draw_sample_p2p_gray
static void draw_sample_p2p_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:379
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
DRAW_NB
@ DRAW_NB
Definition: avf_showwaves.c:60
ShowWavesContext::n
AVRational n
Definition: avf_showwaves.c:85
intreadwrite.h
FLAGS
#define FLAGS
Definition: avf_showwaves.c:107
ShowWavesContext::sum
int64_t * sum
Definition: avf_showwaves.c:103
ShowWavesContext::last_frame
struct frame_node * last_frame
Definition: avf_showwaves.c:101
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:617
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
ShowWavesContext::audio_frames
struct frame_node * audio_frames
Definition: avf_showwaves.c:100
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:178
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
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
init
static av_cold int init(AVFilterContext *ctx)
Definition: avf_showwaves.c:684
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
push_frame
static int push_frame(AVFilterLink *outlink, int i, int64_t pts)
Definition: avf_showwaves.c:563
ShowWavesContext::rate
AVRational rate
Definition: avf_showwaves.c:77
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:192
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
frame
static AVFrame * frame
Definition: demux_decode.c:54
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:65
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_showwaves.c:409
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
ShowWavesContext::scale
int scale
ShowWavesScale.
Definition: avf_showwaves.c:88
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:1402
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
get_log_h
static int get_log_h(int16_t sample, int height)
Definition: avf_showwaves.c:199
activate
filter_frame For filters that do not use the activate() callback
ShowWavesContext::single_pic
int single_pic
Definition: avf_showwaves.c:99
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:405
ShowWavesContext::mode
int mode
ShowWavesMode.
Definition: avf_showwaves.c:87
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:362
parseutils.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showwaves.c:135
ff_avf_showwavespic
const AVFilter ff_avf_showwavespic
ff_audio_default_filterpad
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition: audio.c:32
ShowWavesContext::total_samples
int64_t total_samples
Definition: avf_showwaves.c:102
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: avf_showwaves.c:654
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: avf_showwaves.c:158
abs
#define abs(x)
Definition: cuda_runtime.h:35
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
MODE_POINT
@ MODE_POINT
Definition: avf_showwaves.c:42
ShowWavesContext::draw_mode
int draw_mode
ShowWavesDrawMode.
Definition: avf_showwaves.c:89
draw_sample_cline_gray
static void draw_sample_cline_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:398
f
f
Definition: af_crystalizer.c:121
ShowWavesFilterMode
ShowWavesFilterMode
Definition: avf_showwaves.c:63
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:106
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:374
MODE_CENTERED_LINE
@ MODE_CENTERED_LINE
Definition: avf_showwaves.c:45
draw_sample_p2p_rgba_full
static void draw_sample_p2p_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:310
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
ShowWavesContext::history
int16_t * history
Definition: avf_showwaves.c:81
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
sample
#define sample
Definition: flacdsp_template.c:44
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
SCALE_LIN
@ SCALE_LIN
Definition: avf_showwaves.c:50
height
#define height
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
ff_all_channel_layouts
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:578
MODE_P2P
@ MODE_P2P
Definition: avf_showwaves.c:44
ShowWavesContext::outpicref
AVFrame * outpicref
Definition: avf_showwaves.c:84
internal.h
ShowWavesContext::h
int h
Definition: avf_showwaves.c:76
ShowWavesScale
ShowWavesScale
Definition: avf_showwaves.c:49
push_single_pic
static int push_single_pic(AVFilterLink *outlink)
Definition: avf_showwaves.c:584
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
ff_avf_showwaves
const AVFilter ff_avf_showwaves
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
ShowWavesContext::history_index
int history_index
Definition: avf_showwaves.c:83
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
draw_sample_line_gray
static void draw_sample_line_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:366
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
draw_sample_p2p_rgba_scale
static void draw_sample_p2p_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:283
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:53
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
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
AVFilter
Filter definition.
Definition: avfilter.h:166
ret
ret
Definition: filter_design.txt:187
ShowWavesContext::draw_sample
void(* draw_sample)(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:95
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
ShowWavesContext::fg
uint8_t * fg
Definition: avf_showwaves.c:92
SCALE_LOG
@ SCALE_LOG
Definition: avf_showwaves.c:51
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:572
channel_layout.h
AVRational::den
int den
Denominator.
Definition: rational.h:60
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
draw_sample_cline_rgba_scale
static void draw_sample_cline_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:331
ShowWavesContext::split_channels
int split_channels
Definition: avf_showwaves.c:90
ShowWavesContext::colors
char * colors
Definition: avf_showwaves.c:78
alloc_out_frame
static int alloc_out_frame(ShowWavesContext *showwaves, AVFilterLink *outlink)
Definition: avf_showwaves.c:668
MODE_LINE
@ MODE_LINE
Definition: avf_showwaves.c:43
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
ShowWavesMode
ShowWavesMode
Definition: avf_showwaves.c:41
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
audio.h
OFFSET
#define OFFSET(x)
Definition: avf_showwaves.c:106
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:505
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_add_q
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
Definition: rational.c:93
FF_FILTER_FORWARD_STATUS
FF_FILTER_FORWARD_STATUS(inlink, outlink)
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2038
ShowWavesDrawMode
ShowWavesDrawMode
Definition: avf_showwaves.c:57
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
int
int
Definition: ffmpeg_filter.c:368
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
ShowWavesContext::pixstep
int pixstep
Definition: avf_showwaves.c:86
ShowWavesContext
Definition: avf_showwaves.c:74
ShowWavesContext::q
AVRational q
Definition: avf_showwaves.c:85
SCALE_NB
@ SCALE_NB
Definition: avf_showwaves.c:54
draw_sample_line_rgba_full
static void draw_sample_line_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:268
draw_sample_point_rgba_full
static void draw_sample_point_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
Definition: avf_showwaves.c:241