From patchwork Mon Feb 12 09:48:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaullier Nicolas X-Patchwork-Id: 7570 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp3792256jai; Mon, 12 Feb 2018 01:49:21 -0800 (PST) X-Google-Smtp-Source: AH8x224/jSK64C02v2QKhV7ac7zk0OGR1ZgoMHfzVA/1LBseUDB0fLHtVBj6FH3tqYuuxUhxtEDy X-Received: by 10.28.140.9 with SMTP id o9mr3013813wmd.28.1518428960909; Mon, 12 Feb 2018 01:49:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518428960; cv=none; d=google.com; s=arc-20160816; b=KD49Cv69Z6Jbhl2U8W8gzn0zPpWntoEj/Mzfu4VhMpQi7DI0eiug+JPMZaoP2S7Btf TSdsexZD+UUcwVuniFu1tvr0E34wuL09VzA69y/lQwe6kjK1POhtqx+y24wm7lddn518 XB1KEJY+AUKbNlJHfkIJvBb0g9ZsokBSC/Ir3/+34wci0O2pyFuK6uhfWhWUOmlEv7Gq ggVLPYjXjuV+KBYBxyAP1XWnMrJKPY5ucjjLyL+0deOomrlCplYvLID+Kcj3QdadESKp x3gQDR4KVTWiiq4cN3qL05LOnQ3A2lVT44I/wFOv5ICNGTiNFMXyxm4rrqABg0H4lYtq 4bgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=Ft4Zr+YP3Fw2GZgIm8SvtFH1qP4pnMXYXlmFbeUDlt4=; b=Ty3zXdAG8gNemVrqamouY6ImDeKs/6SlPCU0BpgnRiCBIS3By2u+19+B0tJPdiB9Z/ nYkn2/omVp1wuWMyk1dXT6L++u7UOG05d9w4lC47CcssVGlIICvy8kok/Zzrfwamov+V 7gurAa+aHZLrXrKcrIiqYLoCX/t30j+1pSlFayZVT2sqzKpKfPyHs+XUpWfBPA0lwMBT 3QyyaRPrjV6vver9E+JAag2Q2b0c85Wor6vwEV7g8yisNVJVr/e9dzY4C48C3DsSg+yG /ZpHrbGWkFCV6sYFTBPJYJahB7npnO8IaDOq8Z8c9Qymr4tTa3HmVAteLNUXlzbiVDic SB5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@arkena.com header.s=20150421 header.b=Wry+AGyt; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p78si3419496wmg.235.2018.02.12.01.49.20; Mon, 12 Feb 2018 01:49:20 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@arkena.com header.s=20150421 header.b=Wry+AGyt; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C09B2689977; Mon, 12 Feb 2018 11:48:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp-1.arkena.net (smtp-1.arkena.net [95.81.173.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4AAD2689A46 for ; Mon, 12 Feb 2018 11:48:26 +0200 (EET) Received: from secu2 (unknown [10.180.103.10]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-1.arkena.net (Postfix) with ESMTPSA id 3zg1840p3rzMcYJ; Mon, 12 Feb 2018 09:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arkena.com; s=20150421; t=1518428916; bh=F4Z0+T4sChO2VJ1NWxGOfcQa9qBzoEucIqo3E7/Rics=; h=From:To:Cc:Subject:Date:Message-Id; b=Wry+AGyti2Co8+L74RsSTUkykDP2CtYL0l+jrJlB+PlN57oaf3Ha4g+kQRrUMQFFJ WqgREH0b3sBBSqT0FGQqtel0ZCPA2/HSTfDx9gUMVcrcxgcIjbp5TNULf9/Xh0795t iOu63p2GpE1aj17R7k5QB8+QYBhx3vad50HzfRkE= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 55C903FA75; Mon, 12 Feb 2018 12:39:29 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Feb 2018 10:48:26 +0100 Message-Id: <20180212094830.9304-4-nicolas.gaullier@arkena.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180212094830.9304-1-nicolas.gaullier@arkena.com> References: <20180212094830.9304-1-nicolas.gaullier@arkena.com> Subject: [FFmpeg-devel] [PATCH v2 4/8] avfilter/silencedetect: fix silence_start accuracy X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: nicolas gaullier MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: nicolas gaullier --- libavfilter/af_silencedetect.c | 7 +++++-- tests/ref/fate/filter-metadata-silencedetect | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c index b4184c2486..749c3fbcb7 100644 --- a/libavfilter/af_silencedetect.c +++ b/libavfilter/af_silencedetect.c @@ -37,6 +37,7 @@ typedef struct SilenceDetectContext { double noise; ///< noise amplitude ratio double duration; ///< minimum duration of silence until notification int mono; ///< mono mode : check each channel separately (default = check when ALL channels are silent) + int channels; ///< number of channels 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 (default/unset = INT64_MIN) @@ -79,7 +80,8 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, if (s->start[channel] == INT64_MIN) { 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); + s->start[channel] = insamples->pts + av_rescale_q(current_sample / s->channels + 1 - nb_samples_notify * s->independant_channels / s->channels, + (AVRational){ 1, s->last_sample_rate }, time_base); set_meta(insamples, s->mono ? channel + 1 : 0, "silence_start", av_ts2timestr(s->start[channel], &time_base)); if (s->mono) @@ -132,7 +134,8 @@ static int config_input(AVFilterLink *inlink) SilenceDetectContext *s = ctx->priv; int c; - s->independant_channels = s->mono ? inlink->channels : 1; + s->channels = inlink->channels; + s->independant_channels = s->mono ? s->channels : 1; s->nb_null_samples = av_mallocz_array(sizeof(*s->nb_null_samples), s->independant_channels); if (!s->nb_null_samples) return AVERROR(ENOMEM); diff --git a/tests/ref/fate/filter-metadata-silencedetect b/tests/ref/fate/filter-metadata-silencedetect index d1d6f67dc0..917b836250 100644 --- a/tests/ref/fate/filter-metadata-silencedetect +++ b/tests/ref/fate/filter-metadata-silencedetect @@ -12,12 +12,12 @@ pkt_pts=3200 pkt_pts=3520 pkt_pts=3840 pkt_pts=4160 -pkt_pts=4480|tag:lavfi.silence_start=-0.02 +pkt_pts=4480|tag:lavfi.silence_start=0 pkt_pts=4800 pkt_pts=5120 pkt_pts=5440 pkt_pts=5760 -pkt_pts=6080|tag:lavfi.silence_end=0.38|tag:lavfi.silence_duration=0.4 +pkt_pts=6080|tag:lavfi.silence_end=0.38|tag:lavfi.silence_duration=0.38 pkt_pts=6400 pkt_pts=6720 pkt_pts=7040 @@ -72,7 +72,7 @@ pkt_pts=22400 pkt_pts=22720 pkt_pts=23040 pkt_pts=23360 -pkt_pts=23680|tag:lavfi.silence_start=1.18 +pkt_pts=23680|tag:lavfi.silence_start=1.18756 pkt_pts=24000 pkt_pts=24320 pkt_pts=24640 @@ -97,7 +97,7 @@ pkt_pts=30400 pkt_pts=30720 pkt_pts=31040 pkt_pts=31360 -pkt_pts=31680|tag:lavfi.silence_end=1.98|tag:lavfi.silence_duration=0.8 +pkt_pts=31680|tag:lavfi.silence_end=1.98|tag:lavfi.silence_duration=0.792438 pkt_pts=32000 pkt_pts=32320 pkt_pts=32640 @@ -160,7 +160,7 @@ pkt_pts=50560 pkt_pts=50880 pkt_pts=51200 pkt_pts=51520 -pkt_pts=51840|tag:lavfi.silence_start=2.94 +pkt_pts=51840|tag:lavfi.silence_start=2.945 pkt_pts=52160 pkt_pts=52480 pkt_pts=52800 @@ -196,7 +196,7 @@ pkt_pts=62080 pkt_pts=62400 pkt_pts=62720 pkt_pts=63040 -pkt_pts=63360|tag:lavfi.silence_end=3.96|tag:lavfi.silence_duration=1.02 +pkt_pts=63360|tag:lavfi.silence_end=3.96|tag:lavfi.silence_duration=1.015 pkt_pts=63680 pkt_pts=64000 pkt_pts=64320 @@ -250,7 +250,7 @@ pkt_pts=79360 pkt_pts=79680 pkt_pts=80000 pkt_pts=80320 -pkt_pts=80640|tag:lavfi.silence_start=4.74 +pkt_pts=80640|tag:lavfi.silence_start=4.75662 pkt_pts=80960 pkt_pts=81280 pkt_pts=81600 @@ -270,7 +270,7 @@ pkt_pts=85760 pkt_pts=86080 pkt_pts=86400 pkt_pts=86720 -pkt_pts=87040|tag:lavfi.silence_end=5.44|tag:lavfi.silence_duration=0.7 +pkt_pts=87040|tag:lavfi.silence_end=5.44|tag:lavfi.silence_duration=0.683375 pkt_pts=87360 pkt_pts=87680 pkt_pts=88000 @@ -326,7 +326,7 @@ pkt_pts=103680 pkt_pts=104000 pkt_pts=104320 pkt_pts=104640 -pkt_pts=104960|tag:lavfi.silence_start=6.26 +pkt_pts=104960|tag:lavfi.silence_start=6.27319 pkt_pts=105280 pkt_pts=105600 pkt_pts=105920 @@ -362,7 +362,7 @@ pkt_pts=115200 pkt_pts=115520 pkt_pts=115840 pkt_pts=116160 -pkt_pts=116480|tag:lavfi.silence_end=7.28|tag:lavfi.silence_duration=1.02 +pkt_pts=116480|tag:lavfi.silence_end=7.28|tag:lavfi.silence_duration=1.00681 pkt_pts=116800 pkt_pts=117120 pkt_pts=117440 @@ -425,7 +425,7 @@ pkt_pts=135360 pkt_pts=135680 pkt_pts=136000 pkt_pts=136320 -pkt_pts=136640|tag:lavfi.silence_start=8.24 +pkt_pts=136640|tag:lavfi.silence_start=8.25106 pkt_pts=136960 pkt_pts=137280 pkt_pts=137600 @@ -452,7 +452,7 @@ pkt_pts=144000 pkt_pts=144320 pkt_pts=144640 pkt_pts=144960 -pkt_pts=145280|tag:lavfi.silence_end=9.08|tag:lavfi.silence_duration=0.84 +pkt_pts=145280|tag:lavfi.silence_end=9.08|tag:lavfi.silence_duration=0.828937 pkt_pts=145600 pkt_pts=145920 pkt_pts=146240 @@ -504,7 +504,7 @@ pkt_pts=160640 pkt_pts=160960 pkt_pts=161280 pkt_pts=161600 -pkt_pts=161920|tag:lavfi.silence_start=9.82 +pkt_pts=161920|tag:lavfi.silence_start=9.83881 pkt_pts=162240 pkt_pts=162560 pkt_pts=162880