[FFmpeg-devel] [PATCH 3/4] lavfi/silencedetect: export silence info to metadata.

Clément Bœsch ubitux at gmail.com
Wed Oct 10 00:55:12 CEST 2012


---
 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)
+{
+    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);
+                    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;
             }
         }
-- 
1.7.12.2



More information about the ffmpeg-devel mailing list