From patchwork Tue Feb 13 17:21:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaullier Nicolas X-Patchwork-Id: 7585 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp1297386jai; Tue, 13 Feb 2018 09:21:24 -0800 (PST) X-Google-Smtp-Source: AH8x224IEJyEtNAydtAAH3nqgrzDNRmOOQoPPc+wxN7qvNgCCwZQXikdvC/GeJBlYdEc36rQNAls X-Received: by 10.28.51.12 with SMTP id z12mr1863536wmz.16.1518542484239; Tue, 13 Feb 2018 09:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518542484; cv=none; d=google.com; s=arc-20160816; b=vb+oB38qF8r4p2QBX43pNcw2Zexv9NmPfisUvX8sBx/FdzaDRQqMGUJ32qiEQQpfC2 NafntkobAI0WVb8T2NyC7po90Alzw03iZ62iC09nc/i7hsmix7vdHvAGpbK5+1GRwA9V caIa0IHvKUsmcHfsWJmePD3VWq8GvP1WLhcPWjsr7GHRPg8Tdr8pAWdNSGTZgWnjrzsM ZiInE6p+OgkA8lvA7Y1yj++3DNx6DY/TsOA0CRrr21dsiBjEz6CizKyVo4iZCvnhBkEU vrRX70pZljE2Kw6Ce0TXDkNCo9FN6K/cW8JGVCbvu6KA+f1L/t/km39rejBIpOvY8HSa 3k0Q== 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=MG4XHz/mfsWl/XQ9Eqtg2sDMe5Zk115rzpLxeVR5r+s=; b=k3c7Ni3QlsLFby1pDMv/JdU15Oe1DhhCClJFU0QDt6Nse2K1C5hiZXLM1AgIdslA9P W7VD+OUAPQ69JtXcG8ebLKUYioZUdlOfuJhpApcuANtfI2OjA5naBn+n8tJbFE68qqqi EvdB2zJQMgWsDngxhs6bRamGyxRMgpsnO7vrk3XmXLe08IgNAwPQWwvqEpIy6WdSxMAW 0/leB3JepWhPIWLuO3IYI6LSGpKFtLA4UuPFKZDIEGjhpWAGX9QgP//Up5ykgAYRNRvW pwWDcZTbTKC1nleWc7SW2hw4Vhk8Iqb9yO9aUPAfCVeUAA3o5tKUrqGK0Yo3KdhNUiZu ZYYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@arkena.com header.s=20150421 header.b=M/HyRafS; 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 r28si3265757wrc.408.2018.02.13.09.21.23; Tue, 13 Feb 2018 09:21:24 -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=M/HyRafS; 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 E4F5A689BE4; Tue, 13 Feb 2018 19:21:11 +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 5D128687988 for ; Tue, 13 Feb 2018 19:21: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 3zgq7v6jzYzMcWL; Tue, 13 Feb 2018 17:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arkena.com; s=20150421; t=1518542475; bh=rkOPXp43UQ110MwE8zI02tth0TT0wJHt8jQ9eA/7NCM=; h=From:To:Cc:Subject:Date:Message-Id; b=M/HyRafSeLDGzFhcRNhxJpfcjTI3DY2GLNhuKwVbjwcRv0776QE09ej85vTzelHUS LYuV+HwhWugAkLWcPt+fALOvlrBnTzYPvq7WbyYocl2l2H3ynVmKhw8lGK/SBbjoEv Bao+mW22Q6Ea0+YPMDz1jWtmQv8zypruypZsCSA8= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 2A7D53FA71; Tue, 13 Feb 2018 20:11:57 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Feb 2018 18:21:05 +0100 Message-Id: <20180213172105.5140-1-nicolas.gaullier@arkena.com> X-Mailer: git-send-email 2.15.0 Subject: [FFmpeg-devel] [PATCH v3 6/8] lavfi/silencedetect: Fix missing log at eos 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 Fixes ticket #6968 --- libavfilter/af_silencedetect.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c index 8973049fe5..723136c2a8 100644 --- a/libavfilter/af_silencedetect.c +++ b/libavfilter/af_silencedetect.c @@ -41,7 +41,9 @@ typedef struct SilenceDetectContext { 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) + int64_t frame_end; ///< pts of the end of the current frame (used to compute duration of silence at EOS) int last_sample_rate; ///< last sample rate to check for sample rate changes + AVRational time_base; ///< time_base void (*silencedetect)(struct SilenceDetectContext *s, AVFrame *insamples, int nb_samples, int64_t nb_samples_notify, @@ -92,13 +94,16 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, } } else { if (s->start[channel] > INT64_MIN) { - int64_t end_pts = insamples->pts + av_rescale_q(current_sample / s->channels, - (AVRational){ 1, s->last_sample_rate }, time_base); + int64_t end_pts = insamples ? insamples->pts + av_rescale_q(current_sample / s->channels, + (AVRational){ 1, s->last_sample_rate }, time_base) + : s->frame_end; int64_t duration_ts = end_pts - s->start[channel]; - set_meta(insamples, s->mono ? channel + 1 : 0, "silence_end", - av_ts2timestr(end_pts, &time_base)); - set_meta(insamples, s->mono ? channel + 1 : 0, "silence_duration", - av_ts2timestr(duration_ts, &time_base)); + if (insamples) { + set_meta(insamples, s->mono ? channel + 1 : 0, "silence_end", + av_ts2timestr(end_pts, &time_base)); + set_meta(insamples, s->mono ? channel + 1 : 0, "silence_duration", + av_ts2timestr(duration_ts, &time_base)); + } if (s->mono) av_log(s, AV_LOG_INFO, "channel: %d | ", channel); av_log(s, AV_LOG_INFO, "silence_end: %s | silence_duration: %s\n", @@ -177,6 +182,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) s->nb_null_samples[c] = srate * s->nb_null_samples[c] / s->last_sample_rate; } s->last_sample_rate = srate; + s->time_base = inlink->time_base; + s->frame_end = insamples->pts + av_rescale_q(insamples->nb_samples, + (AVRational){ 1, s->last_sample_rate }, inlink->time_base); // TODO: document metadata s->silencedetect(s, insamples, nb_samples, nb_samples_notify, @@ -218,6 +226,18 @@ static int query_formats(AVFilterContext *ctx) return ff_set_common_samplerates(ctx, formats); } +static av_cold void uninit(AVFilterContext *ctx) +{ + SilenceDetectContext *s = ctx->priv; + int c; + + for (c = 0; c < s->independant_channels; c++) + if (s->start[c] > INT64_MIN) + update(s, NULL, 0, c, 0, s->time_base); + av_freep(&s->nb_null_samples); + av_freep(&s->start); +} + static const AVFilterPad silencedetect_inputs[] = { { .name = "default", @@ -241,6 +261,7 @@ AVFilter ff_af_silencedetect = { .description = NULL_IF_CONFIG_SMALL("Detect silence."), .priv_size = sizeof(SilenceDetectContext), .query_formats = query_formats, + .uninit = uninit, .inputs = silencedetect_inputs, .outputs = silencedetect_outputs, .priv_class = &silencedetect_class,