[FFmpeg-devel] [PATCH 3/4] lavfi/silencedetect: export silence info to metadata.
Stefano Sabatini
stefasab at gmail.com
Thu Oct 11 11:55:05 CEST 2012
On date Wednesday 2012-10-10 00:55:12 +0200, Clément Bœsch encoded:
> ---
> libavfilter/af_silencedetect.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c
> index 2ea5d7f..7f1a8c4 100644
> --- a/libavfilter/af_silencedetect.c
> +++ b/libavfilter/af_silencedetect.c
> @@ -78,6 +78,12 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
> return 0;
> }
>
> +static char *get_meta_val(AVFilterBufferRef *insamples, const char *key)
static inline char *get_meta_val(const AVFilterBufferRef *insamples, const char *key) av_const
> +{
> + AVDictionaryEntry *e = av_dict_get(insamples->metadata, key, NULL, 0);
> + return e && e->value ? e->value : NULL;
> +}
> +
> static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
> {
> int i;
> @@ -103,16 +109,23 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
> silence->nb_null_samples++;
> if (silence->nb_null_samples >= nb_samples_notify) {
> silence->start = insamples->pts - silence->duration / av_q2d(inlink->time_base);
> - av_log(silence, AV_LOG_INFO,
> - "silence_start: %s\n", av_ts2timestr(silence->start, &inlink->time_base));
> + av_dict_set(&insamples->metadata, "lavfi.silence_start",
> + av_ts2timestr(silence->start, &inlink->time_base), 0);
> + av_log(silence, AV_LOG_INFO, "silence_start: %s\n",
> + get_meta_val(insamples, "lavfi.silence_start"));
> }
> }
> } else {
> - if (silence->start)
> + if (silence->start) {
> + av_dict_set(&insamples->metadata, "lavfi.silence_end",
> + av_ts2timestr(silence->start, &inlink->time_base), 0);
end/start mismatch?
> + av_dict_set(&insamples->metadata, "lavfi.silence_duration",
> + av_ts2timestr(insamples->pts - silence->start, &inlink->time_base), 0);
> av_log(silence, AV_LOG_INFO,
> "silence_end: %s | silence_duration: %s\n",
> - av_ts2timestr(insamples->pts, &inlink->time_base),
> - av_ts2timestr(insamples->pts - silence->start, &inlink->time_base));
> + get_meta_val(insamples, "lavfi.silence_end"),
> + get_meta_val(insamples, "lavfi.silence_duration"));
> + }
> silence->nb_null_samples = silence->start = 0;
> }
> }
Note: we should document this stuff in filters.texi, or people will
never realize the existence of this feature.
LGTM otherwise.
--
FFmpeg = Fundamentalist and Frenzy Martial Purposeless Elitarian Gigant
More information about the ffmpeg-devel
mailing list