FFmpeg
af_astats.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Rob Sykes <robs@users.sourceforge.net>
3  * Copyright (c) 2013 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <float.h>
23 #include <math.h>
24 
25 #include "libavutil/opt.h"
26 #include "audio.h"
27 #include "avfilter.h"
28 #include "internal.h"
29 
30 #define HISTOGRAM_SIZE 8192
31 #define HISTOGRAM_MAX (HISTOGRAM_SIZE-1)
32 
33 #define MEASURE_ALL UINT_MAX
34 #define MEASURE_NONE 0
35 
36 #define MEASURE_DC_OFFSET (1 << 0)
37 #define MEASURE_MIN_LEVEL (1 << 1)
38 #define MEASURE_MAX_LEVEL (1 << 2)
39 #define MEASURE_MIN_DIFFERENCE (1 << 3)
40 #define MEASURE_MAX_DIFFERENCE (1 << 4)
41 #define MEASURE_MEAN_DIFFERENCE (1 << 5)
42 #define MEASURE_RMS_DIFFERENCE (1 << 6)
43 #define MEASURE_PEAK_LEVEL (1 << 7)
44 #define MEASURE_RMS_LEVEL (1 << 8)
45 #define MEASURE_RMS_PEAK (1 << 9)
46 #define MEASURE_RMS_TROUGH (1 << 10)
47 #define MEASURE_CREST_FACTOR (1 << 11)
48 #define MEASURE_FLAT_FACTOR (1 << 12)
49 #define MEASURE_PEAK_COUNT (1 << 13)
50 #define MEASURE_BIT_DEPTH (1 << 14)
51 #define MEASURE_DYNAMIC_RANGE (1 << 15)
52 #define MEASURE_ZERO_CROSSINGS (1 << 16)
53 #define MEASURE_ZERO_CROSSINGS_RATE (1 << 17)
54 #define MEASURE_NUMBER_OF_SAMPLES (1 << 18)
55 #define MEASURE_NUMBER_OF_NANS (1 << 19)
56 #define MEASURE_NUMBER_OF_INFS (1 << 20)
57 #define MEASURE_NUMBER_OF_DENORMALS (1 << 21)
58 #define MEASURE_NOISE_FLOOR (1 << 22)
59 #define MEASURE_NOISE_FLOOR_COUNT (1 << 23)
60 
61 #define MEASURE_MINMAXPEAK (MEASURE_MIN_LEVEL | MEASURE_MAX_LEVEL | MEASURE_PEAK_LEVEL)
62 
63 typedef struct ChannelStats {
64  double last;
65  double last_non_zero;
66  double min_non_zero;
67  double sigma_x, sigma_x2;
69  double min, max;
70  double nmin, nmax;
71  double min_run, max_run;
72  double min_runs, max_runs;
73  double min_diff, max_diff;
74  double diff1_sum;
75  double diff1_sum_x2;
76  uint64_t mask, imask;
77  uint64_t min_count, max_count;
79  uint64_t zero_runs;
80  uint64_t nb_samples;
81  uint64_t nb_nans;
82  uint64_t nb_infs;
83  uint64_t nb_denormals;
84  double *win_samples;
86  int win_pos;
87  int max_index;
88  double noise_floor;
89 } ChannelStats;
90 
91 typedef struct AudioStatsContext {
92  const AVClass *class;
95  uint64_t tc_samples;
96  double time_constant;
97  double mult;
98  int metadata;
104  int is_float;
107 
108 #define OFFSET(x) offsetof(AudioStatsContext, x)
109 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
110 
111 static const AVOption astats_options[] = {
112  { "length", "set the window length", OFFSET(time_constant), AV_OPT_TYPE_DOUBLE, {.dbl=.05}, .01, 10, FLAGS },
113  { "metadata", "inject metadata in the filtergraph", OFFSET(metadata), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
114  { "reset", "recalculate stats after this many frames", OFFSET(reset_count), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
115  { "measure_perchannel", "only measure_perchannel these per-channel statistics", OFFSET(measure_perchannel), AV_OPT_TYPE_FLAGS, {.i64=MEASURE_ALL}, 0, UINT_MAX, FLAGS, "measure" },
116  { "none" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NONE }, 0, 0, FLAGS, "measure" },
117  { "all" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_ALL }, 0, 0, FLAGS, "measure" },
118  { "DC_offset" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_DC_OFFSET }, 0, 0, FLAGS, "measure" },
119  { "Min_level" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MIN_LEVEL }, 0, 0, FLAGS, "measure" },
120  { "Max_level" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MAX_LEVEL }, 0, 0, FLAGS, "measure" },
121  { "Min_difference" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MIN_DIFFERENCE }, 0, 0, FLAGS, "measure" },
122  { "Max_difference" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MAX_DIFFERENCE }, 0, 0, FLAGS, "measure" },
123  { "Mean_difference" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MEAN_DIFFERENCE }, 0, 0, FLAGS, "measure" },
124  { "RMS_difference" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_RMS_DIFFERENCE }, 0, 0, FLAGS, "measure" },
125  { "Peak_level" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_PEAK_LEVEL }, 0, 0, FLAGS, "measure" },
126  { "RMS_level" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_RMS_LEVEL }, 0, 0, FLAGS, "measure" },
127  { "RMS_peak" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_RMS_PEAK }, 0, 0, FLAGS, "measure" },
128  { "RMS_trough" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_RMS_TROUGH }, 0, 0, FLAGS, "measure" },
129  { "Crest_factor" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_CREST_FACTOR }, 0, 0, FLAGS, "measure" },
130  { "Flat_factor" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_FLAT_FACTOR }, 0, 0, FLAGS, "measure" },
131  { "Peak_count" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_PEAK_COUNT }, 0, 0, FLAGS, "measure" },
132  { "Bit_depth" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_BIT_DEPTH }, 0, 0, FLAGS, "measure" },
133  { "Dynamic_range" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_DYNAMIC_RANGE }, 0, 0, FLAGS, "measure" },
134  { "Zero_crossings" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_ZERO_CROSSINGS }, 0, 0, FLAGS, "measure" },
135  { "Zero_crossings_rate" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_ZERO_CROSSINGS_RATE }, 0, 0, FLAGS, "measure" },
136  { "Noise_floor" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NOISE_FLOOR }, 0, 0, FLAGS, "measure" },
137  { "Noise_floor_count" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NOISE_FLOOR_COUNT }, 0, 0, FLAGS, "measure" },
138  { "Number_of_samples" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_SAMPLES }, 0, 0, FLAGS, "measure" },
139  { "Number_of_NaNs" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_NANS }, 0, 0, FLAGS, "measure" },
140  { "Number_of_Infs" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_INFS }, 0, 0, FLAGS, "measure" },
141  { "Number_of_denormals" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_DENORMALS }, 0, 0, FLAGS, "measure" },
142  { "measure_overall", "only measure_perchannel these overall statistics", OFFSET(measure_overall), AV_OPT_TYPE_FLAGS, {.i64=MEASURE_ALL}, 0, UINT_MAX, FLAGS, "measure" },
143  { NULL }
144 };
145 
146 AVFILTER_DEFINE_CLASS(astats);
147 
149 {
152  static const enum AVSampleFormat sample_fmts[] = {
159  };
160  int ret;
161 
162  layouts = ff_all_channel_counts();
163  if (!layouts)
164  return AVERROR(ENOMEM);
165  ret = ff_set_common_channel_layouts(ctx, layouts);
166  if (ret < 0)
167  return ret;
168 
169  formats = ff_make_format_list(sample_fmts);
170  if (!formats)
171  return AVERROR(ENOMEM);
172  ret = ff_set_common_formats(ctx, formats);
173  if (ret < 0)
174  return ret;
175 
176  formats = ff_all_samplerates();
177  if (!formats)
178  return AVERROR(ENOMEM);
179  return ff_set_common_samplerates(ctx, formats);
180 }
181 
183 {
184  int c;
185 
186  for (c = 0; c < s->nb_channels; c++) {
187  ChannelStats *p = &s->chstats[c];
188 
189  p->min = p->nmin = p->min_sigma_x2 = DBL_MAX;
190  p->max = p->nmax = p->max_sigma_x2 =-DBL_MAX;
191  p->min_non_zero = DBL_MAX;
192  p->min_diff = DBL_MAX;
193  p->max_diff = 0;
194  p->sigma_x = 0;
195  p->sigma_x2 = 0;
196  p->avg_sigma_x2 = 0;
197  p->min_run = 0;
198  p->max_run = 0;
199  p->min_runs = 0;
200  p->max_runs = 0;
201  p->diff1_sum = 0;
202  p->diff1_sum_x2 = 0;
203  p->mask = 0;
204  p->imask = 0xFFFFFFFFFFFFFFFF;
205  p->min_count = 0;
206  p->max_count = 0;
207  p->zero_runs = 0;
208  p->nb_samples = 0;
209  p->nb_nans = 0;
210  p->nb_infs = 0;
211  p->nb_denormals = 0;
212  p->last = NAN;
213  p->noise_floor = NAN;
214  p->noise_floor_count = 0;
215  p->win_pos = 0;
216  memset(p->win_samples, 0, s->tc_samples * sizeof(*p->win_samples));
217  memset(p->histogram, 0, sizeof(p->histogram));
218  }
219 }
220 
221 static int config_output(AVFilterLink *outlink)
222 {
223  AudioStatsContext *s = outlink->src->priv;
224 
225  s->chstats = av_calloc(sizeof(*s->chstats), outlink->channels);
226  if (!s->chstats)
227  return AVERROR(ENOMEM);
228 
229  s->tc_samples = 5 * s->time_constant * outlink->sample_rate + .5;
230  s->nb_channels = outlink->channels;
231 
232  for (int i = 0; i < s->nb_channels; i++) {
233  ChannelStats *p = &s->chstats[i];
234 
235  p->win_samples = av_calloc(s->tc_samples, sizeof(*p->win_samples));
236  if (!p->win_samples)
237  return AVERROR(ENOMEM);
238  }
239 
240  s->mult = exp((-1 / s->time_constant / outlink->sample_rate));
241  s->nb_frames = 0;
242  s->maxbitdepth = av_get_bytes_per_sample(outlink->format) * 8;
243  s->is_double = outlink->format == AV_SAMPLE_FMT_DBL ||
244  outlink->format == AV_SAMPLE_FMT_DBLP;
245 
246  s->is_float = outlink->format == AV_SAMPLE_FMT_FLT ||
247  outlink->format == AV_SAMPLE_FMT_FLTP;
248 
249  reset_stats(s);
250 
251  return 0;
252 }
253 
254 static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
255 {
256  unsigned result = s->maxbitdepth;
257 
258  mask = mask & (~imask);
259 
260  for (; result && !(mask & 1); --result, mask >>= 1);
261 
262  depth->den = result;
263  depth->num = 0;
264 
265  for (; result; --result, mask >>= 1)
266  if (mask & 1)
267  depth->num++;
268 }
269 
270 static inline void update_minmax(AudioStatsContext *s, ChannelStats *p, double d)
271 {
272  if (d < p->min)
273  p->min = d;
274  if (d > p->max)
275  p->max = d;
276 }
277 
278 static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i)
279 {
280  double drop;
281  int index;
282 
283  if (d < p->min) {
284  p->min = d;
285  p->nmin = nd;
286  p->min_run = 1;
287  p->min_runs = 0;
288  p->min_count = 1;
289  } else if (d == p->min) {
290  p->min_count++;
291  p->min_run = d == p->last ? p->min_run + 1 : 1;
292  } else if (p->last == p->min) {
293  p->min_runs += p->min_run * p->min_run;
294  }
295 
296  if (d != 0 && FFABS(d) < p->min_non_zero)
297  p->min_non_zero = FFABS(d);
298 
299  if (d > p->max) {
300  p->max = d;
301  p->nmax = nd;
302  p->max_run = 1;
303  p->max_runs = 0;
304  p->max_count = 1;
305  } else if (d == p->max) {
306  p->max_count++;
307  p->max_run = d == p->last ? p->max_run + 1 : 1;
308  } else if (p->last == p->max) {
309  p->max_runs += p->max_run * p->max_run;
310  }
311 
312  if (d != 0) {
313  p->zero_runs += FFSIGN(d) != FFSIGN(p->last_non_zero);
314  p->last_non_zero = d;
315  }
316 
317  p->sigma_x += nd;
318  p->sigma_x2 += nd * nd;
319  p->avg_sigma_x2 = p->avg_sigma_x2 * s->mult + (1.0 - s->mult) * nd * nd;
320  if (!isnan(p->last)) {
321  p->min_diff = FFMIN(p->min_diff, fabs(d - p->last));
322  p->max_diff = FFMAX(p->max_diff, fabs(d - p->last));
323  p->diff1_sum += fabs(d - p->last);
324  p->diff1_sum_x2 += (d - p->last) * (d - p->last);
325  }
326  p->last = d;
327  p->mask |= i;
328  p->imask &= i;
329 
330  drop = p->win_samples[p->win_pos];
331  p->win_samples[p->win_pos] = nd;
332  index = av_clip(FFABS(nd) * HISTOGRAM_MAX, 0, HISTOGRAM_MAX);
333  p->max_index = FFMAX(p->max_index, index);
334  p->histogram[index]++;
335  if (!isnan(p->noise_floor))
336  p->histogram[av_clip(FFABS(drop) * HISTOGRAM_MAX, 0, HISTOGRAM_MAX)]--;
337  p->win_pos++;
338 
339  while (p->histogram[p->max_index] == 0)
340  p->max_index--;
341  if (p->win_pos >= s->tc_samples || !isnan(p->noise_floor)) {
342  double noise_floor = 1.;
343 
344  for (int i = p->max_index; i >= 0; i--) {
345  if (p->histogram[i]) {
346  noise_floor = i / (double)HISTOGRAM_MAX;
347  break;
348  }
349  }
350 
351  if (isnan(p->noise_floor)) {
353  p->noise_floor_count = 1;
354  } else {
355  if (noise_floor < p->noise_floor) {
357  p->noise_floor_count = 1;
358  } else if (noise_floor == p->noise_floor) {
359  p->noise_floor_count++;
360  }
361  }
362  }
363 
364  if (p->win_pos >= s->tc_samples) {
365  p->win_pos = 0;
366  }
367 
368  if (p->nb_samples >= s->tc_samples) {
371  }
372  p->nb_samples++;
373 }
374 
375 static inline void update_float_stat(AudioStatsContext *s, ChannelStats *p, float d)
376 {
377  int type = fpclassify(d);
378 
379  p->nb_nans += type == FP_NAN;
380  p->nb_infs += type == FP_INFINITE;
381  p->nb_denormals += type == FP_SUBNORMAL;
382 }
383 
384 static inline void update_double_stat(AudioStatsContext *s, ChannelStats *p, double d)
385 {
386  int type = fpclassify(d);
387 
388  p->nb_nans += type == FP_NAN;
389  p->nb_infs += type == FP_INFINITE;
390  p->nb_denormals += type == FP_SUBNORMAL;
391 }
392 
393 static void set_meta(AVDictionary **metadata, int chan, const char *key,
394  const char *fmt, double val)
395 {
396  uint8_t value[128];
397  uint8_t key2[128];
398 
399  snprintf(value, sizeof(value), fmt, val);
400  if (chan)
401  snprintf(key2, sizeof(key2), "lavfi.astats.%d.%s", chan, key);
402  else
403  snprintf(key2, sizeof(key2), "lavfi.astats.%s", key);
404  av_dict_set(metadata, key2, value, 0);
405 }
406 
407 #define LINEAR_TO_DB(x) (log10(x) * 20)
408 
409 static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
410 {
411  uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0;
412  uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0;
413  double min_runs = 0, max_runs = 0,
414  min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0,
415  nmin = DBL_MAX, nmax =-DBL_MAX,
416  max_sigma_x = 0,
417  diff1_sum = 0,
418  diff1_sum_x2 = 0,
419  sigma_x = 0,
420  sigma_x2 = 0,
421  noise_floor = 0,
422  min_sigma_x2 = DBL_MAX,
423  max_sigma_x2 =-DBL_MAX;
424  AVRational depth;
425  int c;
426 
427  for (c = 0; c < s->nb_channels; c++) {
428  ChannelStats *p = &s->chstats[c];
429 
430  if (p->nb_samples < s->tc_samples)
431  p->min_sigma_x2 = p->max_sigma_x2 = p->sigma_x2 / p->nb_samples;
432 
433  min = FFMIN(min, p->min);
434  max = FFMAX(max, p->max);
435  nmin = FFMIN(nmin, p->nmin);
436  nmax = FFMAX(nmax, p->nmax);
437  min_diff = FFMIN(min_diff, p->min_diff);
438  max_diff = FFMAX(max_diff, p->max_diff);
439  diff1_sum += p->diff1_sum;
442  max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
443  sigma_x += p->sigma_x;
444  sigma_x2 += p->sigma_x2;
447  min_count += p->min_count;
448  max_count += p->max_count;
449  min_runs += p->min_runs;
450  max_runs += p->max_runs;
451  mask |= p->mask;
452  imask &= p->imask;
453  nb_samples += p->nb_samples;
454  nb_nans += p->nb_nans;
455  nb_infs += p->nb_infs;
457  if (fabs(p->sigma_x) > fabs(max_sigma_x))
458  max_sigma_x = p->sigma_x;
459 
461  set_meta(metadata, c + 1, "DC_offset", "%f", p->sigma_x / p->nb_samples);
463  set_meta(metadata, c + 1, "Min_level", "%f", p->min);
465  set_meta(metadata, c + 1, "Max_level", "%f", p->max);
467  set_meta(metadata, c + 1, "Min_difference", "%f", p->min_diff);
469  set_meta(metadata, c + 1, "Max_difference", "%f", p->max_diff);
471  set_meta(metadata, c + 1, "Mean_difference", "%f", p->diff1_sum / (p->nb_samples - 1));
473  set_meta(metadata, c + 1, "RMS_difference", "%f", sqrt(p->diff1_sum_x2 / (p->nb_samples - 1)));
475  set_meta(metadata, c + 1, "Peak_level", "%f", LINEAR_TO_DB(FFMAX(-p->nmin, p->nmax)));
477  set_meta(metadata, c + 1, "RMS_level", "%f", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples)));
479  set_meta(metadata, c + 1, "RMS_peak", "%f", LINEAR_TO_DB(sqrt(p->max_sigma_x2)));
481  set_meta(metadata, c + 1, "RMS_trough", "%f", LINEAR_TO_DB(sqrt(p->min_sigma_x2)));
483  set_meta(metadata, c + 1, "Crest_factor", "%f", p->sigma_x2 ? FFMAX(-p->min, p->max) / sqrt(p->sigma_x2 / p->nb_samples) : 1);
485  set_meta(metadata, c + 1, "Flat_factor", "%f", LINEAR_TO_DB((p->min_runs + p->max_runs) / (p->min_count + p->max_count)));
487  set_meta(metadata, c + 1, "Peak_count", "%f", (float)(p->min_count + p->max_count));
489  set_meta(metadata, c + 1, "Noise_floor", "%f", LINEAR_TO_DB(p->noise_floor));
491  set_meta(metadata, c + 1, "Noise_floor_count", "%f", p->noise_floor_count);
493  bit_depth(s, p->mask, p->imask, &depth);
494  set_meta(metadata, c + 1, "Bit_depth", "%f", depth.num);
495  set_meta(metadata, c + 1, "Bit_depth2", "%f", depth.den);
496  }
498  set_meta(metadata, c + 1, "Dynamic_range", "%f", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero));
500  set_meta(metadata, c + 1, "Zero_crossings", "%f", p->zero_runs);
502  set_meta(metadata, c + 1, "Zero_crossings_rate", "%f", p->zero_runs/(double)p->nb_samples);
504  set_meta(metadata, c + 1, "Number of NaNs", "%f", p->nb_nans);
506  set_meta(metadata, c + 1, "Number of Infs", "%f", p->nb_infs);
508  set_meta(metadata, c + 1, "Number of denormals", "%f", p->nb_denormals);
509  }
510 
512  set_meta(metadata, 0, "Overall.DC_offset", "%f", max_sigma_x / (nb_samples / s->nb_channels));
514  set_meta(metadata, 0, "Overall.Min_level", "%f", min);
516  set_meta(metadata, 0, "Overall.Max_level", "%f", max);
518  set_meta(metadata, 0, "Overall.Min_difference", "%f", min_diff);
520  set_meta(metadata, 0, "Overall.Max_difference", "%f", max_diff);
522  set_meta(metadata, 0, "Overall.Mean_difference", "%f", diff1_sum / (nb_samples - s->nb_channels));
524  set_meta(metadata, 0, "Overall.RMS_difference", "%f", sqrt(diff1_sum_x2 / (nb_samples - s->nb_channels)));
526  set_meta(metadata, 0, "Overall.Peak_level", "%f", LINEAR_TO_DB(FFMAX(-nmin, nmax)));
528  set_meta(metadata, 0, "Overall.RMS_level", "%f", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
530  set_meta(metadata, 0, "Overall.RMS_peak", "%f", LINEAR_TO_DB(sqrt(max_sigma_x2)));
532  set_meta(metadata, 0, "Overall.RMS_trough", "%f", LINEAR_TO_DB(sqrt(min_sigma_x2)));
534  set_meta(metadata, 0, "Overall.Flat_factor", "%f", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
536  set_meta(metadata, 0, "Overall.Peak_count", "%f", (float)(min_count + max_count) / (double)s->nb_channels);
538  set_meta(metadata, 0, "Overall.Noise_floor", "%f", LINEAR_TO_DB(noise_floor));
540  set_meta(metadata, 0, "Overall.Noise_floor_count", "%f", noise_floor_count / (double)s->nb_channels);
542  bit_depth(s, mask, imask, &depth);
543  set_meta(metadata, 0, "Overall.Bit_depth", "%f", depth.num);
544  set_meta(metadata, 0, "Overall.Bit_depth2", "%f", depth.den);
545  }
547  set_meta(metadata, 0, "Overall.Number_of_samples", "%f", nb_samples / s->nb_channels);
549  set_meta(metadata, 0, "Number of NaNs", "%f", nb_nans / (float)s->nb_channels);
551  set_meta(metadata, 0, "Number of Infs", "%f", nb_infs / (float)s->nb_channels);
553  set_meta(metadata, 0, "Number of denormals", "%f", nb_denormals / (float)s->nb_channels);
554 }
555 
556 #define UPDATE_STATS_P(type, update_func, update_float, channel_func) \
557  for (int c = start; c < end; c++) { \
558  ChannelStats *p = &s->chstats[c]; \
559  const type *src = (const type *)data[c]; \
560  const type * const srcend = src + samples; \
561  for (; src < srcend; src++) { \
562  update_func; \
563  update_float; \
564  } \
565  channel_func; \
566  }
567 
568 #define UPDATE_STATS_I(type, update_func, update_float, channel_func) \
569  for (int c = start; c < end; c++) { \
570  ChannelStats *p = &s->chstats[c]; \
571  const type *src = (const type *)data[0]; \
572  const type * const srcend = src + samples * channels; \
573  for (src += c; src < srcend; src += channels) { \
574  update_func; \
575  update_float; \
576  } \
577  channel_func; \
578  }
579 
580 #define UPDATE_STATS(planar, type, sample, normalizer_suffix, int_sample) \
581  if ((s->measure_overall | s->measure_perchannel) & ~MEASURE_MINMAXPEAK) { \
582  UPDATE_STATS_##planar(type, update_stat(s, p, sample, sample normalizer_suffix, int_sample), s->is_float ? update_float_stat(s, p, sample) : s->is_double ? update_double_stat(s, p, sample) : (void)NULL, ); \
583  } else { \
584  UPDATE_STATS_##planar(type, update_minmax(s, p, sample), , p->nmin = p->min normalizer_suffix; p->nmax = p->max normalizer_suffix;); \
585  }
586 
587 static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
588 {
589  AudioStatsContext *s = ctx->priv;
590  AVFilterLink *inlink = ctx->inputs[0];
591  AVFrame *buf = arg;
592  const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data;
593  const int channels = s->nb_channels;
594  const int samples = buf->nb_samples;
595  const int start = (buf->channels * jobnr) / nb_jobs;
596  const int end = (buf->channels * (jobnr+1)) / nb_jobs;
597 
598  switch (inlink->format) {
599  case AV_SAMPLE_FMT_DBLP:
600  UPDATE_STATS(P, double, *src, , llrint(*src * (UINT64_C(1) << 63)));
601  break;
602  case AV_SAMPLE_FMT_DBL:
603  UPDATE_STATS(I, double, *src, , llrint(*src * (UINT64_C(1) << 63)));
604  break;
605  case AV_SAMPLE_FMT_FLTP:
606  UPDATE_STATS(P, float, *src, , llrint(*src * (UINT64_C(1) << 31)));
607  break;
608  case AV_SAMPLE_FMT_FLT:
609  UPDATE_STATS(I, float, *src, , llrint(*src * (UINT64_C(1) << 31)));
610  break;
611  case AV_SAMPLE_FMT_S64P:
612  UPDATE_STATS(P, int64_t, *src, / (double)INT64_MAX, *src);
613  break;
614  case AV_SAMPLE_FMT_S64:
615  UPDATE_STATS(I, int64_t, *src, / (double)INT64_MAX, *src);
616  break;
617  case AV_SAMPLE_FMT_S32P:
618  UPDATE_STATS(P, int32_t, *src, / (double)INT32_MAX, *src);
619  break;
620  case AV_SAMPLE_FMT_S32:
621  UPDATE_STATS(I, int32_t, *src, / (double)INT32_MAX, *src);
622  break;
623  case AV_SAMPLE_FMT_S16P:
624  UPDATE_STATS(P, int16_t, *src, / (double)INT16_MAX, *src);
625  break;
626  case AV_SAMPLE_FMT_S16:
627  UPDATE_STATS(I, int16_t, *src, / (double)INT16_MAX, *src);
628  break;
629  }
630 
631  return 0;
632 }
633 
635 {
636  AVFilterContext *ctx = inlink->dst;
637  AudioStatsContext *s = ctx->priv;
638  AVDictionary **metadata = &buf->metadata;
639 
640  if (s->reset_count > 0) {
641  if (s->nb_frames >= s->reset_count) {
642  reset_stats(s);
643  s->nb_frames = 0;
644  }
645  s->nb_frames++;
646  }
647 
648  ctx->internal->execute(ctx, filter_channel, buf, NULL, FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
649 
650  if (s->metadata)
651  set_metadata(s, metadata);
652 
653  return ff_filter_frame(inlink->dst->outputs[0], buf);
654 }
655 
657 {
658  AudioStatsContext *s = ctx->priv;
659  uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0;
660  uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0;
661  double min_runs = 0, max_runs = 0,
662  min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0,
663  nmin = DBL_MAX, nmax =-DBL_MAX,
664  max_sigma_x = 0,
665  diff1_sum_x2 = 0,
666  diff1_sum = 0,
667  sigma_x = 0,
668  sigma_x2 = 0,
669  noise_floor = 0,
670  min_sigma_x2 = DBL_MAX,
671  max_sigma_x2 =-DBL_MAX;
672  AVRational depth;
673  int c;
674 
675  for (c = 0; c < s->nb_channels; c++) {
676  ChannelStats *p = &s->chstats[c];
677 
678  if (p->nb_samples < s->tc_samples)
679  p->min_sigma_x2 = p->max_sigma_x2 = p->sigma_x2 / p->nb_samples;
680 
681  min = FFMIN(min, p->min);
682  max = FFMAX(max, p->max);
683  nmin = FFMIN(nmin, p->nmin);
684  nmax = FFMAX(nmax, p->nmax);
685  min_diff = FFMIN(min_diff, p->min_diff);
686  max_diff = FFMAX(max_diff, p->max_diff);
688  diff1_sum += p->diff1_sum;
690  max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
691  sigma_x += p->sigma_x;
692  sigma_x2 += p->sigma_x2;
694  min_count += p->min_count;
695  max_count += p->max_count;
697  min_runs += p->min_runs;
698  max_runs += p->max_runs;
699  mask |= p->mask;
700  imask &= p->imask;
701  nb_samples += p->nb_samples;
702  nb_nans += p->nb_nans;
703  nb_infs += p->nb_infs;
705  if (fabs(p->sigma_x) > fabs(max_sigma_x))
706  max_sigma_x = p->sigma_x;
707 
708  av_log(ctx, AV_LOG_INFO, "Channel: %d\n", c + 1);
710  av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", p->sigma_x / p->nb_samples);
712  av_log(ctx, AV_LOG_INFO, "Min level: %f\n", p->min);
714  av_log(ctx, AV_LOG_INFO, "Max level: %f\n", p->max);
716  av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", p->min_diff);
718  av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", p->max_diff);
720  av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", p->diff1_sum / (p->nb_samples - 1));
722  av_log(ctx, AV_LOG_INFO, "RMS difference: %f\n", sqrt(p->diff1_sum_x2 / (p->nb_samples - 1)));
724  av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-p->nmin, p->nmax)));
726  av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples)));
728  av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(p->max_sigma_x2)));
730  if (p->min_sigma_x2 != 1)
731  av_log(ctx, AV_LOG_INFO, "RMS trough dB: %f\n",LINEAR_TO_DB(sqrt(p->min_sigma_x2)));
733  av_log(ctx, AV_LOG_INFO, "Crest factor: %f\n", p->sigma_x2 ? FFMAX(-p->nmin, p->nmax) / sqrt(p->sigma_x2 / p->nb_samples) : 1);
735  av_log(ctx, AV_LOG_INFO, "Flat factor: %f\n", LINEAR_TO_DB((p->min_runs + p->max_runs) / (p->min_count + p->max_count)));
737  av_log(ctx, AV_LOG_INFO, "Peak count: %"PRId64"\n", p->min_count + p->max_count);
739  av_log(ctx, AV_LOG_INFO, "Noise floor dB: %f\n", LINEAR_TO_DB(p->noise_floor));
741  av_log(ctx, AV_LOG_INFO, "Noise floor count: %"PRId64"\n", p->noise_floor_count);
743  bit_depth(s, p->mask, p->imask, &depth);
744  av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
745  }
747  av_log(ctx, AV_LOG_INFO, "Dynamic range: %f\n", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero));
749  av_log(ctx, AV_LOG_INFO, "Zero crossings: %"PRId64"\n", p->zero_runs);
751  av_log(ctx, AV_LOG_INFO, "Zero crossings rate: %f\n", p->zero_runs/(double)p->nb_samples);
753  av_log(ctx, AV_LOG_INFO, "Number of NaNs: %"PRId64"\n", p->nb_nans);
755  av_log(ctx, AV_LOG_INFO, "Number of Infs: %"PRId64"\n", p->nb_infs);
757  av_log(ctx, AV_LOG_INFO, "Number of denormals: %"PRId64"\n", p->nb_denormals);
758  }
759 
760  av_log(ctx, AV_LOG_INFO, "Overall\n");
762  av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", max_sigma_x / (nb_samples / s->nb_channels));
764  av_log(ctx, AV_LOG_INFO, "Min level: %f\n", min);
766  av_log(ctx, AV_LOG_INFO, "Max level: %f\n", max);
768  av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", min_diff);
770  av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", max_diff);
772  av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", diff1_sum / (nb_samples - s->nb_channels));
774  av_log(ctx, AV_LOG_INFO, "RMS difference: %f\n", sqrt(diff1_sum_x2 / (nb_samples - s->nb_channels)));
776  av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-nmin, nmax)));
778  av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
780  av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(max_sigma_x2)));
782  if (min_sigma_x2 != 1)
783  av_log(ctx, AV_LOG_INFO, "RMS trough dB: %f\n", LINEAR_TO_DB(sqrt(min_sigma_x2)));
785  av_log(ctx, AV_LOG_INFO, "Flat factor: %f\n", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
787  av_log(ctx, AV_LOG_INFO, "Peak count: %f\n", (min_count + max_count) / (double)s->nb_channels);
789  av_log(ctx, AV_LOG_INFO, "Noise floor dB: %f\n", LINEAR_TO_DB(noise_floor));
791  av_log(ctx, AV_LOG_INFO, "Noise floor count: %f\n", noise_floor_count / (double)s->nb_channels);
793  bit_depth(s, mask, imask, &depth);
794  av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
795  }
797  av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels);
799  av_log(ctx, AV_LOG_INFO, "Number of NaNs: %f\n", nb_nans / (float)s->nb_channels);
801  av_log(ctx, AV_LOG_INFO, "Number of Infs: %f\n", nb_infs / (float)s->nb_channels);
803  av_log(ctx, AV_LOG_INFO, "Number of denormals: %f\n", nb_denormals / (float)s->nb_channels);
804 }
805 
807 {
808  AudioStatsContext *s = ctx->priv;
809 
810  if (s->nb_channels)
811  print_stats(ctx);
812  if (s->chstats) {
813  for (int i = 0; i < s->nb_channels; i++) {
814  ChannelStats *p = &s->chstats[i];
815 
816  av_freep(&p->win_samples);
817  }
818  }
819  av_freep(&s->chstats);
820 }
821 
822 static const AVFilterPad astats_inputs[] = {
823  {
824  .name = "default",
825  .type = AVMEDIA_TYPE_AUDIO,
826  .filter_frame = filter_frame,
827  },
828  { NULL }
829 };
830 
831 static const AVFilterPad astats_outputs[] = {
832  {
833  .name = "default",
834  .type = AVMEDIA_TYPE_AUDIO,
835  .config_props = config_output,
836  },
837  { NULL }
838 };
839 
841  .name = "astats",
842  .description = NULL_IF_CONFIG_SMALL("Show time domain statistics about audio frames."),
843  .query_formats = query_formats,
844  .priv_size = sizeof(AudioStatsContext),
845  .priv_class = &astats_class,
846  .uninit = uninit,
847  .inputs = astats_inputs,
848  .outputs = astats_outputs,
850 };
float, planar
Definition: samplefmt.h:69
#define MEASURE_NUMBER_OF_INFS
Definition: af_astats.c:56
#define NULL
Definition: coverity.c:32
#define P
#define MEASURE_NONE
Definition: af_astats.c:34
#define MEASURE_DYNAMIC_RANGE
Definition: af_astats.c:51
#define MEASURE_RMS_PEAK
Definition: af_astats.c:45
double * win_samples
Definition: af_astats.c:84
This structure describes decoded (raw) audio or video data.
Definition: frame.h:308
AVOption.
Definition: opt.h:248
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
static int query_formats(AVFilterContext *ctx)
Definition: af_astats.c:148
#define HISTOGRAM_MAX
Definition: af_astats.c:31
AVFilter ff_af_astats
Definition: af_astats.c:840
Main libavfilter public API header.
#define OFFSET(x)
Definition: af_astats.c:108
double min_run
Definition: af_astats.c:71
#define MEASURE_MAX_DIFFERENCE
Definition: af_astats.c:40
double min
Definition: af_astats.c:69
int num
Numerator.
Definition: rational.h:59
#define MEASURE_RMS_DIFFERENCE
Definition: af_astats.c:42
#define MEASURE_NUMBER_OF_NANS
Definition: af_astats.c:55
double, planar
Definition: samplefmt.h:70
double max_sigma_x2
Definition: af_astats.c:68
GLint GLenum type
Definition: opengl_enc.c:104
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *channel_layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates...
Definition: formats.c:569
const char * key
static void update_minmax(AudioStatsContext *s, ChannelStats *p, double d)
Definition: af_astats.c:270
int max_index
Definition: af_astats.c:87
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:287
ChannelStats * chstats
Definition: af_astats.c:93
uint64_t nb_infs
Definition: af_astats.c:82
const char * name
Pad name.
Definition: internal.h:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:349
#define MEASURE_MEAN_DIFFERENCE
Definition: af_astats.c:41
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1091
#define MEASURE_NUMBER_OF_DENORMALS
Definition: af_astats.c:57
uint8_t
#define av_cold
Definition: attributes.h:88
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_astats.c:587
AVOptions.
#define MEASURE_RMS_LEVEL
Definition: af_astats.c:44
double nmin
Definition: af_astats.c:70
static const AVFilterPad astats_inputs[]
Definition: af_astats.c:822
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
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
#define LINEAR_TO_DB(x)
Definition: af_astats.c:407
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:108
double diff1_sum_x2
Definition: af_astats.c:75
static void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i)
Definition: af_astats.c:278
uint64_t noise_floor_count
Definition: af_astats.c:78
uint64_t nb_nans
Definition: af_astats.c:81
AVDictionary * metadata
metadata.
Definition: frame.h:594
#define MEASURE_PEAK_LEVEL
Definition: af_astats.c:43
channels
Definition: aptx.h:33
signed 32 bits
Definition: samplefmt.h:62
#define av_log(a,...)
#define MEASURE_PEAK_COUNT
Definition: af_astats.c:49
A filter pad used for either input or output.
Definition: internal.h:54
#define src
Definition: vp8dsp.c:254
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_astats.c:634
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_astats.c:806
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:588
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
void * priv
private data for use by the filter
Definition: avfilter.h:356
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#define MEASURE_NUMBER_OF_SAMPLES
Definition: af_astats.c:54
const char * arg
Definition: jacosubdec.c:66
#define MEASURE_BIT_DEPTH
Definition: af_astats.c:50
AVFILTER_DEFINE_CLASS(astats)
uint64_t tc_samples
Definition: af_astats.c:95
double max
Definition: af_astats.c:69
#define FFMAX(a, b)
Definition: common.h:94
int8_t exp
Definition: eval.c:72
double last_non_zero
Definition: af_astats.c:65
#define MEASURE_DC_OFFSET
Definition: af_astats.c:36
double noise_floor
Definition: af_astats.c:88
double sigma_x2
Definition: af_astats.c:67
#define MEASURE_ALL
Definition: af_astats.c:33
static void print_stats(AVFilterContext *ctx)
Definition: af_astats.c:656
#define UPDATE_STATS(planar, type, sample, normalizer_suffix, int_sample)
Definition: af_astats.c:580
int channels
number of audio channels, only used for audio.
Definition: frame.h:614
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:800
#define NAN
Definition: mathematics.h:64
#define FFMIN(a, b)
Definition: common.h:96
signed 32 bits, planar
Definition: samplefmt.h:68
double min_sigma_x2
Definition: af_astats.c:68
signed 64 bits
Definition: samplefmt.h:71
#define FFSIGN(a)
Definition: common.h:73
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:254
double max_runs
Definition: af_astats.c:72
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
static void update_float_stat(AudioStatsContext *s, ChannelStats *p, float d)
Definition: af_astats.c:375
static int config_output(AVFilterLink *outlink)
Definition: af_astats.c:221
static void reset_stats(AudioStatsContext *s)
Definition: af_astats.c:182
uint64_t max_count
Definition: af_astats.c:77
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define s(width, name)
Definition: cbs_vp9.c:257
#define MEASURE_ZERO_CROSSINGS_RATE
Definition: af_astats.c:53
double sigma_x
Definition: af_astats.c:67
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
double nmax
Definition: af_astats.c:70
A list of supported channel layouts.
Definition: formats.h:86
#define MEASURE_FLAT_FACTOR
Definition: af_astats.c:48
static const AVOption astats_options[]
Definition: af_astats.c:111
double min_diff
Definition: af_astats.c:73
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
uint64_t mask
Definition: af_astats.c:76
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
#define llrint(x)
Definition: libm.h:394
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
double avg_sigma_x2
Definition: af_astats.c:68
#define HISTOGRAM_SIZE
Definition: af_astats.c:30
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:145
int index
Definition: gxfenc.c:89
double max_run
Definition: af_astats.c:71
Rational number (pair of numerator and denominator).
Definition: rational.h:58
double max_diff
Definition: af_astats.c:73
#define isnan(x)
Definition: libm.h:340
double min_non_zero
Definition: af_astats.c:66
const char * name
Filter name.
Definition: avfilter.h:149
#define snprintf
Definition: snprintf.h:34
#define FLAGS
Definition: af_astats.c:109
double last
Definition: af_astats.c:64
uint64_t nb_denormals
Definition: af_astats.c:83
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:422
#define flags(name, subs,...)
Definition: cbs_av1.c:560
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:381
#define MEASURE_RMS_TROUGH
Definition: af_astats.c:46
#define MEASURE_NOISE_FLOOR
Definition: af_astats.c:58
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
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
unsigned histogram[HISTOGRAM_SIZE]
Definition: af_astats.c:85
double time_constant
Definition: af_astats.c:96
static void update_double_stat(AudioStatsContext *s, ChannelStats *p, double d)
Definition: af_astats.c:384
uint64_t nb_samples
Definition: af_astats.c:80
#define MEASURE_MIN_LEVEL
Definition: af_astats.c:37
signed 16 bits
Definition: samplefmt.h:61
static void set_meta(AVDictionary **metadata, int chan, const char *key, const char *fmt, double val)
Definition: af_astats.c:393
int den
Denominator.
Definition: rational.h:60
avfilter_execute_func * execute
Definition: internal.h:136
uint64_t min_count
Definition: af_astats.c:77
double min_runs
Definition: af_astats.c:72
double diff1_sum
Definition: af_astats.c:74
A list of supported formats for one end of a filter link.
Definition: formats.h:65
signed 64 bits, planar
Definition: samplefmt.h:72
An instance of a filter.
Definition: avfilter.h:341
and forward the result(frame or status change) to the corresponding input.If nothing is possible
static const AVFilterPad astats_outputs[]
Definition: af_astats.c:831
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:846
Filter the word “frame” indicates either a video frame or a group of audio samples
#define av_freep(p)
signed 16 bits, planar
Definition: samplefmt.h:67
#define MEASURE_CREST_FACTOR
Definition: af_astats.c:47
#define MEASURE_MAX_LEVEL
Definition: af_astats.c:38
formats
Definition: signature.h:48
#define MEASURE_ZERO_CROSSINGS
Definition: af_astats.c:52
internal API functions
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
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:437
#define MEASURE_MIN_DIFFERENCE
Definition: af_astats.c:39
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:355
#define MEASURE_NOISE_FLOOR_COUNT
Definition: af_astats.c:59
static double val(void *priv, double ch)
Definition: aeval.c:76
uint64_t imask
Definition: af_astats.c:76
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:374
uint64_t zero_runs
Definition: af_astats.c:79
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:576
static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
Definition: af_astats.c:409
int i
Definition: input.c:407