mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
avfilter/af_astats: implement recalculation of stats after each X frames
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
d3836b603e
commit
c0d676f977
@ -45,6 +45,8 @@ typedef struct {
|
|||||||
double time_constant;
|
double time_constant;
|
||||||
double mult;
|
double mult;
|
||||||
int metadata;
|
int metadata;
|
||||||
|
int reset_count;
|
||||||
|
int nb_frames;
|
||||||
} AudioStatsContext;
|
} AudioStatsContext;
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(AudioStatsContext, x)
|
#define OFFSET(x) offsetof(AudioStatsContext, x)
|
||||||
@ -53,6 +55,7 @@ typedef struct {
|
|||||||
static const AVOption astats_options[] = {
|
static const AVOption astats_options[] = {
|
||||||
{ "length", "set the window length", OFFSET(time_constant), AV_OPT_TYPE_DOUBLE, {.dbl=.05}, .01, 10, FLAGS },
|
{ "length", "set the window length", OFFSET(time_constant), AV_OPT_TYPE_DOUBLE, {.dbl=.05}, .01, 10, FLAGS },
|
||||||
{ "metadata", "inject metadata in the filtergraph", OFFSET(metadata), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
|
{ "metadata", "inject metadata in the filtergraph", OFFSET(metadata), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
|
||||||
|
{ "reset", "recalculate stats after this many frames", OFFSET(reset_count), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,10 +91,23 @@ static int query_formats(AVFilterContext *ctx)
|
|||||||
return ff_set_common_samplerates(ctx, formats);
|
return ff_set_common_samplerates(ctx, formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void reset_stats(AudioStatsContext *s)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
memset(s->chstats, 0, sizeof(*s->chstats));
|
||||||
|
|
||||||
|
for (c = 0; c < s->nb_channels; c++) {
|
||||||
|
ChannelStats *p = &s->chstats[c];
|
||||||
|
|
||||||
|
p->min = p->min_sigma_x2 = DBL_MAX;
|
||||||
|
p->max = p->max_sigma_x2 = DBL_MIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int config_output(AVFilterLink *outlink)
|
static int config_output(AVFilterLink *outlink)
|
||||||
{
|
{
|
||||||
AudioStatsContext *s = outlink->src->priv;
|
AudioStatsContext *s = outlink->src->priv;
|
||||||
int c;
|
|
||||||
|
|
||||||
s->chstats = av_calloc(sizeof(*s->chstats), outlink->channels);
|
s->chstats = av_calloc(sizeof(*s->chstats), outlink->channels);
|
||||||
if (!s->chstats)
|
if (!s->chstats)
|
||||||
@ -100,12 +116,7 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
s->mult = exp((-1 / s->time_constant / outlink->sample_rate));
|
s->mult = exp((-1 / s->time_constant / outlink->sample_rate));
|
||||||
s->tc_samples = 5 * s->time_constant * outlink->sample_rate + .5;
|
s->tc_samples = 5 * s->time_constant * outlink->sample_rate + .5;
|
||||||
|
|
||||||
for (c = 0; c < s->nb_channels; c++) {
|
reset_stats(s);
|
||||||
ChannelStats *p = &s->chstats[c];
|
|
||||||
|
|
||||||
p->min = p->min_sigma_x2 = DBL_MAX;
|
|
||||||
p->max = p->max_sigma_x2 = DBL_MIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -251,6 +262,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
|
|||||||
if (s->metadata)
|
if (s->metadata)
|
||||||
set_metadata(s, metadata);
|
set_metadata(s, metadata);
|
||||||
|
|
||||||
|
if (s->reset_count > 0) {
|
||||||
|
s->nb_frames++;
|
||||||
|
if (s->nb_frames >= s->reset_count) {
|
||||||
|
reset_stats(s);
|
||||||
|
s->nb_frames = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ff_filter_frame(inlink->dst->outputs[0], buf);
|
return ff_filter_frame(inlink->dst->outputs[0], buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user