diff options
author | Paul B Mahol <onemda@gmail.com> | 2015-07-17 09:30:03 +0000 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2015-07-17 09:30:03 +0000 |
commit | 3b365dda5cd5e0db394d807bf904403bde4f4bc8 (patch) | |
tree | ca5d967c5689b23e090b4d4c50c38b5819f6bcb6 /libavfilter/af_astats.c | |
parent | 8250943febe951824252d0f5b1e77b076544cbd3 (diff) | |
download | ffmpeg-3b365dda5cd5e0db394d807bf904403bde4f4bc8.tar.gz |
avfilter/af_astats: measure minimal and mean difference between two consecutive samples
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/af_astats.c')
-rw-r--r-- | libavfilter/af_astats.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c index 0e8c3e243a..e38d66b008 100644 --- a/libavfilter/af_astats.c +++ b/libavfilter/af_astats.c @@ -33,7 +33,8 @@ typedef struct ChannelStats { double min, max; double min_run, max_run; double min_runs, max_runs; - double max_diff; + double min_diff, max_diff; + double diff1_sum; uint64_t mask; uint64_t min_count, max_count; uint64_t nb_samples; @@ -104,7 +105,7 @@ static void reset_stats(AudioStatsContext *s) p->min = p->min_sigma_x2 = DBL_MAX; p->max = p->max_sigma_x2 = DBL_MIN; - p->max_diff = -1; + p->min_diff = p->max_diff = -1; } } @@ -162,7 +163,9 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d) p->sigma_x += d; p->sigma_x2 += d * d; p->avg_sigma_x2 = p->avg_sigma_x2 * s->mult + (1.0 - s->mult) * d * d; + p->min_diff = FFMIN(p->min_diff == -1 ? DBL_MAX : p->min_diff, FFABS(d - (p->min_diff == -1 ? DBL_MAX : p->last))); p->max_diff = FFMAX(p->max_diff, FFABS(d - (p->max_diff == -1 ? d : p->last))); + p->diff1_sum += FFABS(d - p->last); p->last = d; p->mask |= llrint(d * (1LLU<<63)); @@ -193,8 +196,9 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) { uint64_t mask = 0, min_count = 0, max_count = 0, nb_samples = 0; double min_runs = 0, max_runs = 0, - min = DBL_MAX, max = DBL_MIN, max_diff = 0, + min = DBL_MAX, max = DBL_MIN, min_diff = DBL_MAX, max_diff = 0, max_sigma_x = 0, + diff1_sum = 0, sigma_x = 0, sigma_x2 = 0, min_sigma_x2 = DBL_MAX, @@ -209,7 +213,9 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) min = FFMIN(min, p->min); max = FFMAX(max, p->max); + min_diff = FFMIN(min_diff, p->min_diff); max_diff = FFMAX(max_diff, p->max_diff); + diff1_sum += p->diff1_sum, min_sigma_x2 = FFMIN(min_sigma_x2, p->min_sigma_x2); max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2); sigma_x += p->sigma_x; @@ -226,7 +232,9 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) set_meta(metadata, c + 1, "DC_offset", "%f", p->sigma_x / p->nb_samples); set_meta(metadata, c + 1, "Min_level", "%f", p->min); set_meta(metadata, c + 1, "Max_level", "%f", p->max); + set_meta(metadata, c + 1, "Min_difference", "%f", p->min_diff); set_meta(metadata, c + 1, "Max_difference", "%f", p->max_diff); + set_meta(metadata, c + 1, "Mean_difference", "%f", p->diff1_sum / (p->nb_samples - 1)); set_meta(metadata, c + 1, "Peak_level", "%f", LINEAR_TO_DB(FFMAX(-p->min, p->max))); set_meta(metadata, c + 1, "RMS_level", "%f", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples))); set_meta(metadata, c + 1, "RMS_peak", "%f", LINEAR_TO_DB(sqrt(p->max_sigma_x2))); @@ -240,7 +248,9 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) set_meta(metadata, 0, "Overall.DC_offset", "%f", max_sigma_x / (nb_samples / s->nb_channels)); set_meta(metadata, 0, "Overall.Min_level", "%f", min); set_meta(metadata, 0, "Overall.Max_level", "%f", max); + set_meta(metadata, 0, "Overall.Min_difference", "%f", min_diff); set_meta(metadata, 0, "Overall.Max_difference", "%f", max_diff); + set_meta(metadata, 0, "Overall.Mean_difference", "%f", diff1_sum / (nb_samples - s->nb_channels)); set_meta(metadata, 0, "Overall.Peak_level", "%f", LINEAR_TO_DB(FFMAX(-min, max))); set_meta(metadata, 0, "Overall.RMS_level", "%f", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples))); set_meta(metadata, 0, "Overall.RMS_peak", "%f", LINEAR_TO_DB(sqrt(max_sigma_x2))); @@ -298,8 +308,9 @@ static void print_stats(AVFilterContext *ctx) AudioStatsContext *s = ctx->priv; uint64_t mask = 0, min_count = 0, max_count = 0, nb_samples = 0; double min_runs = 0, max_runs = 0, - min = DBL_MAX, max = DBL_MIN, max_diff = 0, + min = DBL_MAX, max = DBL_MIN, min_diff = DBL_MAX, max_diff = 0, max_sigma_x = 0, + diff1_sum = 0, sigma_x = 0, sigma_x2 = 0, min_sigma_x2 = DBL_MAX, @@ -314,7 +325,9 @@ static void print_stats(AVFilterContext *ctx) min = FFMIN(min, p->min); max = FFMAX(max, p->max); + min_diff = FFMIN(min_diff, p->min_diff); max_diff = FFMAX(max_diff, p->max_diff); + diff1_sum += p->diff1_sum, min_sigma_x2 = FFMIN(min_sigma_x2, p->min_sigma_x2); max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2); sigma_x += p->sigma_x; @@ -332,7 +345,9 @@ static void print_stats(AVFilterContext *ctx) av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", p->sigma_x / p->nb_samples); av_log(ctx, AV_LOG_INFO, "Min level: %f\n", p->min); av_log(ctx, AV_LOG_INFO, "Max level: %f\n", p->max); + av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", p->min_diff); av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", p->max_diff); + av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", p->diff1_sum / (p->nb_samples - 1)); av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-p->min, p->max))); av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples))); av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(p->max_sigma_x2))); @@ -348,7 +363,9 @@ static void print_stats(AVFilterContext *ctx) av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", max_sigma_x / (nb_samples / s->nb_channels)); av_log(ctx, AV_LOG_INFO, "Min level: %f\n", min); av_log(ctx, AV_LOG_INFO, "Max level: %f\n", max); + av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", min_diff); av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", max_diff); + av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", diff1_sum / (nb_samples - s->nb_channels)); av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-min, max))); av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples))); av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(max_sigma_x2))); |