From patchwork Mon Feb 19 13:16:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaullier Nicolas X-Patchwork-Id: 7657 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.33 with SMTP id c30csp1507171jai; Mon, 19 Feb 2018 05:16:11 -0800 (PST) X-Google-Smtp-Source: AH8x2264v4NwfKhP2odsG5qqZSES2SmYJprytujTJ6IDn2hAUICv3kQwxJUiVNrZ/ljy8cYBznFK X-Received: by 10.28.194.2 with SMTP id s2mr10878348wmf.55.1519046171125; Mon, 19 Feb 2018 05:16:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519046171; cv=none; d=google.com; s=arc-20160816; b=tzwahKByOw3D0yhZMSamRf9utgcHlNFUi3xUy/tXyOUXh/1uyr60mgNGj5ZDDFQ/KK hiLWIOokI0m4Pht++cMBq2OOzmGC4fGQt3XoR9X4Yqq+fXZ7Dha+DOhC2IC+H4O5TN+W NUnVYVUuxCexzHFSgcP1uvFHjWRaWyn54uxQZdXju46Bpa1GlhEHzHg4NDz/XxhamoeI GL3Q7ywNjZfJWHMyfqSd+m1f46waWO6tqqivYNw1RhJVdRxb4KsBoRYDS+xc8mWioa4V gx6bdgUM8X3lHEPKrexA6TF4DFN6DNmjW/6EBViETBdoST040FD83y8xLyclfkyGmVfF TL9Q== 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:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=jSvpmeBkW/CKSRVgQJFfYu8fzD8aOfzQgdG02tDbMgc=; b=VUV/rjmgQzClexwhY5VrlXN1xwssYkDYfRTypBVccc+xzLJP59vdB6Pa6d60lsE709 z9Lilia8eqJC92Coi9lCbUHNF48UPML9nHeAqmVxjfEviFHLdThp3T8DdC7HSn0s4oUi nydLQEHL0Wj2Xh0iqTA1caEz0X4rcXaVl4sp4tamhAHF+ab1zvObTPgqAZpw1swfcUnj dfK25LB8f7QelbaSMBkGd6bukn1ehQP3SW+jZEEuMrWwE/6lQeRokMBTgnAgXJKLaxx2 G4y4fI4W3xreEkcYLg/zFQd8laZ39IKJe+c/ohegpMGTGFpbPLvYOpBlVXVHrgCBL8UL AcKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@arkena.com header.s=20150421 header.b=GF1QDEjH; 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 u11si8508032wru.314.2018.02.19.05.16.10; Mon, 19 Feb 2018 05:16:11 -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=GF1QDEjH; 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 D794768A109; Mon, 19 Feb 2018 15:16:06 +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 4E49468A0E3 for ; Mon, 19 Feb 2018 15:16:05 +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 3zlPQF5gF1zMcWc; Mon, 19 Feb 2018 13:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arkena.com; s=20150421; t=1519046165; bh=9WnLj2IZPxsPC46U5ks6rr4HlANV7aO8395tjV8uY3M=; h=From:To:Cc:Subject:Date:Message-Id; b=GF1QDEjHfAonL7J31Qlq5JYoW3ZqOi1DQ1ruj2Iy0sQXEgmLgD9Nj7ShqFWGrcCu+ iHzccvn78BBlVuRpZt3FmAq5fVvdNfKXusyZTc9mG+cFicEbTTiBbvtu4LzNJqQ47G 5qN7tfG3z8fZ4ljydOd3JEJUZB09wubEdffXJV+0= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id BF1D03FA71; Mon, 19 Feb 2018 16:05:53 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Feb 2018 14:16:04 +0100 Message-Id: <20180219131604.836-1-nicolas.gaullier@arkena.com> X-Mailer: git-send-email 2.15.0 Subject: [FFmpeg-devel] [PATCH v3 4/8] lavfi/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" --- 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