From patchwork Mon Feb 19 13:16:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaullier Nicolas X-Patchwork-Id: 7654 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.33 with SMTP id c30csp1507618jai; Mon, 19 Feb 2018 05:16:35 -0800 (PST) X-Google-Smtp-Source: AH8x227eEuN+wulAIzFnvuDGcfhOFs0I2FhBZVUlG/d3ReUnpKg2Uzvz1CIoEyqjyx7vWTFWRZiZ X-Received: by 10.223.164.14 with SMTP id d14mr9619572wra.182.1519046195353; Mon, 19 Feb 2018 05:16:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519046195; cv=none; d=google.com; s=arc-20160816; b=mcW7Pjy0VlHipT1PlMs1NGDoRHN5fvWIC3cO9BzL934hA95M1bxhtyHm3hBFu2APo4 UdXrMTazVhM3DNEtKMXNnO8B/i3IFFNnnaOUWbGAnrqoX4A1v7pzPRgD1m9uUgGc7TC/ x5iZPHCgENoxPTWJ21Ikzb2MY+nDgGyXA/YNhNPb5p1pfuBZOtsXl6Sa1bn/NwNHqX3X LACgAQkKUbmuJQCZvCaWOBKqhcy5RnNOAzM9Rg3jFHiMdWxFudXKS5O9pQH8fGZTuyGg Yy/MUR8swDitUblkjOp62LyZ9MMMt/VydOSXetO1ZSzS7SojYtlycsNS5J2ssTRFV8lx vljg== 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=A7//hmvEKSR1I1YqVW8CPaHRsiII9H+JKbiZeBTdTuE=; b=ogH6Lb8kzltSUv8lTNKIWFpG4PqrR5U6ISqIU350mzOCQ8uLuHBRyoDYd9nufrDzwx lFO5sTN8JxXcgTNf4+gXliel7+0E2hALbGAumFoFybeNBS5dc0cQA9+e2MujMYq0xlE1 9fPyYNPjm+H8s/uiWxnz2VZvQrFtOZdhslFdF4tuP75aFyjo0BoB9wyTRGq1l0UmcC5W FnhnKdrdu96yYzn6l5xyk+QDI9Wnrp46n+jJrzRFWAfeQ75jGQ1zQn7sjByilj1Md5Is jAgmdD8Y127UNwsG9NecMRv2/YxFgBdC9v+8KeTAEzSAXqdGzWkyyAjmphsS9nB3yTKL 8DhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@arkena.com header.s=20150421 header.b=U5CHWH7e; 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 x3si5494157wre.44.2018.02.19.05.16.35; Mon, 19 Feb 2018 05:16:35 -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=U5CHWH7e; 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 E118668A169; Mon, 19 Feb 2018 15:16:32 +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 9798A689F3C for ; Mon, 19 Feb 2018 15:16:31 +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 3zlPQm0ZV3zMcWc; Mon, 19 Feb 2018 13:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arkena.com; s=20150421; t=1519046192; bh=/Xgcg6cBqpZ6/pehSvuOCVSXSzTDrwry2GwAXNcLkG0=; h=From:To:Cc:Subject:Date:Message-Id; b=U5CHWH7e7FbX7VoecKxvK+qelepwFdWTgzfZJyD89K7CQIQOEKo0DAZFWWYBvVts2 ZNq6pHtC+4G4HaGiplsngj4CYD28JlDlpbyxxpYMFtTeBf2fOLWg6HmF6vSKuEMPOP GZ01WYQbC48ChFG5Df7ekaU7cvQSjAz4/XAdVH1w= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 10F063FA71; Mon, 19 Feb 2018 16:06:20 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Feb 2018 14:16:30 +0100 Message-Id: <20180219131630.7268-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" 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..6e321a5d97 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,