Re: [FFmpeg-devel] [PATCH v2 1/8] avfilter/silencedetect: add mono mode in mono mode, silence is detected in any single channel (instead of all them simultaneously)

2018-02-12 Thread Gaullier Nicolas
>I believe there is an issue with your commit message:
>It should be something like:
>lavfi/silencedetect: Add mono mode
>
>In mono mode, silence is detected...
>(Note the two linebreaks, other differences are irrelevant.)
>
>Carl Eugen

Sorry, all my patches are missing an empty newline to separate the header and 
the body of the commit messages, I just realize my mistake, thank you. I will 
fix that in the next post at the end of the current review.

Nicolas Gaullier
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 1/8] avfilter/silencedetect: add mono mode in mono mode, silence is detected in any single channel (instead of all them simultaneously)

2018-02-12 Thread Carl Eugen Hoyos
2018-02-12 10:48 GMT+01:00 Nicolas Gaullier :
> From: nicolas gaullier 

I believe there is an issue with your commit message:
It should be something like:
lavfi/silencedetect: Add mono mode

In mono mode, silence is detected...
(Note the two linebreaks, other differences are irrelevant.)

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2 1/8] avfilter/silencedetect: add mono mode in mono mode, silence is detected in any single channel (instead of all them simultaneously)

2018-02-12 Thread Nicolas Gaullier
From: nicolas gaullier 

---
 libavfilter/af_silencedetect.c | 78 +++---
 1 file changed, 51 insertions(+), 27 deletions(-)

diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c
index b048d63738..c53b9d9218 100644
--- a/libavfilter/af_silencedetect.c
+++ b/libavfilter/af_silencedetect.c
@@ -36,8 +36,10 @@ typedef struct SilenceDetectContext {
 const AVClass *class;
 double noise;   ///< noise amplitude ratio
 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 mono;   ///< mono mode : check each channel separately 
(default = check when ALL channels are silent)
+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
 int last_sample_rate;   ///< last sample rate to check for sample rate 
changes
 
 void (*silencedetect)(struct SilenceDetectContext *s, AVFrame *insamples,
@@ -52,44 +54,55 @@ static const AVOption silencedetect_options[] = {
 { "noise", "set noise tolerance",  OFFSET(noise), 
AV_OPT_TYPE_DOUBLE, {.dbl=0.001},  0, DBL_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 },
+{ "mono",  "check each channel separately",OFFSET(mono),  
AV_OPT_TYPE_BOOL,   {.i64=0.}, 0, 1, FLAGS },
 { NULL }
 };
 
 AVFILTER_DEFINE_CLASS(silencedetect);
 
-static char *get_metadata_val(AVFrame *insamples, const char *key)
+static void set_meta(AVFrame *insamples, int channel, const char *key, char 
*value)
 {
-AVDictionaryEntry *e = av_dict_get(insamples->metadata, key, NULL, 0);
-return e && e->value ? e->value : NULL;
-}
+char key2[128];
 
+if (channel)
+snprintf(key2, sizeof(key2), "lavfi.%s.%d", key, channel);
+else
+snprintf(key2, sizeof(key2), "lavfi.%s", key);
+av_dict_set(>metadata, key2, value, 0);
+}
 static av_always_inline void update(SilenceDetectContext *s, AVFrame 
*insamples,
-int is_silence, int64_t nb_samples_notify,
+int is_silence, int current_sample, 
int64_t nb_samples_notify,
 AVRational time_base)
 {
+int channel = current_sample % s->independant_channels;
 if (is_silence) {
-if (!s->start) {
-s->nb_null_samples++;
-if (s->nb_null_samples >= nb_samples_notify) {
-s->start = insamples->pts - (int64_t)(s->duration / 
av_q2d(time_base) + .5);
-av_dict_set(>metadata, "lavfi.silence_start",
-av_ts2timestr(s->start, _base), 0);
+if (!s->start[channel]) {
+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);
+set_meta(insamples, s->mono ? channel + 1 : 0, "silence_start",
+av_ts2timestr(s->start[channel], _base));
+if (s->mono)
+av_log(s, AV_LOG_INFO, "channel: %d | ", channel);
 av_log(s, AV_LOG_INFO, "silence_start: %s\n",
-   get_metadata_val(insamples, "lavfi.silence_start"));
+av_ts2timestr(s->start[channel], _base));
 }
 }
 } else {
-if (s->start) {
-av_dict_set(>metadata, "lavfi.silence_end",
-av_ts2timestr(insamples->pts, _base), 0);
-av_dict_set(>metadata, "lavfi.silence_duration",
-av_ts2timestr(insamples->pts - s->start, _base), 
0);
-av_log(s, AV_LOG_INFO,
-   "silence_end: %s | silence_duration: %s\n",
-   get_metadata_val(insamples, "lavfi.silence_end"),
-   get_metadata_val(insamples, "lavfi.silence_duration"));
+if (s->start[channel]) {
+int64_t end_pts = insamples->pts;
+int64_t duration_ts = end_pts - s->start[channel];
+set_meta(insamples, s->mono ? channel + 1 : 0, "silence_end",
+av_ts2timestr(end_pts, _base));
+set_meta(insamples, s->mono ? channel + 1 : 0,