diff options
author | Nicolas Gaullier <nicolas.gaullier@arkena.com> | 2018-02-19 14:16:04 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2018-03-29 15:45:20 +0200 |
commit | 56b2731aae33ea63bad06bca0a28569399be96ca (patch) | |
tree | d00426e3959c47e819426d27d9f8c808aa7686a7 /libavfilter/af_silencedetect.c | |
parent | cd4756a558195752abd1118953224d34e64b5243 (diff) |
lavfi/silencedetect: Fix silence_start accuracy
Diffstat (limited to 'libavfilter/af_silencedetect.c')
-rw-r--r-- | libavfilter/af_silencedetect.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c index b4184c2486..749c3fbcb7 100644 --- a/libavfilter/af_silencedetect.c +++ b/libavfilter/af_silencedetect.c @@ -37,6 +37,7 @@ typedef struct SilenceDetectContext { double noise; ///< noise amplitude ratio double duration; ///< minimum duration of silence until notification int mono; ///< mono mode : check each channel separately (default = check when ALL channels are silent) + int channels; ///< number of channels int independant_channels; ///< number of entries in following arrays (always 1 in mono mode) int64_t *nb_null_samples; ///< (array) current number of continuous zero samples int64_t *start; ///< (array) if silence is detected, this value contains the time of the first zero sample (default/unset = INT64_MIN) @@ -79,7 +80,8 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, if (s->start[channel] == INT64_MIN) { s->nb_null_samples[channel]++; if (s->nb_null_samples[channel] >= nb_samples_notify) { - s->start[channel] = insamples->pts - (int64_t)(s->duration / av_q2d(time_base) + .5); + s->start[channel] = insamples->pts + av_rescale_q(current_sample / s->channels + 1 - nb_samples_notify * s->independant_channels / s->channels, + (AVRational){ 1, s->last_sample_rate }, time_base); set_meta(insamples, s->mono ? channel + 1 : 0, "silence_start", av_ts2timestr(s->start[channel], &time_base)); if (s->mono) @@ -132,7 +134,8 @@ static int config_input(AVFilterLink *inlink) SilenceDetectContext *s = ctx->priv; int c; - s->independant_channels = s->mono ? inlink->channels : 1; + s->channels = inlink->channels; + s->independant_channels = s->mono ? s->channels : 1; s->nb_null_samples = av_mallocz_array(sizeof(*s->nb_null_samples), s->independant_channels); if (!s->nb_null_samples) return AVERROR(ENOMEM); |