[FFmpeg-cvslog] lavfi/silencedetect: increase duration precision.

Clément Bœsch git at videolan.org
Sun Oct 21 01:25:20 CEST 2012


ffmpeg | branch: master | Clément Bœsch <ubitux at gmail.com> | Sun Oct 21 01:28:19 2012 +0200| [273fca9ac071da4078afa61f087e1e90fafd4958] | committer: Clément Bœsch

lavfi/silencedetect: increase duration precision.

This should also fix CID717889.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=273fca9ac071da4078afa61f087e1e90fafd4958
---

 libavfilter/af_silencedetect.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c
index 2ea5d7f..b19ac2e 100644
--- a/libavfilter/af_silencedetect.c
+++ b/libavfilter/af_silencedetect.c
@@ -35,7 +35,7 @@ typedef struct {
     const AVClass *class;
     char *noise_str;            ///< noise option string
     double noise;               ///< noise amplitude ratio
-    int duration;               ///< minimum duration of silence until notification
+    double duration;            ///< minimum duration of silence until notification
     int64_t nb_null_samples;    ///< current number of continuous zero samples
     int64_t start;              ///< if silence is detected, this value contains the time of the first zero sample
     int last_sample_rate;       ///< last sample rate to check for sample rate changes
@@ -46,8 +46,8 @@ typedef struct {
 static const AVOption silencedetect_options[] = {
     { "n",         "set noise tolerance",              OFFSET(noise_str), AV_OPT_TYPE_STRING, {.str="-60dB"}, CHAR_MIN, CHAR_MAX, FLAGS },
     { "noise",     "set noise tolerance",              OFFSET(noise_str), AV_OPT_TYPE_STRING, {.str="-60dB"}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "d",         "set minimum duration in seconds",  OFFSET(duration),  AV_OPT_TYPE_INT,    {.i64=2},    0, INT_MAX, FLAGS },
-    { "duration",  "set minimum duration in seconds",  OFFSET(duration),  AV_OPT_TYPE_INT,    {.i64=2},    0, INT_MAX, FLAGS },
+    { "d",         "set minimum duration in seconds",  OFFSET(duration),  AV_OPT_TYPE_DOUBLE, {.dbl=2.},             0, 24*60*60, FLAGS },
+    { "duration",  "set minimum duration in seconds",  OFFSET(duration),  AV_OPT_TYPE_DOUBLE, {.dbl=2.},             0, 24*60*60, FLAGS },
     { NULL },
 };
 
@@ -102,7 +102,7 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
                 if (!silence->start) {
                     silence->nb_null_samples++;
                     if (silence->nb_null_samples >= nb_samples_notify) {
-                        silence->start = insamples->pts - silence->duration / av_q2d(inlink->time_base);
+                        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));
                     }



More information about the ffmpeg-cvslog mailing list