30 #define MEASURE_ALL UINT_MAX 31 #define MEASURE_NONE 0 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) 56 #define MEASURE_MINMAXPEAK (MEASURE_MIN_LEVEL | MEASURE_MAX_LEVEL | MEASURE_PEAK_LEVEL) 97 #define OFFSET(x) offsetof(AudioStatsContext, x) 98 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 191 p->
imask = 0xFFFFFFFFFFFFFFFF;
230 mask = mask & (~imask);
232 for (; result && !(mask & 1); --result, mask >>= 1);
237 for (; result; --result, mask >>= 1)
258 }
else if (d == p->
min) {
261 }
else if (p->
last == p->
min) {
274 }
else if (d == p->
max) {
277 }
else if (p->
last == p->
max) {
308 int type = fpclassify(d);
311 p->
nb_infs += type == FP_INFINITE;
317 int type = fpclassify(d);
320 p->
nb_infs += type == FP_INFINITE;
325 const char *
fmt,
double val)
330 snprintf(value,
sizeof(value), fmt, val);
332 snprintf(key2,
sizeof(key2),
"lavfi.astats.%d.%s", chan, key);
334 snprintf(key2,
sizeof(key2),
"lavfi.astats.%s", key);
338 #define LINEAR_TO_DB(x) (log10(x) * 20) 385 if (fabs(p->
sigma_x) > fabs(max_sigma_x))
391 set_meta(metadata, c + 1,
"Min_level",
"%f", p->
min);
393 set_meta(metadata, c + 1,
"Max_level",
"%f", p->
max);
418 set_meta(metadata, c + 1,
"Bit_depth",
"%f", depth.
num);
419 set_meta(metadata, c + 1,
"Bit_depth2",
"%f", depth.
den);
438 set_meta(metadata, 0,
"Overall.Min_level",
"%f",
min);
440 set_meta(metadata, 0,
"Overall.Max_level",
"%f", max);
442 set_meta(metadata, 0,
"Overall.Min_difference",
"%f", min_diff);
444 set_meta(metadata, 0,
"Overall.Max_difference",
"%f", max_diff);
463 set_meta(metadata, 0,
"Overall.Bit_depth",
"%f", depth.
num);
464 set_meta(metadata, 0,
"Overall.Bit_depth2",
"%f", depth.
den);
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++) { \ 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) { \ 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, ); \ 504 UPDATE_STATS_##planar(type, update_minmax(s, p, sample), , p->nmin = p->min normalizer_suffix; p->nmax = p->max normalizer_suffix;); \ 608 if (fabs(p->
sigma_x) > fabs(max_sigma_x))
733 .priv_class = &astats_class,
#define MEASURE_NUMBER_OF_INFS
const char const char void * val
#define MEASURE_DYNAMIC_RANGE
This structure describes decoded (raw) audio or video data.
static int query_formats(AVFilterContext *ctx)
Main libavfilter public API header.
#define MEASURE_MAX_DIFFERENCE
#define MEASURE_RMS_DIFFERENCE
#define MEASURE_NUMBER_OF_NANS
static void update_minmax(AudioStatsContext *s, ChannelStats *p, double d)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
const char * name
Pad name.
#define MEASURE_MEAN_DIFFERENCE
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define MEASURE_NUMBER_OF_DENORMALS
#define MEASURE_RMS_LEVEL
static const AVFilterPad astats_inputs[]
static void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i)
AVDictionary * metadata
metadata.
#define MEASURE_PEAK_LEVEL
#define MEASURE_PEAK_COUNT
A filter pad used for either input or output.
A link between two filters.
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
static av_cold void uninit(AVFilterContext *ctx)
#define i(width, name, range_min, range_max)
int sample_rate
samples per second
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define MEASURE_NUMBER_OF_SAMPLES
#define MEASURE_BIT_DEPTH
AVFILTER_DEFINE_CLASS(astats)
#define MEASURE_DC_OFFSET
static void print_stats(AVFilterContext *ctx)
#define UPDATE_STATS(planar, type, sample, normalizer_suffix, int_sample)
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
static void update_float_stat(AudioStatsContext *s, ChannelStats *p, float d)
static int config_output(AVFilterLink *outlink)
static void reset_stats(AudioStatsContext *s)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define MEASURE_ZERO_CROSSINGS_RATE
AVFilterContext * src
source filter
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
int format
agreed upon media format
A list of supported channel layouts.
#define MEASURE_FLAT_FACTOR
static const AVOption astats_options[]
#define AV_LOG_INFO
Standard information.
AVSampleFormat
Audio sample formats.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
#define MEASURE_RMS_TROUGH
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static void update_double_stat(AudioStatsContext *s, ChannelStats *p, double d)
#define MEASURE_MIN_LEVEL
static void set_meta(AVDictionary **metadata, int chan, const char *key, const char *fmt, double val)
int channels
Number of channels.
AVFilterContext * dst
dest filter
static const AVFilterPad astats_outputs[]
static enum AVSampleFormat sample_fmts[]
#define MEASURE_CREST_FACTOR
#define MEASURE_MAX_LEVEL
#define MEASURE_ZERO_CROSSINGS
#define MEASURE_MIN_DIFFERENCE
uint8_t ** extended_data
pointers to the data planes/channels.
int nb_samples
number of audio samples (per channel) described by this frame
static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)