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 MEASURE_ALL UINT_MAX
31 #define MEASURE_NONE 0
32 
33 #define MEASURE_DC_OFFSET (1 << 0)
34 #define MEASURE_MIN_LEVEL (1 << 1)
35 #define MEASURE_MAX_LEVEL (1 << 2)
36 #define MEASURE_MIN_DIFFERENCE (1 << 3)
37 #define MEASURE_MAX_DIFFERENCE (1 << 4)
38 #define MEASURE_MEAN_DIFFERENCE (1 << 5)
39 #define MEASURE_RMS_DIFFERENCE (1 << 6)
40 #define MEASURE_PEAK_LEVEL (1 << 7)
41 #define MEASURE_RMS_LEVEL (1 << 8)
42 #define MEASURE_RMS_PEAK (1 << 9)
43 #define MEASURE_RMS_TROUGH (1 << 10)
44 #define MEASURE_CREST_FACTOR (1 << 11)
45 #define MEASURE_FLAT_FACTOR (1 << 12)
46 #define MEASURE_PEAK_COUNT (1 << 13)
47 #define MEASURE_BIT_DEPTH (1 << 14)
48 #define MEASURE_DYNAMIC_RANGE (1 << 15)
49 #define MEASURE_ZERO_CROSSINGS (1 << 16)
50 #define MEASURE_ZERO_CROSSINGS_RATE (1 << 17)
51 #define MEASURE_NUMBER_OF_SAMPLES (1 << 18)
52 #define MEASURE_NUMBER_OF_NANS (1 << 19)
53 #define MEASURE_NUMBER_OF_INFS (1 << 20)
54 #define MEASURE_NUMBER_OF_DENORMALS (1 << 21)
55 
56 #define MEASURE_MINMAXPEAK (MEASURE_MIN_LEVEL | MEASURE_MAX_LEVEL | MEASURE_PEAK_LEVEL)
57 
58 typedef struct ChannelStats {
59  double last;
60  double last_non_zero;
61  double min_non_zero;
62  double sigma_x, sigma_x2;
64  double min, max;
65  double nmin, nmax;
66  double min_run, max_run;
67  double min_runs, max_runs;
68  double min_diff, max_diff;
69  double diff1_sum;
70  double diff1_sum_x2;
71  uint64_t mask, imask;
72  uint64_t min_count, max_count;
73  uint64_t zero_runs;
74  uint64_t nb_samples;
75  uint64_t nb_nans;
76  uint64_t nb_infs;
77  uint64_t nb_denormals;
78 } ChannelStats;
79 
80 typedef struct AudioStatsContext {
81  const AVClass *class;
84  uint64_t tc_samples;
85  double time_constant;
86  double mult;
87  int metadata;
89  int nb_frames;
93  int is_float;
94  int is_double;
96 
97 #define OFFSET(x) offsetof(AudioStatsContext, x)
98 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
99 
100 static const AVOption astats_options[] = {
101  { "length", "set the window length", OFFSET(time_constant), AV_OPT_TYPE_DOUBLE, {.dbl=.05}, .01, 10, FLAGS },
102  { "metadata", "inject metadata in the filtergraph", OFFSET(metadata), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
103  { "reset", "recalculate stats after this many frames", OFFSET(reset_count), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
104  { "measure_perchannel", "only measure_perchannel these per-channel statistics", OFFSET(measure_perchannel), AV_OPT_TYPE_FLAGS, {.i64=MEASURE_ALL}, 0, UINT_MAX, FLAGS, "measure" },
105  { "none" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NONE }, 0, 0, FLAGS, "measure" },
106  { "all" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_ALL }, 0, 0, FLAGS, "measure" },
107  { "DC_offset" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_DC_OFFSET }, 0, 0, FLAGS, "measure" },
108  { "Min_level" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MIN_LEVEL }, 0, 0, FLAGS, "measure" },
109  { "Max_level" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MAX_LEVEL }, 0, 0, FLAGS, "measure" },
110  { "Min_difference" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MIN_DIFFERENCE }, 0, 0, FLAGS, "measure" },
111  { "Max_difference" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MAX_DIFFERENCE }, 0, 0, FLAGS, "measure" },
112  { "Mean_difference" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_MEAN_DIFFERENCE }, 0, 0, FLAGS, "measure" },
113  { "RMS_difference" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_RMS_DIFFERENCE }, 0, 0, FLAGS, "measure" },
114  { "Peak_level" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_PEAK_LEVEL }, 0, 0, FLAGS, "measure" },
115  { "RMS_level" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_RMS_LEVEL }, 0, 0, FLAGS, "measure" },
116  { "RMS_peak" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_RMS_PEAK }, 0, 0, FLAGS, "measure" },
117  { "RMS_trough" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_RMS_TROUGH }, 0, 0, FLAGS, "measure" },
118  { "Crest_factor" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_CREST_FACTOR }, 0, 0, FLAGS, "measure" },
119  { "Flat_factor" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_FLAT_FACTOR }, 0, 0, FLAGS, "measure" },
120  { "Peak_count" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_PEAK_COUNT }, 0, 0, FLAGS, "measure" },
121  { "Bit_depth" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_BIT_DEPTH }, 0, 0, FLAGS, "measure" },
122  { "Dynamic_range" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_DYNAMIC_RANGE }, 0, 0, FLAGS, "measure" },
123  { "Zero_crossings" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_ZERO_CROSSINGS }, 0, 0, FLAGS, "measure" },
124  { "Zero_crossings_rate" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_ZERO_CROSSINGS_RATE }, 0, 0, FLAGS, "measure" },
125  { "Number_of_samples" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_SAMPLES }, 0, 0, FLAGS, "measure" },
126  { "Number_of_NaNs" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_NANS }, 0, 0, FLAGS, "measure" },
127  { "Number_of_Infs" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_INFS }, 0, 0, FLAGS, "measure" },
128  { "Number_of_denormals" , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_DENORMALS }, 0, 0, FLAGS, "measure" },
129  { "measure_overall", "only measure_perchannel these overall statistics", OFFSET(measure_overall), AV_OPT_TYPE_FLAGS, {.i64=MEASURE_ALL}, 0, UINT_MAX, FLAGS, "measure" },
130  { NULL }
131 };
132 
133 AVFILTER_DEFINE_CLASS(astats);
134 
136 {
139  static const enum AVSampleFormat sample_fmts[] = {
146  };
147  int ret;
148 
150  if (!layouts)
151  return AVERROR(ENOMEM);
153  if (ret < 0)
154  return ret;
155 
157  if (!formats)
158  return AVERROR(ENOMEM);
160  if (ret < 0)
161  return ret;
162 
164  if (!formats)
165  return AVERROR(ENOMEM);
167 }
168 
170 {
171  int c;
172 
173  for (c = 0; c < s->nb_channels; c++) {
174  ChannelStats *p = &s->chstats[c];
175 
176  p->min = p->nmin = p->min_sigma_x2 = DBL_MAX;
177  p->max = p->nmax = p->max_sigma_x2 =-DBL_MAX;
178  p->min_non_zero = DBL_MAX;
179  p->min_diff = DBL_MAX;
180  p->max_diff = 0;
181  p->sigma_x = 0;
182  p->sigma_x2 = 0;
183  p->avg_sigma_x2 = 0;
184  p->min_run = 0;
185  p->max_run = 0;
186  p->min_runs = 0;
187  p->max_runs = 0;
188  p->diff1_sum = 0;
189  p->diff1_sum_x2 = 0;
190  p->mask = 0;
191  p->imask = 0xFFFFFFFFFFFFFFFF;
192  p->min_count = 0;
193  p->max_count = 0;
194  p->zero_runs = 0;
195  p->nb_samples = 0;
196  p->nb_nans = 0;
197  p->nb_infs = 0;
198  p->nb_denormals = 0;
199  p->last = NAN;
200  }
201 }
202 
203 static int config_output(AVFilterLink *outlink)
204 {
205  AudioStatsContext *s = outlink->src->priv;
206 
207  s->chstats = av_calloc(sizeof(*s->chstats), outlink->channels);
208  if (!s->chstats)
209  return AVERROR(ENOMEM);
210  s->nb_channels = outlink->channels;
211  s->mult = exp((-1 / s->time_constant / outlink->sample_rate));
212  s->tc_samples = 5 * s->time_constant * outlink->sample_rate + .5;
213  s->nb_frames = 0;
214  s->maxbitdepth = av_get_bytes_per_sample(outlink->format) * 8;
215  s->is_double = outlink->format == AV_SAMPLE_FMT_DBL ||
216  outlink->format == AV_SAMPLE_FMT_DBLP;
217 
218  s->is_float = outlink->format == AV_SAMPLE_FMT_FLT ||
219  outlink->format == AV_SAMPLE_FMT_FLTP;
220 
221  reset_stats(s);
222 
223  return 0;
224 }
225 
226 static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
227 {
228  unsigned result = s->maxbitdepth;
229 
230  mask = mask & (~imask);
231 
232  for (; result && !(mask & 1); --result, mask >>= 1);
233 
234  depth->den = result;
235  depth->num = 0;
236 
237  for (; result; --result, mask >>= 1)
238  if (mask & 1)
239  depth->num++;
240 }
241 
242 static inline void update_minmax(AudioStatsContext *s, ChannelStats *p, double d)
243 {
244  if (d < p->min)
245  p->min = d;
246  if (d > p->max)
247  p->max = d;
248 }
249 
250 static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i)
251 {
252  if (d < p->min) {
253  p->min = d;
254  p->nmin = nd;
255  p->min_run = 1;
256  p->min_runs = 0;
257  p->min_count = 1;
258  } else if (d == p->min) {
259  p->min_count++;
260  p->min_run = d == p->last ? p->min_run + 1 : 1;
261  } else if (p->last == p->min) {
262  p->min_runs += p->min_run * p->min_run;
263  }
264 
265  if (d != 0 && FFABS(d) < p->min_non_zero)
266  p->min_non_zero = FFABS(d);
267 
268  if (d > p->max) {
269  p->max = d;
270  p->nmax = nd;
271  p->max_run = 1;
272  p->max_runs = 0;
273  p->max_count = 1;
274  } else if (d == p->max) {
275  p->max_count++;
276  p->max_run = d == p->last ? p->max_run + 1 : 1;
277  } else if (p->last == p->max) {
278  p->max_runs += p->max_run * p->max_run;
279  }
280 
281  if (d != 0) {
282  p->zero_runs += FFSIGN(d) != FFSIGN(p->last_non_zero);
283  p->last_non_zero = d;
284  }
285 
286  p->sigma_x += nd;
287  p->sigma_x2 += nd * nd;
288  p->avg_sigma_x2 = p->avg_sigma_x2 * s->mult + (1.0 - s->mult) * nd * nd;
289  if (!isnan(p->last)) {
290  p->min_diff = FFMIN(p->min_diff, fabs(d - p->last));
291  p->max_diff = FFMAX(p->max_diff, fabs(d - p->last));
292  p->diff1_sum += fabs(d - p->last);
293  p->diff1_sum_x2 += (d - p->last) * (d - p->last);
294  }
295  p->last = d;
296  p->mask |= i;
297  p->imask &= i;
298 
299  if (p->nb_samples >= s->tc_samples) {
302  }
303  p->nb_samples++;
304 }
305 
306 static inline void update_float_stat(AudioStatsContext *s, ChannelStats *p, float d)
307 {
308  int type = fpclassify(d);
309 
310  p->nb_nans += type == FP_NAN;
311  p->nb_infs += type == FP_INFINITE;
312  p->nb_denormals += type == FP_SUBNORMAL;
313 }
314 
315 static inline void update_double_stat(AudioStatsContext *s, ChannelStats *p, double d)
316 {
317  int type = fpclassify(d);
318 
319  p->nb_nans += type == FP_NAN;
320  p->nb_infs += type == FP_INFINITE;
321  p->nb_denormals += type == FP_SUBNORMAL;
322 }
323 
324 static void set_meta(AVDictionary **metadata, int chan, const char *key,
325  const char *fmt, double val)
326 {
327  uint8_t value[128];
328  uint8_t key2[128];
329 
330  snprintf(value, sizeof(value), fmt, val);
331  if (chan)
332  snprintf(key2, sizeof(key2), "lavfi.astats.%d.%s", chan, key);
333  else
334  snprintf(key2, sizeof(key2), "lavfi.astats.%s", key);
335  av_dict_set(metadata, key2, value, 0);
336 }
337 
338 #define LINEAR_TO_DB(x) (log10(x) * 20)
339 
340 static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
341 {
342  uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0;
343  uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0;
344  double min_runs = 0, max_runs = 0,
345  min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0,
346  nmin = DBL_MAX, nmax =-DBL_MAX,
347  max_sigma_x = 0,
348  diff1_sum = 0,
349  diff1_sum_x2 = 0,
350  sigma_x = 0,
351  sigma_x2 = 0,
352  min_sigma_x2 = DBL_MAX,
353  max_sigma_x2 =-DBL_MAX;
354  AVRational depth;
355  int c;
356 
357  for (c = 0; c < s->nb_channels; c++) {
358  ChannelStats *p = &s->chstats[c];
359 
360  if (p->nb_samples < s->tc_samples)
361  p->min_sigma_x2 = p->max_sigma_x2 = p->sigma_x2 / p->nb_samples;
362 
363  min = FFMIN(min, p->min);
364  max = FFMAX(max, p->max);
365  nmin = FFMIN(nmin, p->nmin);
366  nmax = FFMAX(nmax, p->nmax);
367  min_diff = FFMIN(min_diff, p->min_diff);
368  max_diff = FFMAX(max_diff, p->max_diff);
369  diff1_sum += p->diff1_sum;
370  diff1_sum_x2 += p->diff1_sum_x2;
371  min_sigma_x2 = FFMIN(min_sigma_x2, p->min_sigma_x2);
372  max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
373  sigma_x += p->sigma_x;
374  sigma_x2 += p->sigma_x2;
375  min_count += p->min_count;
376  max_count += p->max_count;
377  min_runs += p->min_runs;
378  max_runs += p->max_runs;
379  mask |= p->mask;
380  imask &= p->imask;
381  nb_samples += p->nb_samples;
382  nb_nans += p->nb_nans;
383  nb_infs += p->nb_infs;
384  nb_denormals += p->nb_denormals;
385  if (fabs(p->sigma_x) > fabs(max_sigma_x))
386  max_sigma_x = p->sigma_x;
387 
388  if (s->measure_perchannel & MEASURE_DC_OFFSET)
389  set_meta(metadata, c + 1, "DC_offset", "%f", p->sigma_x / p->nb_samples);
390  if (s->measure_perchannel & MEASURE_MIN_LEVEL)
391  set_meta(metadata, c + 1, "Min_level", "%f", p->min);
392  if (s->measure_perchannel & MEASURE_MAX_LEVEL)
393  set_meta(metadata, c + 1, "Max_level", "%f", p->max);
394  if (s->measure_perchannel & MEASURE_MIN_DIFFERENCE)
395  set_meta(metadata, c + 1, "Min_difference", "%f", p->min_diff);
396  if (s->measure_perchannel & MEASURE_MAX_DIFFERENCE)
397  set_meta(metadata, c + 1, "Max_difference", "%f", p->max_diff);
398  if (s->measure_perchannel & MEASURE_MEAN_DIFFERENCE)
399  set_meta(metadata, c + 1, "Mean_difference", "%f", p->diff1_sum / (p->nb_samples - 1));
400  if (s->measure_perchannel & MEASURE_RMS_DIFFERENCE)
401  set_meta(metadata, c + 1, "RMS_difference", "%f", sqrt(p->diff1_sum_x2 / (p->nb_samples - 1)));
402  if (s->measure_perchannel & MEASURE_PEAK_LEVEL)
403  set_meta(metadata, c + 1, "Peak_level", "%f", LINEAR_TO_DB(FFMAX(-p->nmin, p->nmax)));
404  if (s->measure_perchannel & MEASURE_RMS_LEVEL)
405  set_meta(metadata, c + 1, "RMS_level", "%f", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples)));
406  if (s->measure_perchannel & MEASURE_RMS_PEAK)
407  set_meta(metadata, c + 1, "RMS_peak", "%f", LINEAR_TO_DB(sqrt(p->max_sigma_x2)));
408  if (s->measure_perchannel & MEASURE_RMS_TROUGH)
409  set_meta(metadata, c + 1, "RMS_trough", "%f", LINEAR_TO_DB(sqrt(p->min_sigma_x2)));
410  if (s->measure_perchannel & MEASURE_CREST_FACTOR)
411  set_meta(metadata, c + 1, "Crest_factor", "%f", p->sigma_x2 ? FFMAX(-p->min, p->max) / sqrt(p->sigma_x2 / p->nb_samples) : 1);
412  if (s->measure_perchannel & MEASURE_FLAT_FACTOR)
413  set_meta(metadata, c + 1, "Flat_factor", "%f", LINEAR_TO_DB((p->min_runs + p->max_runs) / (p->min_count + p->max_count)));
414  if (s->measure_perchannel & MEASURE_PEAK_COUNT)
415  set_meta(metadata, c + 1, "Peak_count", "%f", (float)(p->min_count + p->max_count));
416  if (s->measure_perchannel & MEASURE_BIT_DEPTH) {
417  bit_depth(s, p->mask, p->imask, &depth);
418  set_meta(metadata, c + 1, "Bit_depth", "%f", depth.num);
419  set_meta(metadata, c + 1, "Bit_depth2", "%f", depth.den);
420  }
421  if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE)
422  set_meta(metadata, c + 1, "Dynamic_range", "%f", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero));
423  if (s->measure_perchannel & MEASURE_ZERO_CROSSINGS)
424  set_meta(metadata, c + 1, "Zero_crossings", "%f", p->zero_runs);
425  if (s->measure_perchannel & MEASURE_ZERO_CROSSINGS_RATE)
426  set_meta(metadata, c + 1, "Zero_crossings_rate", "%f", p->zero_runs/(double)p->nb_samples);
427  if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_NANS)
428  set_meta(metadata, c + 1, "Number of NaNs", "%f", p->nb_nans);
429  if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_INFS)
430  set_meta(metadata, c + 1, "Number of Infs", "%f", p->nb_infs);
431  if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_DENORMALS)
432  set_meta(metadata, c + 1, "Number of denormals", "%f", p->nb_denormals);
433  }
434 
435  if (s->measure_overall & MEASURE_DC_OFFSET)
436  set_meta(metadata, 0, "Overall.DC_offset", "%f", max_sigma_x / (nb_samples / s->nb_channels));
437  if (s->measure_overall & MEASURE_MIN_LEVEL)
438  set_meta(metadata, 0, "Overall.Min_level", "%f", min);
439  if (s->measure_overall & MEASURE_MAX_LEVEL)
440  set_meta(metadata, 0, "Overall.Max_level", "%f", max);
441  if (s->measure_overall & MEASURE_MIN_DIFFERENCE)
442  set_meta(metadata, 0, "Overall.Min_difference", "%f", min_diff);
443  if (s->measure_overall & MEASURE_MAX_DIFFERENCE)
444  set_meta(metadata, 0, "Overall.Max_difference", "%f", max_diff);
445  if (s->measure_overall & MEASURE_MEAN_DIFFERENCE)
446  set_meta(metadata, 0, "Overall.Mean_difference", "%f", diff1_sum / (nb_samples - s->nb_channels));
447  if (s->measure_overall & MEASURE_RMS_DIFFERENCE)
448  set_meta(metadata, 0, "Overall.RMS_difference", "%f", sqrt(diff1_sum_x2 / (nb_samples - s->nb_channels)));
449  if (s->measure_overall & MEASURE_PEAK_LEVEL)
450  set_meta(metadata, 0, "Overall.Peak_level", "%f", LINEAR_TO_DB(FFMAX(-nmin, nmax)));
451  if (s->measure_overall & MEASURE_RMS_LEVEL)
452  set_meta(metadata, 0, "Overall.RMS_level", "%f", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
453  if (s->measure_overall & MEASURE_RMS_PEAK)
454  set_meta(metadata, 0, "Overall.RMS_peak", "%f", LINEAR_TO_DB(sqrt(max_sigma_x2)));
455  if (s->measure_overall & MEASURE_RMS_TROUGH)
456  set_meta(metadata, 0, "Overall.RMS_trough", "%f", LINEAR_TO_DB(sqrt(min_sigma_x2)));
457  if (s->measure_overall & MEASURE_FLAT_FACTOR)
458  set_meta(metadata, 0, "Overall.Flat_factor", "%f", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
459  if (s->measure_overall & MEASURE_PEAK_COUNT)
460  set_meta(metadata, 0, "Overall.Peak_count", "%f", (float)(min_count + max_count) / (double)s->nb_channels);
461  if (s->measure_overall & MEASURE_BIT_DEPTH) {
462  bit_depth(s, mask, imask, &depth);
463  set_meta(metadata, 0, "Overall.Bit_depth", "%f", depth.num);
464  set_meta(metadata, 0, "Overall.Bit_depth2", "%f", depth.den);
465  }
466  if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES)
467  set_meta(metadata, 0, "Overall.Number_of_samples", "%f", nb_samples / s->nb_channels);
468  if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_NANS)
469  set_meta(metadata, 0, "Number of NaNs", "%f", nb_nans / (float)s->nb_channels);
470  if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_INFS)
471  set_meta(metadata, 0, "Number of Infs", "%f", nb_infs / (float)s->nb_channels);
472  if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_DENORMALS)
473  set_meta(metadata, 0, "Number of denormals", "%f", nb_denormals / (float)s->nb_channels);
474 }
475 
476 #define UPDATE_STATS_P(type, update_func, update_float, channel_func) \
477  for (int c = 0; c < channels; c++) { \
478  ChannelStats *p = &s->chstats[c]; \
479  const type *src = (const type *)data[c]; \
480  const type * const srcend = src + samples; \
481  for (; src < srcend; src++) { \
482  update_func; \
483  update_float; \
484  } \
485  channel_func; \
486  }
487 
488 #define UPDATE_STATS_I(type, update_func, update_float, channel_func) \
489  for (int c = 0; c < channels; c++) { \
490  ChannelStats *p = &s->chstats[c]; \
491  const type *src = (const type *)data[0]; \
492  const type * const srcend = src + samples * channels; \
493  for (src += c; src < srcend; src += channels) { \
494  update_func; \
495  update_float; \
496  } \
497  channel_func; \
498  }
499 
500 #define UPDATE_STATS(planar, type, sample, normalizer_suffix, int_sample) \
501  if ((s->measure_overall | s->measure_perchannel) & ~MEASURE_MINMAXPEAK) { \
502  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, ); \
503  } else { \
504  UPDATE_STATS_##planar(type, update_minmax(s, p, sample), , p->nmin = p->min normalizer_suffix; p->nmax = p->max normalizer_suffix;); \
505  }
506 
508 {
509  AudioStatsContext *s = inlink->dst->priv;
510  AVDictionary **metadata = &buf->metadata;
511  const int channels = s->nb_channels;
512  const int samples = buf->nb_samples;
513  const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data;
514 
515  if (s->reset_count > 0) {
516  if (s->nb_frames >= s->reset_count) {
517  reset_stats(s);
518  s->nb_frames = 0;
519  }
520  s->nb_frames++;
521  }
522 
523  switch (inlink->format) {
524  case AV_SAMPLE_FMT_DBLP:
525  UPDATE_STATS(P, double, *src, , llrint(*src * (UINT64_C(1) << 63)));
526  break;
527  case AV_SAMPLE_FMT_DBL:
528  UPDATE_STATS(I, double, *src, , llrint(*src * (UINT64_C(1) << 63)));
529  break;
530  case AV_SAMPLE_FMT_FLTP:
531  UPDATE_STATS(P, float, *src, , llrint(*src * (UINT64_C(1) << 31)));
532  break;
533  case AV_SAMPLE_FMT_FLT:
534  UPDATE_STATS(I, float, *src, , llrint(*src * (UINT64_C(1) << 31)));
535  break;
536  case AV_SAMPLE_FMT_S64P:
537  UPDATE_STATS(P, int64_t, *src, / (double)INT64_MAX, *src);
538  break;
539  case AV_SAMPLE_FMT_S64:
540  UPDATE_STATS(I, int64_t, *src, / (double)INT64_MAX, *src);
541  break;
542  case AV_SAMPLE_FMT_S32P:
543  UPDATE_STATS(P, int32_t, *src, / (double)INT32_MAX, *src);
544  break;
545  case AV_SAMPLE_FMT_S32:
546  UPDATE_STATS(I, int32_t, *src, / (double)INT32_MAX, *src);
547  break;
548  case AV_SAMPLE_FMT_S16P:
549  UPDATE_STATS(P, int16_t, *src, / (double)INT16_MAX, *src);
550  break;
551  case AV_SAMPLE_FMT_S16:
552  UPDATE_STATS(I, int16_t, *src, / (double)INT16_MAX, *src);
553  break;
554  }
555 
556  if (s->metadata)
557  set_metadata(s, metadata);
558 
559  return ff_filter_frame(inlink->dst->outputs[0], buf);
560 }
561 
563 {
564  AudioStatsContext *s = ctx->priv;
565  uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0;
566  uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0;
567  double min_runs = 0, max_runs = 0,
568  min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0,
569  nmin = DBL_MAX, nmax =-DBL_MAX,
570  max_sigma_x = 0,
571  diff1_sum_x2 = 0,
572  diff1_sum = 0,
573  sigma_x = 0,
574  sigma_x2 = 0,
575  min_sigma_x2 = DBL_MAX,
576  max_sigma_x2 =-DBL_MAX;
577  AVRational depth;
578  int c;
579 
580  for (c = 0; c < s->nb_channels; c++) {
581  ChannelStats *p = &s->chstats[c];
582 
583  if (p->nb_samples < s->tc_samples)
584  p->min_sigma_x2 = p->max_sigma_x2 = p->sigma_x2 / p->nb_samples;
585 
586  min = FFMIN(min, p->min);
587  max = FFMAX(max, p->max);
588  nmin = FFMIN(nmin, p->nmin);
589  nmax = FFMAX(nmax, p->nmax);
590  min_diff = FFMIN(min_diff, p->min_diff);
591  max_diff = FFMAX(max_diff, p->max_diff);
592  diff1_sum_x2 += p->diff1_sum_x2;
593  diff1_sum += p->diff1_sum;
594  min_sigma_x2 = FFMIN(min_sigma_x2, p->min_sigma_x2);
595  max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
596  sigma_x += p->sigma_x;
597  sigma_x2 += p->sigma_x2;
598  min_count += p->min_count;
599  max_count += p->max_count;
600  min_runs += p->min_runs;
601  max_runs += p->max_runs;
602  mask |= p->mask;
603  imask &= p->imask;
604  nb_samples += p->nb_samples;
605  nb_nans += p->nb_nans;
606  nb_infs += p->nb_infs;
607  nb_denormals += p->nb_denormals;
608  if (fabs(p->sigma_x) > fabs(max_sigma_x))
609  max_sigma_x = p->sigma_x;
610 
611  av_log(ctx, AV_LOG_INFO, "Channel: %d\n", c + 1);
612  if (s->measure_perchannel & MEASURE_DC_OFFSET)
613  av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", p->sigma_x / p->nb_samples);
614  if (s->measure_perchannel & MEASURE_MIN_LEVEL)
615  av_log(ctx, AV_LOG_INFO, "Min level: %f\n", p->min);
616  if (s->measure_perchannel & MEASURE_MAX_LEVEL)
617  av_log(ctx, AV_LOG_INFO, "Max level: %f\n", p->max);
618  if (s->measure_perchannel & MEASURE_MIN_DIFFERENCE)
619  av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", p->min_diff);
620  if (s->measure_perchannel & MEASURE_MAX_DIFFERENCE)
621  av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", p->max_diff);
622  if (s->measure_perchannel & MEASURE_MEAN_DIFFERENCE)
623  av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", p->diff1_sum / (p->nb_samples - 1));
624  if (s->measure_perchannel & MEASURE_RMS_DIFFERENCE)
625  av_log(ctx, AV_LOG_INFO, "RMS difference: %f\n", sqrt(p->diff1_sum_x2 / (p->nb_samples - 1)));
626  if (s->measure_perchannel & MEASURE_PEAK_LEVEL)
627  av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-p->nmin, p->nmax)));
628  if (s->measure_perchannel & MEASURE_RMS_LEVEL)
629  av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples)));
630  if (s->measure_perchannel & MEASURE_RMS_PEAK)
631  av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(p->max_sigma_x2)));
632  if (s->measure_perchannel & MEASURE_RMS_TROUGH)
633  if (p->min_sigma_x2 != 1)
634  av_log(ctx, AV_LOG_INFO, "RMS trough dB: %f\n",LINEAR_TO_DB(sqrt(p->min_sigma_x2)));
635  if (s->measure_perchannel & MEASURE_CREST_FACTOR)
636  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);
637  if (s->measure_perchannel & MEASURE_FLAT_FACTOR)
638  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)));
639  if (s->measure_perchannel & MEASURE_PEAK_COUNT)
640  av_log(ctx, AV_LOG_INFO, "Peak count: %"PRId64"\n", p->min_count + p->max_count);
641  if (s->measure_perchannel & MEASURE_BIT_DEPTH) {
642  bit_depth(s, p->mask, p->imask, &depth);
643  av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
644  }
645  if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE)
646  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));
647  if (s->measure_perchannel & MEASURE_ZERO_CROSSINGS)
648  av_log(ctx, AV_LOG_INFO, "Zero crossings: %"PRId64"\n", p->zero_runs);
649  if (s->measure_perchannel & MEASURE_ZERO_CROSSINGS_RATE)
650  av_log(ctx, AV_LOG_INFO, "Zero crossings rate: %f\n", p->zero_runs/(double)p->nb_samples);
651  if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_NANS)
652  av_log(ctx, AV_LOG_INFO, "Number of NaNs: %"PRId64"\n", p->nb_nans);
653  if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_INFS)
654  av_log(ctx, AV_LOG_INFO, "Number of Infs: %"PRId64"\n", p->nb_infs);
655  if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_DENORMALS)
656  av_log(ctx, AV_LOG_INFO, "Number of denormals: %"PRId64"\n", p->nb_denormals);
657  }
658 
659  av_log(ctx, AV_LOG_INFO, "Overall\n");
660  if (s->measure_overall & MEASURE_DC_OFFSET)
661  av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", max_sigma_x / (nb_samples / s->nb_channels));
662  if (s->measure_overall & MEASURE_MIN_LEVEL)
663  av_log(ctx, AV_LOG_INFO, "Min level: %f\n", min);
664  if (s->measure_overall & MEASURE_MAX_LEVEL)
665  av_log(ctx, AV_LOG_INFO, "Max level: %f\n", max);
666  if (s->measure_overall & MEASURE_MIN_DIFFERENCE)
667  av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", min_diff);
668  if (s->measure_overall & MEASURE_MAX_DIFFERENCE)
669  av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", max_diff);
670  if (s->measure_overall & MEASURE_MEAN_DIFFERENCE)
671  av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", diff1_sum / (nb_samples - s->nb_channels));
672  if (s->measure_overall & MEASURE_RMS_DIFFERENCE)
673  av_log(ctx, AV_LOG_INFO, "RMS difference: %f\n", sqrt(diff1_sum_x2 / (nb_samples - s->nb_channels)));
674  if (s->measure_overall & MEASURE_PEAK_LEVEL)
675  av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-nmin, nmax)));
676  if (s->measure_overall & MEASURE_RMS_LEVEL)
677  av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
678  if (s->measure_overall & MEASURE_RMS_PEAK)
679  av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(max_sigma_x2)));
680  if (s->measure_overall & MEASURE_RMS_TROUGH)
681  if (min_sigma_x2 != 1)
682  av_log(ctx, AV_LOG_INFO, "RMS trough dB: %f\n", LINEAR_TO_DB(sqrt(min_sigma_x2)));
683  if (s->measure_overall & MEASURE_FLAT_FACTOR)
684  av_log(ctx, AV_LOG_INFO, "Flat factor: %f\n", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
685  if (s->measure_overall & MEASURE_PEAK_COUNT)
686  av_log(ctx, AV_LOG_INFO, "Peak count: %f\n", (min_count + max_count) / (double)s->nb_channels);
687  if (s->measure_overall & MEASURE_BIT_DEPTH) {
688  bit_depth(s, mask, imask, &depth);
689  av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
690  }
691  if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES)
692  av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels);
693  if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_NANS)
694  av_log(ctx, AV_LOG_INFO, "Number of NaNs: %f\n", nb_nans / (float)s->nb_channels);
695  if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_INFS)
696  av_log(ctx, AV_LOG_INFO, "Number of Infs: %f\n", nb_infs / (float)s->nb_channels);
697  if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_DENORMALS)
698  av_log(ctx, AV_LOG_INFO, "Number of denormals: %f\n", nb_denormals / (float)s->nb_channels);
699 }
700 
702 {
703  AudioStatsContext *s = ctx->priv;
704 
705  if (s->nb_channels)
706  print_stats(ctx);
707  av_freep(&s->chstats);
708 }
709 
710 static const AVFilterPad astats_inputs[] = {
711  {
712  .name = "default",
713  .type = AVMEDIA_TYPE_AUDIO,
714  .filter_frame = filter_frame,
715  },
716  { NULL }
717 };
718 
719 static const AVFilterPad astats_outputs[] = {
720  {
721  .name = "default",
722  .type = AVMEDIA_TYPE_AUDIO,
723  .config_props = config_output,
724  },
725  { NULL }
726 };
727 
729  .name = "astats",
730  .description = NULL_IF_CONFIG_SMALL("Show time domain statistics about audio frames."),
731  .query_formats = query_formats,
732  .priv_size = sizeof(AudioStatsContext),
733  .priv_class = &astats_class,
734  .uninit = uninit,
737 };
formats
formats
Definition: signature.h:48
ChannelStats::nmax
double nmax
Definition: af_astats.c:65
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
bit_depth
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:226
AudioStatsContext::nb_channels
int nb_channels
Definition: af_astats.c:83
set_meta
static void set_meta(AVDictionary **metadata, int chan, const char *key, const char *fmt, double val)
Definition: af_astats.c:324
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:283
MEASURE_PEAK_COUNT
#define MEASURE_PEAK_COUNT
Definition: af_astats.c:46
AudioStatsContext::is_double
int is_double
Definition: af_astats.c:94
ff_set_common_channel_layouts
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.
Definition: formats.c:549
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:686
astats_options
static const AVOption astats_options[]
Definition: af_astats.c:100
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AudioStatsContext::maxbitdepth
int maxbitdepth
Definition: af_astats.c:90
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
MEASURE_RMS_TROUGH
#define MEASURE_RMS_TROUGH
Definition: af_astats.c:43
MEASURE_MIN_LEVEL
#define MEASURE_MIN_LEVEL
Definition: af_astats.c:34
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:410
ChannelStats::diff1_sum
double diff1_sum
Definition: af_astats.c:69
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
MEASURE_ALL
#define MEASURE_ALL
Definition: af_astats.c:30
MEASURE_NONE
#define MEASURE_NONE
Definition: af_astats.c:31
AudioStatsContext::is_float
int is_float
Definition: af_astats.c:93
AVOption
AVOption.
Definition: opt.h:246
ChannelStats::diff1_sum_x2
double diff1_sum_x2
Definition: af_astats.c:70
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:68
data
const char data[16]
Definition: mxf.c:91
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_astats.c:203
AudioStatsContext::tc_samples
uint64_t tc_samples
Definition: af_astats.c:84
float.h
channels
channels
Definition: aptx.c:30
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVDictionary
Definition: dict.c:30
ff_af_astats
AVFilter ff_af_astats
Definition: af_astats.c:728
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
ChannelStats::max_sigma_x2
double max_sigma_x2
Definition: af_astats.c:63
reset_stats
static void reset_stats(AudioStatsContext *s)
Definition: af_astats.c:169
ChannelStats::last_non_zero
double last_non_zero
Definition: af_astats.c:60
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
update_stat
static void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i)
Definition: af_astats.c:250
fmt
const char * fmt
Definition: avisynth_c.h:861
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:353
FFSIGN
#define FFSIGN(a)
Definition: common.h:73
ChannelStats::nb_nans
uint64_t nb_nans
Definition: af_astats.c:75
update_minmax
static void update_minmax(AudioStatsContext *s, ChannelStats *p, double d)
Definition: af_astats.c:242
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_SAMPLE_FMT_S64P
@ AV_SAMPLE_FMT_S64P
signed 64 bits, planar
Definition: samplefmt.h:72
OFFSET
#define OFFSET(x)
Definition: af_astats.c:97
ChannelStats::avg_sigma_x2
double avg_sigma_x2
Definition: af_astats.c:63
AVRational::num
int num
Numerator.
Definition: rational.h:59
src
#define src
Definition: vp8dsp.c:254
ChannelStats::mask
uint64_t mask
Definition: af_astats.c:71
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
ChannelStats::nmin
double nmin
Definition: af_astats.c:65
LINEAR_TO_DB
#define LINEAR_TO_DB(x)
Definition: af_astats.c:338
buf
void * buf
Definition: avisynth_c.h:766
av_cold
#define av_cold
Definition: attributes.h:84
ff_set_common_formats
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:568
mask
static const uint16_t mask[17]
Definition: lzw.c:38
ChannelStats::last
double last
Definition: af_astats.c:59
AudioStatsContext::mult
double mult
Definition: af_astats.c:86
s
#define s(width, name)
Definition: cbs_vp9.c:257
AudioStatsContext::measure_overall
int measure_overall
Definition: af_astats.c:92
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:225
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_astats.c:507
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
ctx
AVFormatContext * ctx
Definition: movenc.c:48
UPDATE_STATS
#define UPDATE_STATS(planar, type, sample, normalizer_suffix, int_sample)
Definition: af_astats.c:500
ChannelStats::max
double max
Definition: af_astats.c:64
update_double_stat
static void update_double_stat(AudioStatsContext *s, ChannelStats *p, double d)
Definition: af_astats.c:315
update_float_stat
static void update_float_stat(AudioStatsContext *s, ChannelStats *p, float d)
Definition: af_astats.c:306
key
const char * key
Definition: hwcontext_opencl.c:168
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_astats.c:701
NAN
#define NAN
Definition: mathematics.h:64
ChannelStats::min_diff
double min_diff
Definition: af_astats.c:68
int32_t
int32_t
Definition: audio_convert.c:194
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
if
if(ret)
Definition: filter_design.txt:179
ChannelStats::min_count
uint64_t min_count
Definition: af_astats.c:72
MEASURE_RMS_DIFFERENCE
#define MEASURE_RMS_DIFFERENCE
Definition: af_astats.c:39
ChannelStats::sigma_x
double sigma_x
Definition: af_astats.c:62
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
NULL
#define NULL
Definition: coverity.c:32
MEASURE_ZERO_CROSSINGS_RATE
#define MEASURE_ZERO_CROSSINGS_RATE
Definition: af_astats.c:50
MEASURE_DC_OFFSET
#define MEASURE_DC_OFFSET
Definition: af_astats.c:33
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
isnan
#define isnan(x)
Definition: libm.h:340
ChannelStats::min_runs
double min_runs
Definition: af_astats.c:67
inputs
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
Definition: filter_design.txt:243
exp
int8_t exp
Definition: eval.c:72
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
FLAGS
#define FLAGS
Definition: af_astats.c:98
MEASURE_FLAT_FACTOR
#define MEASURE_FLAT_FACTOR
Definition: af_astats.c:45
AudioStatsContext::measure_perchannel
int measure_perchannel
Definition: af_astats.c:91
AudioStatsContext
Definition: af_astats.c:80
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:188
P
#define P
MEASURE_DYNAMIC_RANGE
#define MEASURE_DYNAMIC_RANGE
Definition: af_astats.c:48
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
ChannelStats::nb_samples
uint64_t nb_samples
Definition: af_astats.c:74
val
const char const char void * val
Definition: avisynth_c.h:863
MEASURE_NUMBER_OF_SAMPLES
#define MEASURE_NUMBER_OF_SAMPLES
Definition: af_astats.c:51
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
MEASURE_RMS_PEAK
#define MEASURE_RMS_PEAK
Definition: af_astats.c:42
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
internal.h
ChannelStats::max_diff
double max_diff
Definition: af_astats.c:68
astats_inputs
static const AVFilterPad astats_inputs[]
Definition: af_astats.c:710
ChannelStats::min_sigma_x2
double min_sigma_x2
Definition: af_astats.c:63
MEASURE_MEAN_DIFFERENCE
#define MEASURE_MEAN_DIFFERENCE
Definition: af_astats.c:38
ChannelStats
Definition: af_astats.c:58
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
MEASURE_NUMBER_OF_DENORMALS
#define MEASURE_NUMBER_OF_DENORMALS
Definition: af_astats.c:54
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
ChannelStats::min_run
double min_run
Definition: af_astats.c:66
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_astats.c:135
MEASURE_PEAK_LEVEL
#define MEASURE_PEAK_LEVEL
Definition: af_astats.c:40
uint8_t
uint8_t
Definition: audio_convert.c:194
ChannelStats::max_run
double max_run
Definition: af_astats.c:66
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
set_metadata
static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
Definition: af_astats.c:340
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
ChannelStats::max_runs
double max_runs
Definition: af_astats.c:67
AVFilter
Filter definition.
Definition: avfilter.h:144
MEASURE_RMS_LEVEL
#define MEASURE_RMS_LEVEL
Definition: af_astats.c:41
ret
ret
Definition: filter_design.txt:187
MEASURE_NUMBER_OF_NANS
#define MEASURE_NUMBER_OF_NANS
Definition: af_astats.c:52
MEASURE_BIT_DEPTH
#define MEASURE_BIT_DEPTH
Definition: af_astats.c:47
AudioStatsContext::nb_frames
int nb_frames
Definition: af_astats.c:89
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
AudioStatsContext::reset_count
int reset_count
Definition: af_astats.c:88
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
MEASURE_NUMBER_OF_INFS
#define MEASURE_NUMBER_OF_INFS
Definition: af_astats.c:53
audio.h
AudioStatsContext::metadata
int metadata
Definition: af_astats.c:87
llrint
#define llrint(x)
Definition: libm.h:394
ChannelStats::nb_denormals
uint64_t nb_denormals
Definition: af_astats.c:77
ChannelStats::sigma_x2
double sigma_x2
Definition: af_astats.c:62
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(astats)
print_stats
static void print_stats(AVFilterContext *ctx)
Definition: af_astats.c:562
MEASURE_MAX_LEVEL
#define MEASURE_MAX_LEVEL
Definition: af_astats.c:35
MEASURE_MIN_DIFFERENCE
#define MEASURE_MIN_DIFFERENCE
Definition: af_astats.c:36
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
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
AudioStatsContext::chstats
ChannelStats * chstats
Definition: af_astats.c:82
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:222
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ChannelStats::zero_runs
uint64_t zero_runs
Definition: af_astats.c:73
MEASURE_CREST_FACTOR
#define MEASURE_CREST_FACTOR
Definition: af_astats.c:44
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
ChannelStats::imask
uint64_t imask
Definition: af_astats.c:71
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:64
ChannelStats::min
double min
Definition: af_astats.c:64
AudioStatsContext::time_constant
double time_constant
Definition: af_astats.c:85
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:62
ChannelStats::max_count
uint64_t max_count
Definition: af_astats.c:72
ChannelStats::min_non_zero
double min_non_zero
Definition: af_astats.c:61
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
snprintf
#define snprintf
Definition: snprintf.h:34
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:63
MEASURE_MAX_DIFFERENCE
#define MEASURE_MAX_DIFFERENCE
Definition: af_astats.c:37
astats_outputs
static const AVFilterPad astats_outputs[]
Definition: af_astats.c:719
ChannelStats::nb_infs
uint64_t nb_infs
Definition: af_astats.c:76
AV_SAMPLE_FMT_S64
@ AV_SAMPLE_FMT_S64
signed 64 bits
Definition: samplefmt.h:71
MEASURE_ZERO_CROSSINGS
#define MEASURE_ZERO_CROSSINGS
Definition: af_astats.c:49
min
float min
Definition: vorbis_enc_data.h:456