FFmpeg
avf_showvolume.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
22 #include "libavutil/eval.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/opt.h"
27 #include "avfilter.h"
28 #include "filters.h"
29 #include "formats.h"
30 #include "video.h"
31 
32 static const char *const var_names[] = { "VOLUME", "CHANNEL", "PEAK", NULL };
35 
36 typedef struct ShowVolumeContext {
37  const AVClass *class;
38  int w, h;
39  int b;
40  double f;
42  char *color;
44  int step;
45  float bgopacity;
46  int mode;
47 
51  int draw_text;
53  double *values;
54  uint32_t *color_lut;
55  float *max;
57 
58  double draw_persistent_duration; /* in second */
59  uint8_t persistant_max_rgba[4];
60  int persistent_max_frames; /* number of frames to check max value */
61  float *max_persistent; /* max value for draw_persistent_max for each channel */
62  int *nb_frames_max_display; /* number of frame for each channel, for displaying the max value */
63 
64  void (*meter)(float *src, int nb_samples, float *max);
66 
67 #define OFFSET(x) offsetof(ShowVolumeContext, x)
68 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
69 
70 static const AVOption showvolume_options[] = {
71  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
72  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
73  { "b", "set border width", OFFSET(b), AV_OPT_TYPE_INT, {.i64=1}, 0, 5, FLAGS },
74  { "w", "set channel width", OFFSET(w), AV_OPT_TYPE_INT, {.i64=400}, 80, 8192, FLAGS },
75  { "h", "set channel height", OFFSET(h), AV_OPT_TYPE_INT, {.i64=20}, 1, 900, FLAGS },
76  { "f", "set fade", OFFSET(f), AV_OPT_TYPE_DOUBLE, {.dbl=0.95}, 0, 1, FLAGS },
77  { "c", "set volume color expression", OFFSET(color), AV_OPT_TYPE_STRING, {.str="PEAK*255+floor((1-PEAK)*255)*256+0xff000000"}, 0, 0, FLAGS },
78  { "t", "display channel names", OFFSET(draw_text), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
79  { "v", "display volume value", OFFSET(draw_volume), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
80  { "dm", "duration for max value display", OFFSET(draw_persistent_duration), AV_OPT_TYPE_DOUBLE, {.dbl=0.}, 0, 9000, FLAGS},
81  { "dmc","set color of the max value line", OFFSET(persistant_max_rgba), AV_OPT_TYPE_COLOR, {.str = "orange"}, 0, 0, FLAGS },
82  { "o", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, .unit = "orientation" },
83  { "h", "horizontal", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, .unit = "orientation" },
84  { "v", "vertical", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, .unit = "orientation" },
85  { "s", "set step size", OFFSET(step), AV_OPT_TYPE_INT, {.i64=0}, 0, 5, FLAGS },
86  { "p", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 1, FLAGS },
87  { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, .unit = "mode" },
88  { "p", "peak", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, .unit = "mode" },
89  { "r", "rms", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, .unit = "mode" },
90  { "ds", "set display scale", OFFSET(display_scale), AV_OPT_TYPE_INT, {.i64=LINEAR}, LINEAR, NB_DISPLAY_SCALE - 1, FLAGS, .unit = "display_scale" },
91  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, .unit = "display_scale" },
92  { "log", "log", 0, AV_OPT_TYPE_CONST, {.i64=LOG}, 0, 0, FLAGS, .unit = "display_scale" },
93  { NULL }
94 };
95 
96 AVFILTER_DEFINE_CLASS(showvolume);
97 
99 {
100  ShowVolumeContext *s = ctx->priv;
101  int ret;
102 
103  if (s->color) {
104  ret = av_expr_parse(&s->c_expr, s->color, var_names,
105  NULL, NULL, NULL, NULL, 0, ctx);
106  if (ret < 0)
107  return ret;
108  }
109 
110  return 0;
111 }
112 
114  AVFilterFormatsConfig **cfg_in,
115  AVFilterFormatsConfig **cfg_out)
116 {
119  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
120  int ret;
121 
123  if ((ret = ff_formats_ref(formats, &cfg_in[0]->formats)) < 0)
124  return ret;
125 
127  if ((ret = ff_formats_ref(formats, &cfg_out[0]->formats)) < 0)
128  return ret;
129 
130  return 0;
131 }
132 
133 static void find_peak(float *src, int nb_samples, float *peak)
134 {
135  float max = 0.f;
136 
137  max = 0;
138  for (int i = 0; i < nb_samples; i++)
139  max = fmaxf(max, fabsf(src[i]));
140  *peak = max;
141 }
142 
143 static void find_rms(float *src, int nb_samples, float *rms)
144 {
145  float sum = 0.f;
146 
147  for (int i = 0; i < nb_samples; i++)
148  sum += src[i] * src[i];
149  *rms = sqrtf(sum / nb_samples);
150 }
151 
153 {
154  AVFilterContext *ctx = inlink->dst;
155  ShowVolumeContext *s = ctx->priv;
156 
157  s->nb_samples = FFMAX(1, av_rescale(inlink->sample_rate, s->frame_rate.den, s->frame_rate.num));
158  s->values = av_calloc(inlink->ch_layout.nb_channels * VAR_VARS_NB, sizeof(double));
159  if (!s->values)
160  return AVERROR(ENOMEM);
161 
162  s->color_lut = av_calloc(s->w, sizeof(*s->color_lut) * inlink->ch_layout.nb_channels);
163  if (!s->color_lut)
164  return AVERROR(ENOMEM);
165 
166  s->max = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->max));
167  if (!s->max)
168  return AVERROR(ENOMEM);
169 
170  switch (s->mode) {
171  case 0: s->meter = find_peak; break;
172  case 1: s->meter = find_rms; break;
173  default: return AVERROR_BUG;
174  }
175 
176  if (s->draw_persistent_duration > 0.) {
177  s->persistent_max_frames = (int) FFMAX(av_q2d(s->frame_rate) * s->draw_persistent_duration, 1.);
178  s->max_persistent = av_calloc(inlink->ch_layout.nb_channels * s->persistent_max_frames, sizeof(*s->max_persistent));
179  s->nb_frames_max_display = av_calloc(inlink->ch_layout.nb_channels * s->persistent_max_frames, sizeof(*s->nb_frames_max_display));
180  if (!s->max_persistent ||
181  !s->nb_frames_max_display)
182  return AVERROR(ENOMEM);
183  }
184  return 0;
185 }
186 
187 static int config_output(AVFilterLink *outlink)
188 {
189  FilterLink *l = ff_filter_link(outlink);
190  ShowVolumeContext *s = outlink->src->priv;
191  AVFilterLink *inlink = outlink->src->inputs[0];
192  int ch;
193 
194  if (s->orientation) {
195  outlink->h = s->w;
196  outlink->w = s->h * inlink->ch_layout.nb_channels + (inlink->ch_layout.nb_channels - 1) * s->b;
197  } else {
198  outlink->w = s->w;
199  outlink->h = s->h * inlink->ch_layout.nb_channels + (inlink->ch_layout.nb_channels - 1) * s->b;
200  }
201 
202  outlink->sample_aspect_ratio = (AVRational){1,1};
203  l->frame_rate = s->frame_rate;
204  outlink->time_base = av_inv_q(l->frame_rate);
205 
206  for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
207  int i;
208 
209  for (i = 0; i < s->w; i++) {
210  float max = i / (float)(s->w - 1);
211 
212  s->values[ch * VAR_VARS_NB + VAR_PEAK] = max;
213  s->values[ch * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
214  s->values[ch * VAR_VARS_NB + VAR_CHANNEL] = ch;
215  s->color_lut[ch * s->w + i] = av_expr_eval(s->c_expr, &s->values[ch * VAR_VARS_NB], NULL);
216  }
217  }
218 
219  return 0;
220 }
221 
222 static void drawtext(AVFrame *pic, int x, int y, const char *txt, int o)
223 {
224  const uint8_t *font;
225  int font_height;
226  int i;
227 
228  font = avpriv_cga_font, font_height = 8;
229 
230  for (i = 0; txt[i]; i++) {
231  int char_y, mask;
232 
233  if (o) { /* vertical orientation */
234  for (char_y = font_height - 1; char_y >= 0; char_y--) {
235  uint8_t *p = pic->data[0] + (y + i * 10) * pic->linesize[0] + x * 4;
236  for (mask = 0x80; mask; mask >>= 1) {
237  if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
238  AV_WN32(&p[char_y * 4], ~AV_RN32(&p[char_y * 4]));
239  p += pic->linesize[0];
240  }
241  }
242  } else { /* horizontal orientation */
243  uint8_t *p = pic->data[0] + y * pic->linesize[0] + (x + i * 8) * 4;
244  for (char_y = 0; char_y < font_height; char_y++) {
245  for (mask = 0x80; mask; mask >>= 1) {
246  if (font[txt[i] * font_height + char_y] & mask)
247  AV_WN32(p, ~AV_RN32(p));
248  p += 4;
249  }
250  p += pic->linesize[0] - 8 * 4;
251  }
252  }
253  }
254 }
255 
257 {
258  int i, j;
259  const uint32_t bg = (uint32_t)(s->bgopacity * 255) << 24;
260 
261  for (i = 0; i < outlink->h; i++) {
262  uint32_t *dst = (uint32_t *)(s->out->data[0] + i * s->out->linesize[0]);
263  for (j = 0; j < outlink->w; j++)
264  AV_WN32A(dst + j, bg);
265  }
266 }
267 
268 static inline int calc_max_draw(ShowVolumeContext *s, AVFilterLink *outlink, float max)
269 {
270  float max_val;
271  if (s->display_scale == LINEAR) {
272  max_val = max;
273  } else { /* log */
274  max_val = av_clipf(0.21 * log10(max) + 1, 0, 1);
275  }
276  if (s->orientation) { /* vertical */
277  return outlink->h - outlink->h * max_val;
278  } else { /* horizontal */
279  return s->w * max_val;
280  }
281 }
282 
283 static inline void calc_persistent_max(ShowVolumeContext *s, float max, int channel)
284 {
285  /* update max value for persistent max display */
286  if ((max >= s->max_persistent[channel]) || (s->nb_frames_max_display[channel] >= s->persistent_max_frames)) { /* update max value for display */
287  s->max_persistent[channel] = max;
288  s->nb_frames_max_display[channel] = 0;
289  } else {
290  s->nb_frames_max_display[channel] += 1; /* incremente display frame count */
291  }
292 }
293 
294 static inline void draw_max_line(ShowVolumeContext *s, int max_draw, int channel)
295 {
296  int k;
297  if (s->orientation) { /* vertical */
298  uint8_t *dst = s->out->data[0] + max_draw * s->out->linesize[0] + channel * (s->b + s->h) * 4;
299  for (k = 0; k < s->h; k++) {
300  memcpy(dst + k * 4, s->persistant_max_rgba, sizeof(s->persistant_max_rgba));
301  }
302  } else { /* horizontal */
303  for (k = 0; k < s->h; k++) {
304  uint8_t *dst = s->out->data[0] + (channel * s->h + channel * s->b + k) * s->out->linesize[0];
305  memcpy(dst + max_draw * 4, s->persistant_max_rgba, sizeof(s->persistant_max_rgba));
306  }
307  }
308 }
309 
310 static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
311 {
312  AVFilterContext *ctx = inlink->dst;
313  AVFilterLink *outlink = ctx->outputs[0];
314  ShowVolumeContext *s = ctx->priv;
315  const int step = s->step;
316  int c, j, k, max_draw, ret;
317  char channel_name[64];
318  AVFrame *out;
319 
320  if (!s->out || s->out->width != outlink->w ||
321  s->out->height != outlink->h) {
322  av_frame_free(&s->out);
323  s->out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
324  if (!s->out) {
325  av_frame_free(&insamples);
326  return AVERROR(ENOMEM);
327  }
328  clear_picture(s, outlink);
329  }
330  s->out->pts = av_rescale_q(insamples->pts, inlink->time_base, outlink->time_base);
331  s->out->duration = 1;
332 
333  if ((s->f < 1.) && (s->f > 0.)) {
334  for (j = 0; j < outlink->h; j++) {
335  uint8_t *dst = s->out->data[0] + j * s->out->linesize[0];
336  const uint32_t alpha = s->bgopacity * 255;
337 
338  for (k = 0; k < outlink->w; k++) {
339  dst[k * 4 + 0] = FFMAX(dst[k * 4 + 0] * s->f, 0);
340  dst[k * 4 + 1] = FFMAX(dst[k * 4 + 1] * s->f, 0);
341  dst[k * 4 + 2] = FFMAX(dst[k * 4 + 2] * s->f, 0);
342  dst[k * 4 + 3] = FFMAX(dst[k * 4 + 3] * s->f, alpha);
343  }
344  }
345  } else if (s->f == 0.) {
346  clear_picture(s, outlink);
347  }
348 
349  if (s->orientation) { /* vertical */
350  for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
351  float *src = (float *)insamples->extended_data[c];
352  uint32_t *lut = s->color_lut + s->w * c;
353  float max;
354 
355  s->meter(src, insamples->nb_samples, &s->max[c]);
356  max = s->max[c];
357 
358  s->values[c * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
359  max = av_clipf(max, 0, 1);
360  max_draw = calc_max_draw(s, outlink, max);
361 
362  for (j = s->w - 1; j >= max_draw; j--) {
363  uint8_t *dst = s->out->data[0] + j * s->out->linesize[0] + c * (s->b + s->h) * 4;
364  for (k = 0; k < s->h; k++) {
365  AV_WN32A(&dst[k * 4], lut[s->w - j - 1]);
366  }
367  if (j & step)
368  j -= step;
369  }
370 
371  if (s->draw_persistent_duration > 0.) {
373  max_draw = FFMAX(0, calc_max_draw(s, outlink, s->max_persistent[c]) - 1);
374  draw_max_line(s, max_draw, c);
375  }
376  }
377  } else { /* horizontal */
378  for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
379  float *src = (float *)insamples->extended_data[c];
380  uint32_t *lut = s->color_lut + s->w * c;
381  float max;
382 
383  s->meter(src, insamples->nb_samples, &s->max[c]);
384  max = s->max[c];
385 
386  s->values[c * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
387  max = av_clipf(max, 0, 1);
388  max_draw = calc_max_draw(s, outlink, max);
389 
390  for (j = 0; j < s->h; j++) {
391  uint8_t *dst = s->out->data[0] + (c * s->h + c * s->b + j) * s->out->linesize[0];
392 
393  for (k = 0; k < max_draw; k++) {
394  AV_WN32A(dst + k * 4, lut[k]);
395  if (k & step)
396  k += step;
397  }
398  }
399 
400  if (s->draw_persistent_duration > 0.) {
402  max_draw = FFMAX(0, calc_max_draw(s, outlink, s->max_persistent[c]) - 1);
403  draw_max_line(s, max_draw, c);
404  }
405  }
406  }
407 
408  av_frame_free(&insamples);
409  out = av_frame_clone(s->out);
410  if (!out)
411  return AVERROR(ENOMEM);
413  if (ret < 0) {
414  av_frame_free(&out);
415  return ret;
416  }
417 
418  /* draw channel names */
419  for (c = 0; c < inlink->ch_layout.nb_channels && s->h >= 10 && s->draw_text; c++) {
420  if (s->orientation) { /* vertical */
422  if (ret < 0)
423  continue;
424  drawtext(out, c * (s->h + s->b) + (s->h - 10) / 2, outlink->h - 35, channel_name, 1);
425  } else { /* horizontal */
427  if (ret < 0)
428  continue;
429  drawtext(out, 2, c * (s->h + s->b) + (s->h - 8) / 2, channel_name, 0);
430  }
431  }
432 
433  /* draw volume level */
434  for (c = 0; c < inlink->ch_layout.nb_channels && s->h >= 8 && s->draw_volume; c++) {
435  char buf[16];
436 
437  if (s->orientation) { /* vertical */
438  snprintf(buf, sizeof(buf), "%.2f", s->values[c * VAR_VARS_NB + VAR_VOLUME]);
439  drawtext(out, c * (s->h + s->b) + (s->h - 8) / 2, 2, buf, 1);
440  } else { /* horizontal */
441  snprintf(buf, sizeof(buf), "%.2f", s->values[c * VAR_VARS_NB + VAR_VOLUME]);
442  drawtext(out, FFMAX(0, s->w - 8 * (int)strlen(buf)), c * (s->h + s->b) + (s->h - 8) / 2, buf, 0);
443  }
444  }
445 
446  return ff_filter_frame(outlink, out);
447 }
448 
450 {
451  AVFilterLink *inlink = ctx->inputs[0];
452  AVFilterLink *outlink = ctx->outputs[0];
453  ShowVolumeContext *s = ctx->priv;
454  AVFrame *in = NULL;
455  int ret;
456 
458 
459  ret = ff_inlink_consume_samples(inlink, s->nb_samples, s->nb_samples, &in);
460  if (ret < 0)
461  return ret;
462  if (ret > 0)
463  return filter_frame(inlink, in);
464 
465  if (ff_inlink_queued_samples(inlink) >= s->nb_samples) {
467  return 0;
468  }
469 
472 
473  return FFERROR_NOT_READY;
474 }
475 
477 {
478  ShowVolumeContext *s = ctx->priv;
479 
480  av_frame_free(&s->out);
481  av_expr_free(s->c_expr);
482  av_freep(&s->values);
483  av_freep(&s->color_lut);
484  av_freep(&s->max);
485  av_freep(&s->max_persistent);
486  av_freep(&s->nb_frames_max_display);
487 }
488 
489 static const AVFilterPad showvolume_inputs[] = {
490  {
491  .name = "default",
492  .type = AVMEDIA_TYPE_AUDIO,
493  .config_props = config_input,
494  },
495 };
496 
497 static const AVFilterPad showvolume_outputs[] = {
498  {
499  .name = "default",
500  .type = AVMEDIA_TYPE_VIDEO,
501  .config_props = config_output,
502  },
503 };
504 
506  .name = "showvolume",
507  .description = NULL_IF_CONFIG_SMALL("Convert input audio volume to video output."),
508  .init = init,
509  .activate = activate,
510  .uninit = uninit,
511  .priv_size = sizeof(ShowVolumeContext),
515  .priv_class = &showvolume_class,
516 };
formats
formats
Definition: signature.h:47
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:116
ShowVolumeContext
Definition: avf_showvolume.c:36
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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:435
out
FILE * out
Definition: movenc.c:55
color
Definition: vf_paletteuse.c:513
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1061
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
showvolume_inputs
static const AVFilterPad showvolume_inputs[]
Definition: avf_showvolume.c:489
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
Definition: opt.h:315
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
ShowVolumeContext::max_persistent
float * max_persistent
Definition: avf_showvolume.c:61
ShowVolumeContext::meter
void(* meter)(float *src, int nb_samples, float *max)
Definition: avf_showvolume.c:64
ShowVolumeContext::h
int h
Definition: avf_showvolume.c:38
mask
int mask
Definition: mediacodecdec_common.c:154
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
VAR_CHANNEL
@ VAR_CHANNEL
Definition: avf_showvolume.c:33
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
mode
Definition: swscale.c:52
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:501
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
w
uint8_t w
Definition: llviddspenc.c:38
av_channel_layout_channel_from_index
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
Definition: channel_layout.c:671
AVOption
AVOption.
Definition: opt.h:429
b
#define b
Definition: input.c:41
clear_picture
static void clear_picture(ShowVolumeContext *s, AVFilterLink *outlink)
Definition: avf_showvolume.c:256
ShowVolumeContext::c_expr
AVExpr * c_expr
Definition: avf_showvolume.c:50
ShowVolumeContext::display_scale
int display_scale
Definition: avf_showvolume.c:56
ShowVolumeContext::draw_volume
int draw_volume
Definition: avf_showvolume.c:52
AV_WN32A
#define AV_WN32A(p, v)
Definition: intreadwrite.h:534
max
#define max(a, b)
Definition: cuda_runtime.h:33
channel_name
Definition: channel_layout.c:42
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
ShowVolumeContext::out
AVFrame * out
Definition: avf_showvolume.c:49
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:434
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
calc_max_draw
static int calc_max_draw(ShowVolumeContext *s, AVFilterLink *outlink, float max)
Definition: avf_showvolume.c:268
formats.h
av_expr_parse
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:710
ShowVolumeContext::mode
int mode
Definition: avf_showvolume.c:46
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:472
showvolume_options
static const AVOption showvolume_options[]
Definition: avf_showvolume.c:70
VAR_VARS_NB
@ VAR_VARS_NB
Definition: avf_showvolume.c:33
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:358
drawtext
static void drawtext(AVFrame *pic, int x, int y, const char *txt, int o)
Definition: avf_showvolume.c:222
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(showvolume)
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
draw_max_line
static void draw_max_line(ShowVolumeContext *s, int max_draw, int channel)
Definition: avf_showvolume.c:294
av_cold
#define av_cold
Definition: attributes.h:90
float
float
Definition: af_crystalizer.c:122
intreadwrite.h
ShowVolumeContext::orientation
int orientation
Definition: avf_showvolume.c:43
s
#define s(width, name)
Definition: cbs_vp9.c:198
LOG
@ LOG
Definition: avf_showvolume.c:34
ShowVolumeContext::max
float * max
Definition: avf_showvolume.c:55
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
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:678
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
ShowVolumeContext::b
int b
Definition: avf_showvolume.c:39
ShowVolumeContext::step
int step
Definition: avf_showvolume.c:44
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:792
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:609
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
activate
static int activate(AVFilterContext *ctx)
Definition: avf_showvolume.c:449
AVExpr
Definition: eval.c:158
init
static av_cold int init(AVFilterContext *ctx)
Definition: avf_showvolume.c:98
find_rms
static void find_rms(float *src, int nb_samples, float *rms)
Definition: avf_showvolume.c:143
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
ShowVolumeContext::w
int w
Definition: avf_showvolume.c:38
ff_inlink_make_frame_writable
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Definition: avfilter.c:1537
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
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:1510
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition: opt.h:323
calc_persistent_max
static void calc_persistent_max(ShowVolumeContext *s, float max, int channel)
Definition: avf_showvolume.c:283
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:465
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:360
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
find_peak
static void find_peak(float *src, int nb_samples, float *peak)
Definition: avf_showvolume.c:133
av_clipf
av_clipf
Definition: af_crystalizer.c:122
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_showvolume.c:187
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:111
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
ShowVolumeContext::nb_frames_max_display
int * nb_frames_max_display
Definition: avf_showvolume.c:62
ff_avf_showvolume
const AVFilter ff_avf_showvolume
Definition: avf_showvolume.c:505
eval.h
ShowVolumeContext::nb_samples
int nb_samples
Definition: avf_showvolume.c:48
f
f
Definition: af_crystalizer.c:122
var_names
static const char *const var_names[]
Definition: avf_showvolume.c:32
VAR_PEAK
@ VAR_PEAK
Definition: avf_showvolume.c:33
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:94
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:372
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
ShowVolumeContext::persistent_max_frames
int persistent_max_frames
Definition: avf_showvolume.c:60
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
fmaxf
float fmaxf(float, float)
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
OFFSET
#define OFFSET(x)
Definition: avf_showvolume.c:67
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: avf_showvolume.c:113
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
xga_font_data.h
ShowVolumeContext::draw_text
int draw_text
Definition: avf_showvolume.c:51
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:469
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_channel_name
int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id)
Get a human readable string in an abbreviated form describing a given channel.
Definition: channel_layout.c:104
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:450
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
ff_inlink_queued_samples
int ff_inlink_queued_samples(AVFilterLink *link)
Definition: avfilter.c:1465
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
showvolume_outputs
static const AVFilterPad showvolume_outputs[]
Definition: avf_showvolume.c:497
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
AVFilter
Filter definition.
Definition: avfilter.h:201
LINEAR
@ LINEAR
Definition: avf_showvolume.c:34
ShowVolumeContext::color
char * color
Definition: avf_showvolume.c:42
ret
ret
Definition: filter_design.txt:187
ShowVolumeContext::color_lut
uint32_t * color_lut
Definition: avf_showvolume.c:54
ShowVolumeContext::values
double * values
Definition: avf_showvolume.c:53
draw_text
static void draw_text(FFDrawContext *draw, AVFrame *out, FFDrawColor *color, int x0, int y0, const uint8_t *text)
Definition: src_avsynctest.c:247
channel_layout.h
ShowVolumeContext::draw_persistent_duration
double draw_persistent_duration
Definition: avf_showvolume.c:58
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
FLAGS
#define FLAGS
Definition: avf_showvolume.c:68
ShowVolumeContext::bgopacity
float bgopacity
Definition: avf_showvolume.c:45
VAR_VOLUME
@ VAR_VOLUME
Definition: avf_showvolume.c:33
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: avf_showvolume.c:310
DisplayScale
DisplayScale
Definition: avf_ahistogram.c:29
avpriv_cga_font
const uint8_t avpriv_cga_font[2048]
Definition: xga_font_data.c:29
FF_FILTER_FORWARD_STATUS
FF_FILTER_FORWARD_STATUS(inlink, outlink)
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
NB_DISPLAY_SCALE
@ NB_DISPLAY_SCALE
Definition: avf_showvolume.c:34
config_input
static int config_input(AVFilterLink *inlink)
Definition: avf_showvolume.c:152
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:434
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showvolume.c:476
ShowVolumeContext::frame_rate
AVRational frame_rate
Definition: avf_showvolume.c:41
h
h
Definition: vp9dsp_template.c:2070
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
snprintf
#define snprintf
Definition: snprintf.h:34
ShowVolumeContext::persistant_max_rgba
uint8_t persistant_max_rgba[4]
Definition: avf_showvolume.c:59
src
#define src
Definition: vp8dsp.c:248
channel
channel
Definition: ebur128.h:39
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:239
ShowVolumeContext::f
double f
Definition: avf_showvolume.c:40