summaryrefslogtreecommitdiff
path: root/libavfilter/af_astats.c (plain)
blob: e7f9675c2e027de6fd37802aab043b56410e2ba1
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
24#include "libavutil/opt.h"
25#include "audio.h"
26#include "avfilter.h"
27#include "internal.h"
28
29typedef struct ChannelStats {
30 double last;
31 double sigma_x, sigma_x2;
32 double avg_sigma_x2, min_sigma_x2, max_sigma_x2;
33 double min, max;
34 double nmin, nmax;
35 double min_run, max_run;
36 double min_runs, max_runs;
37 double min_diff, max_diff;
38 double diff1_sum;
39 uint64_t mask, imask;
40 uint64_t min_count, max_count;
41 uint64_t nb_samples;
42} ChannelStats;
43
44typedef struct {
45 const AVClass *class;
46 ChannelStats *chstats;
47 int nb_channels;
48 uint64_t tc_samples;
49 double time_constant;
50 double mult;
51 int metadata;
52 int reset_count;
53 int nb_frames;
54 int maxbitdepth;
55} AudioStatsContext;
56
57#define OFFSET(x) offsetof(AudioStatsContext, x)
58#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
59
60static const AVOption astats_options[] = {
61 { "length", "set the window length", OFFSET(time_constant), AV_OPT_TYPE_DOUBLE, {.dbl=.05}, .01, 10, FLAGS },
62 { "metadata", "inject metadata in the filtergraph", OFFSET(metadata), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
63 { "reset", "recalculate stats after this many frames", OFFSET(reset_count), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
64 { NULL }
65};
66
67AVFILTER_DEFINE_CLASS(astats);
68
69static int query_formats(AVFilterContext *ctx)
70{
71 AVFilterFormats *formats;
72 AVFilterChannelLayouts *layouts;
73 static const enum AVSampleFormat sample_fmts[] = {
74 AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
75 AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32P,
76 AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64P,
77 AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
78 AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBLP,
79 AV_SAMPLE_FMT_NONE
80 };
81 int ret;
82
83 layouts = ff_all_channel_counts();
84 if (!layouts)
85 return AVERROR(ENOMEM);
86 ret = ff_set_common_channel_layouts(ctx, layouts);
87 if (ret < 0)
88 return ret;
89
90 formats = ff_make_format_list(sample_fmts);
91 if (!formats)
92 return AVERROR(ENOMEM);
93 ret = ff_set_common_formats(ctx, formats);
94 if (ret < 0)
95 return ret;
96
97 formats = ff_all_samplerates();
98 if (!formats)
99 return AVERROR(ENOMEM);
100 return ff_set_common_samplerates(ctx, formats);
101}
102
103static void reset_stats(AudioStatsContext *s)
104{
105 int c;
106
107 for (c = 0; c < s->nb_channels; c++) {
108 ChannelStats *p = &s->chstats[c];
109
110 p->min = p->nmin = p->min_sigma_x2 = DBL_MAX;
111 p->max = p->nmax = p->max_sigma_x2 = DBL_MIN;
112 p->min_diff = DBL_MAX;
113 p->max_diff = DBL_MIN;
114 p->sigma_x = 0;
115 p->sigma_x2 = 0;
116 p->avg_sigma_x2 = 0;
117 p->min_sigma_x2 = 0;
118 p->max_sigma_x2 = 0;
119 p->min_run = 0;
120 p->max_run = 0;
121 p->min_runs = 0;
122 p->max_runs = 0;
123 p->diff1_sum = 0;
124 p->mask = 0;
125 p->imask = 0xFFFFFFFFFFFFFFFF;
126 p->min_count = 0;
127 p->max_count = 0;
128 p->nb_samples = 0;
129 }
130}
131
132static int config_output(AVFilterLink *outlink)
133{
134 AudioStatsContext *s = outlink->src->priv;
135
136 s->chstats = av_calloc(sizeof(*s->chstats), outlink->channels);
137 if (!s->chstats)
138 return AVERROR(ENOMEM);
139 s->nb_channels = outlink->channels;
140 s->mult = exp((-1 / s->time_constant / outlink->sample_rate));
141 s->tc_samples = 5 * s->time_constant * outlink->sample_rate + .5;
142 s->nb_frames = 0;
143 s->maxbitdepth = av_get_bytes_per_sample(outlink->format) * 8;
144
145 reset_stats(s);
146
147 return 0;
148}
149
150static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
151{
152 unsigned result = s->maxbitdepth;
153
154 mask = mask & (~imask);
155
156 for (; result && !(mask & 1); --result, mask >>= 1);
157
158 depth->den = result;
159 depth->num = 0;
160
161 for (; result; --result, mask >>= 1)
162 if (mask & 1)
163 depth->num++;
164}
165
166static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i)
167{
168 if (d < p->min) {
169 p->min = d;
170 p->nmin = nd;
171 p->min_run = 1;
172 p->min_runs = 0;
173 p->min_count = 1;
174 } else if (d == p->min) {
175 p->min_count++;
176 p->min_run = d == p->last ? p->min_run + 1 : 1;
177 } else if (p->last == p->min) {
178 p->min_runs += p->min_run * p->min_run;
179 }
180
181 if (d > p->max) {
182 p->max = d;
183 p->nmax = nd;
184 p->max_run = 1;
185 p->max_runs = 0;
186 p->max_count = 1;
187 } else if (d == p->max) {
188 p->max_count++;
189 p->max_run = d == p->last ? p->max_run + 1 : 1;
190 } else if (p->last == p->max) {
191 p->max_runs += p->max_run * p->max_run;
192 }
193
194 p->sigma_x += nd;
195 p->sigma_x2 += nd * nd;
196 p->avg_sigma_x2 = p->avg_sigma_x2 * s->mult + (1.0 - s->mult) * nd * nd;
197 p->min_diff = FFMIN(p->min_diff, fabs(d - p->last));
198 p->max_diff = FFMAX(p->max_diff, fabs(d - p->last));
199 p->diff1_sum += fabs(d - p->last);
200 p->last = d;
201 p->mask |= i;
202 p->imask &= i;
203
204 if (p->nb_samples >= s->tc_samples) {
205 p->max_sigma_x2 = FFMAX(p->max_sigma_x2, p->avg_sigma_x2);
206 p->min_sigma_x2 = FFMIN(p->min_sigma_x2, p->avg_sigma_x2);
207 }
208 p->nb_samples++;
209}
210
211static void set_meta(AVDictionary **metadata, int chan, const char *key,
212 const char *fmt, double val)
213{
214 uint8_t value[128];
215 uint8_t key2[128];
216
217 snprintf(value, sizeof(value), fmt, val);
218 if (chan)
219 snprintf(key2, sizeof(key2), "lavfi.astats.%d.%s", chan, key);
220 else
221 snprintf(key2, sizeof(key2), "lavfi.astats.%s", key);
222 av_dict_set(metadata, key2, value, 0);
223}
224
225#define LINEAR_TO_DB(x) (log10(x) * 20)
226
227static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
228{
229 uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0;
230 double min_runs = 0, max_runs = 0,
231 min = DBL_MAX, max = DBL_MIN, min_diff = DBL_MAX, max_diff = 0,
232 nmin = DBL_MAX, nmax = DBL_MIN,
233 max_sigma_x = 0,
234 diff1_sum = 0,
235 sigma_x = 0,
236 sigma_x2 = 0,
237 min_sigma_x2 = DBL_MAX,
238 max_sigma_x2 = DBL_MIN;
239 AVRational depth;
240 int c;
241
242 for (c = 0; c < s->nb_channels; c++) {
243 ChannelStats *p = &s->chstats[c];
244
245 if (p->nb_samples < s->tc_samples)
246 p->min_sigma_x2 = p->max_sigma_x2 = p->sigma_x2 / p->nb_samples;
247
248 min = FFMIN(min, p->min);
249 max = FFMAX(max, p->max);
250 nmin = FFMIN(nmin, p->nmin);
251 nmax = FFMAX(nmax, p->nmax);
252 min_diff = FFMIN(min_diff, p->min_diff);
253 max_diff = FFMAX(max_diff, p->max_diff);
254 diff1_sum += p->diff1_sum,
255 min_sigma_x2 = FFMIN(min_sigma_x2, p->min_sigma_x2);
256 max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
257 sigma_x += p->sigma_x;
258 sigma_x2 += p->sigma_x2;
259 min_count += p->min_count;
260 max_count += p->max_count;
261 min_runs += p->min_runs;
262 max_runs += p->max_runs;
263 mask |= p->mask;
264 imask &= p->imask;
265 nb_samples += p->nb_samples;
266 if (fabs(p->sigma_x) > fabs(max_sigma_x))
267 max_sigma_x = p->sigma_x;
268
269 set_meta(metadata, c + 1, "DC_offset", "%f", p->sigma_x / p->nb_samples);
270 set_meta(metadata, c + 1, "Min_level", "%f", p->min);
271 set_meta(metadata, c + 1, "Max_level", "%f", p->max);
272 set_meta(metadata, c + 1, "Min_difference", "%f", p->min_diff);
273 set_meta(metadata, c + 1, "Max_difference", "%f", p->max_diff);
274 set_meta(metadata, c + 1, "Mean_difference", "%f", p->diff1_sum / (p->nb_samples - 1));
275 set_meta(metadata, c + 1, "Peak_level", "%f", LINEAR_TO_DB(FFMAX(-p->nmin, p->nmax)));
276 set_meta(metadata, c + 1, "RMS_level", "%f", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples)));
277 set_meta(metadata, c + 1, "RMS_peak", "%f", LINEAR_TO_DB(sqrt(p->max_sigma_x2)));
278 set_meta(metadata, c + 1, "RMS_trough", "%f", LINEAR_TO_DB(sqrt(p->min_sigma_x2)));
279 set_meta(metadata, c + 1, "Crest_factor", "%f", p->sigma_x2 ? FFMAX(-p->min, p->max) / sqrt(p->sigma_x2 / p->nb_samples) : 1);
280 set_meta(metadata, c + 1, "Flat_factor", "%f", LINEAR_TO_DB((p->min_runs + p->max_runs) / (p->min_count + p->max_count)));
281 set_meta(metadata, c + 1, "Peak_count", "%f", (float)(p->min_count + p->max_count));
282 bit_depth(s, p->mask, p->imask, &depth);
283 set_meta(metadata, c + 1, "Bit_depth", "%f", depth.num);
284 set_meta(metadata, c + 1, "Bit_depth2", "%f", depth.den);
285 }
286
287 set_meta(metadata, 0, "Overall.DC_offset", "%f", max_sigma_x / (nb_samples / s->nb_channels));
288 set_meta(metadata, 0, "Overall.Min_level", "%f", min);
289 set_meta(metadata, 0, "Overall.Max_level", "%f", max);
290 set_meta(metadata, 0, "Overall.Min_difference", "%f", min_diff);
291 set_meta(metadata, 0, "Overall.Max_difference", "%f", max_diff);
292 set_meta(metadata, 0, "Overall.Mean_difference", "%f", diff1_sum / (nb_samples - s->nb_channels));
293 set_meta(metadata, 0, "Overall.Peak_level", "%f", LINEAR_TO_DB(FFMAX(-nmin, nmax)));
294 set_meta(metadata, 0, "Overall.RMS_level", "%f", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
295 set_meta(metadata, 0, "Overall.RMS_peak", "%f", LINEAR_TO_DB(sqrt(max_sigma_x2)));
296 set_meta(metadata, 0, "Overall.RMS_trough", "%f", LINEAR_TO_DB(sqrt(min_sigma_x2)));
297 set_meta(metadata, 0, "Overall.Flat_factor", "%f", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
298 set_meta(metadata, 0, "Overall.Peak_count", "%f", (float)(min_count + max_count) / (double)s->nb_channels);
299 bit_depth(s, mask, imask, &depth);
300 set_meta(metadata, 0, "Overall.Bit_depth", "%f", depth.num);
301 set_meta(metadata, 0, "Overall.Bit_depth2", "%f", depth.den);
302 set_meta(metadata, 0, "Overall.Number_of_samples", "%f", nb_samples / s->nb_channels);
303}
304
305static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
306{
307 AudioStatsContext *s = inlink->dst->priv;
308 AVDictionary **metadata = avpriv_frame_get_metadatap(buf);
309 const int channels = s->nb_channels;
310 int i, c;
311
312 if (s->reset_count > 0) {
313 if (s->nb_frames >= s->reset_count) {
314 reset_stats(s);
315 s->nb_frames = 0;
316 }
317 s->nb_frames++;
318 }
319
320 switch (inlink->format) {
321 case AV_SAMPLE_FMT_DBLP:
322 for (c = 0; c < channels; c++) {
323 ChannelStats *p = &s->chstats[c];
324 const double *src = (const double *)buf->extended_data[c];
325
326 for (i = 0; i < buf->nb_samples; i++, src++)
327 update_stat(s, p, *src, *src, llrint(*src * (UINT64_C(1) << 63)));
328 }
329 break;
330 case AV_SAMPLE_FMT_DBL: {
331 const double *src = (const double *)buf->extended_data[0];
332
333 for (i = 0; i < buf->nb_samples; i++) {
334 for (c = 0; c < channels; c++, src++)
335 update_stat(s, &s->chstats[c], *src, *src, llrint(*src * (UINT64_C(1) << 63)));
336 }}
337 break;
338 case AV_SAMPLE_FMT_FLTP:
339 for (c = 0; c < channels; c++) {
340 ChannelStats *p = &s->chstats[c];
341 const float *src = (const float *)buf->extended_data[c];
342
343 for (i = 0; i < buf->nb_samples; i++, src++)
344 update_stat(s, p, *src, *src, llrint(*src * (UINT64_C(1) << 31)));
345 }
346 break;
347 case AV_SAMPLE_FMT_FLT: {
348 const float *src = (const float *)buf->extended_data[0];
349
350 for (i = 0; i < buf->nb_samples; i++) {
351 for (c = 0; c < channels; c++, src++)
352 update_stat(s, &s->chstats[c], *src, *src, llrint(*src * (UINT64_C(1) << 31)));
353 }}
354 break;
355 case AV_SAMPLE_FMT_S64P:
356 for (c = 0; c < channels; c++) {
357 ChannelStats *p = &s->chstats[c];
358 const int64_t *src = (const int64_t *)buf->extended_data[c];
359
360 for (i = 0; i < buf->nb_samples; i++, src++)
361 update_stat(s, p, *src, *src / (double)INT64_MAX, *src);
362 }
363 break;
364 case AV_SAMPLE_FMT_S64: {
365 const int64_t *src = (const int64_t *)buf->extended_data[0];
366
367 for (i = 0; i < buf->nb_samples; i++) {
368 for (c = 0; c < channels; c++, src++)
369 update_stat(s, &s->chstats[c], *src, *src / (double)INT64_MAX, *src);
370 }}
371 break;
372 case AV_SAMPLE_FMT_S32P:
373 for (c = 0; c < channels; c++) {
374 ChannelStats *p = &s->chstats[c];
375 const int32_t *src = (const int32_t *)buf->extended_data[c];
376
377 for (i = 0; i < buf->nb_samples; i++, src++)
378 update_stat(s, p, *src, *src / (double)INT32_MAX, *src);
379 }
380 break;
381 case AV_SAMPLE_FMT_S32: {
382 const int32_t *src = (const int32_t *)buf->extended_data[0];
383
384 for (i = 0; i < buf->nb_samples; i++) {
385 for (c = 0; c < channels; c++, src++)
386 update_stat(s, &s->chstats[c], *src, *src / (double)INT32_MAX, *src);
387 }}
388 break;
389 case AV_SAMPLE_FMT_S16P:
390 for (c = 0; c < channels; c++) {
391 ChannelStats *p = &s->chstats[c];
392 const int16_t *src = (const int16_t *)buf->extended_data[c];
393
394 for (i = 0; i < buf->nb_samples; i++, src++)
395 update_stat(s, p, *src, *src / (double)INT16_MAX, *src);
396 }
397 break;
398 case AV_SAMPLE_FMT_S16: {
399 const int16_t *src = (const int16_t *)buf->extended_data[0];
400
401 for (i = 0; i < buf->nb_samples; i++) {
402 for (c = 0; c < channels; c++, src++)
403 update_stat(s, &s->chstats[c], *src, *src / (double)INT16_MAX, *src);
404 }}
405 break;
406 }
407
408 if (s->metadata)
409 set_metadata(s, metadata);
410
411 return ff_filter_frame(inlink->dst->outputs[0], buf);
412}
413
414static void print_stats(AVFilterContext *ctx)
415{
416 AudioStatsContext *s = ctx->priv;
417 uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0;
418 double min_runs = 0, max_runs = 0,
419 min = DBL_MAX, max = DBL_MIN, min_diff = DBL_MAX, max_diff = 0,
420 nmin = DBL_MAX, nmax = DBL_MIN,
421 max_sigma_x = 0,
422 diff1_sum = 0,
423 sigma_x = 0,
424 sigma_x2 = 0,
425 min_sigma_x2 = DBL_MAX,
426 max_sigma_x2 = DBL_MIN;
427 AVRational depth;
428 int c;
429
430 for (c = 0; c < s->nb_channels; c++) {
431 ChannelStats *p = &s->chstats[c];
432
433 if (p->nb_samples < s->tc_samples)
434 p->min_sigma_x2 = p->max_sigma_x2 = p->sigma_x2 / p->nb_samples;
435
436 min = FFMIN(min, p->min);
437 max = FFMAX(max, p->max);
438 nmin = FFMIN(nmin, p->nmin);
439 nmax = FFMAX(nmax, p->nmax);
440 min_diff = FFMIN(min_diff, p->min_diff);
441 max_diff = FFMAX(max_diff, p->max_diff);
442 diff1_sum += p->diff1_sum,
443 min_sigma_x2 = FFMIN(min_sigma_x2, p->min_sigma_x2);
444 max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
445 sigma_x += p->sigma_x;
446 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 if (fabs(p->sigma_x) > fabs(max_sigma_x))
455 max_sigma_x = p->sigma_x;
456
457 av_log(ctx, AV_LOG_INFO, "Channel: %d\n", c + 1);
458 av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", p->sigma_x / p->nb_samples);
459 av_log(ctx, AV_LOG_INFO, "Min level: %f\n", p->min);
460 av_log(ctx, AV_LOG_INFO, "Max level: %f\n", p->max);
461 av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", p->min_diff);
462 av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", p->max_diff);
463 av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", p->diff1_sum / (p->nb_samples - 1));
464 av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-p->nmin, p->nmax)));
465 av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples)));
466 av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(p->max_sigma_x2)));
467 if (p->min_sigma_x2 != 1)
468 av_log(ctx, AV_LOG_INFO, "RMS trough dB: %f\n",LINEAR_TO_DB(sqrt(p->min_sigma_x2)));
469 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);
470 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)));
471 av_log(ctx, AV_LOG_INFO, "Peak count: %"PRId64"\n", p->min_count + p->max_count);
472 bit_depth(s, p->mask, p->imask, &depth);
473 av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
474 }
475
476 av_log(ctx, AV_LOG_INFO, "Overall\n");
477 av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", max_sigma_x / (nb_samples / s->nb_channels));
478 av_log(ctx, AV_LOG_INFO, "Min level: %f\n", min);
479 av_log(ctx, AV_LOG_INFO, "Max level: %f\n", max);
480 av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", min_diff);
481 av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", max_diff);
482 av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", diff1_sum / (nb_samples - s->nb_channels));
483 av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-nmin, nmax)));
484 av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
485 av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(max_sigma_x2)));
486 if (min_sigma_x2 != 1)
487 av_log(ctx, AV_LOG_INFO, "RMS trough dB: %f\n", LINEAR_TO_DB(sqrt(min_sigma_x2)));
488 av_log(ctx, AV_LOG_INFO, "Flat factor: %f\n", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
489 av_log(ctx, AV_LOG_INFO, "Peak count: %f\n", (min_count + max_count) / (double)s->nb_channels);
490 bit_depth(s, mask, imask, &depth);
491 av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
492 av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels);
493}
494
495static av_cold void uninit(AVFilterContext *ctx)
496{
497 AudioStatsContext *s = ctx->priv;
498
499 if (s->nb_channels)
500 print_stats(ctx);
501 av_freep(&s->chstats);
502}
503
504static const AVFilterPad astats_inputs[] = {
505 {
506 .name = "default",
507 .type = AVMEDIA_TYPE_AUDIO,
508 .filter_frame = filter_frame,
509 },
510 { NULL }
511};
512
513static const AVFilterPad astats_outputs[] = {
514 {
515 .name = "default",
516 .type = AVMEDIA_TYPE_AUDIO,
517 .config_props = config_output,
518 },
519 { NULL }
520};
521
522AVFilter ff_af_astats = {
523 .name = "astats",
524 .description = NULL_IF_CONFIG_SMALL("Show time domain statistics about audio frames."),
525 .query_formats = query_formats,
526 .priv_size = sizeof(AudioStatsContext),
527 .priv_class = &astats_class,
528 .uninit = uninit,
529 .inputs = astats_inputs,
530 .outputs = astats_outputs,
531};
532