30 #define HISTOGRAM_SIZE 8192 31 #define HISTOGRAM_MAX (HISTOGRAM_SIZE-1) 33 #define MEASURE_ALL UINT_MAX 34 #define MEASURE_NONE 0 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) 61 #define MEASURE_MINMAXPEAK (MEASURE_MIN_LEVEL | MEASURE_MAX_LEVEL | MEASURE_PEAK_LEVEL) 108 #define OFFSET(x) offsetof(AudioStatsContext, x) 109 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 204 p->
imask = 0xFFFFFFFFFFFFFFFF;
258 mask = mask & (~imask);
260 for (; result && !(mask & 1); --result, mask >>= 1);
265 for (; result; --result, mask >>= 1)
289 }
else if (d == p->
min) {
292 }
else if (p->
last == p->
min) {
305 }
else if (d == p->
max) {
308 }
else if (p->
last == p->
max) {
336 p->
histogram[av_clip(
FFABS(drop) * HISTOGRAM_MAX, 0, HISTOGRAM_MAX)]--;
344 for (
int i = p->
max_index; i >= 0; i--) {
346 noise_floor = i / (double)HISTOGRAM_MAX;
355 if (noise_floor < p->noise_floor) {
377 int type = fpclassify(d);
380 p->
nb_infs += type == FP_INFINITE;
386 int type = fpclassify(d);
389 p->
nb_infs += type == FP_INFINITE;
394 const char *fmt,
double val)
399 snprintf(value,
sizeof(value), fmt, val);
401 snprintf(key2,
sizeof(key2),
"lavfi.astats.%d.%s", chan, key);
403 snprintf(key2,
sizeof(key2),
"lavfi.astats.%s", key);
407 #define LINEAR_TO_DB(x) (log10(x) * 20) 457 if (fabs(p->
sigma_x) > fabs(max_sigma_x))
463 set_meta(metadata, c + 1,
"Min_level",
"%f", p->
min);
465 set_meta(metadata, c + 1,
"Max_level",
"%f", p->
max);
494 set_meta(metadata, c + 1,
"Bit_depth",
"%f", depth.
num);
495 set_meta(metadata, c + 1,
"Bit_depth2",
"%f", depth.
den);
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);
543 set_meta(metadata, 0,
"Overall.Bit_depth",
"%f", depth.
num);
544 set_meta(metadata, 0,
"Overall.Bit_depth2",
"%f", depth.
den);
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++) { \ 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) { \ 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, ); \ 584 UPDATE_STATS_##planar(type, update_minmax(s, p, sample), , p->nmin = p->min normalizer_suffix; p->nmax = p->max normalizer_suffix;); \ 595 const int start = (buf->
channels * jobnr) / nb_jobs;
596 const int end = (buf->
channels * (jobnr+1)) / nb_jobs;
705 if (fabs(p->
sigma_x) > fabs(max_sigma_x))
845 .priv_class = &astats_class,
#define MEASURE_NUMBER_OF_INFS
#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.
AVFilterLink ** inputs
array of pointers to input links
#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
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define MEASURE_RMS_LEVEL
static const AVFilterPad astats_inputs[]
static av_cold int end(AVCodecContext *avctx)
static void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i)
uint64_t noise_floor_count
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 AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#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)
int channels
number of audio channels, only used for audio.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
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 flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
#define MEASURE_RMS_TROUGH
#define MEASURE_NOISE_FLOOR
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
unsigned histogram[HISTOGRAM_SIZE]
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.
avfilter_execute_func * execute
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.
#define MEASURE_NOISE_FLOOR_COUNT
static double val(void *priv, double ch)
int nb_samples
number of audio samples (per channel) described by this frame
static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)