diff options
author | Clément Bœsch <ubitux@gmail.com> | 2012-10-10 01:01:31 +0400 |
---|---|---|
committer | Clément Bœsch <ubitux@gmail.com> | 2012-10-21 19:29:11 +0400 |
commit | fbedce6b8512c33df4cc77996ec3e54221ca7511 (patch) | |
tree | 5c0b1daa795f7f579be0d305cd0388da2c7592fa /libavfilter | |
parent | de23953de2d827381886c900b02e9ead02ad56a3 (diff) |
lavfi/silencedetect: export silence info to metadata.
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/af_silencedetect.c | 24 | ||||
-rw-r--r-- | libavfilter/version.h | 2 |
2 files changed, 20 insertions, 6 deletions
diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c index b19ac2e94a..c456ac4970 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_metadata_val(AVFilterBufferRef *insamples, const char *key) +{ + 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; @@ -94,6 +100,7 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) silence->last_sample_rate = srate; // TODO: support more sample formats + // TODO: document metadata if (insamples->format == AV_SAMPLE_FMT_DBL) { double *p = (double *)insamples->data[0]; @@ -103,16 +110,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 - (int64_t)(silence->duration / av_q2d(inlink->time_base) + .5); - 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_metadata_val(insamples, "lavfi.silence_start")); } } } else { - if (silence->start) + if (silence->start) { + av_dict_set(&insamples->metadata, "lavfi.silence_end", + av_ts2timestr(insamples->pts, &inlink->time_base), 0); + 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_metadata_val(insamples, "lavfi.silence_end"), + get_metadata_val(insamples, "lavfi.silence_duration")); + } silence->nb_null_samples = silence->start = 0; } } diff --git a/libavfilter/version.h b/libavfilter/version.h index 0ad7372f44..2bf2d61749 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MINOR 20 -#define LIBAVFILTER_VERSION_MICRO 101 +#define LIBAVFILTER_VERSION_MICRO 102 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ |