From patchwork Mon Feb 12 09:48:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaullier Nicolas X-Patchwork-Id: 7567 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp3792510jai; Mon, 12 Feb 2018 01:49:46 -0800 (PST) X-Google-Smtp-Source: AH8x226u/15lGiSSLn9QrYksr0flMlnz2ni62A8PNlQnPwh76SLBRHYGncPySNpLemAONtgh4vE9 X-Received: by 10.223.209.80 with SMTP id b16mr9418565wri.86.1518428986711; Mon, 12 Feb 2018 01:49:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518428986; cv=none; d=google.com; s=arc-20160816; b=NL0kWvWLcLV1kWtYEVJHlNf1dyZLAI9uQM4JwoktUK2V1ey/jWKNRnMYnCMzzk3Cmm oML0LDt7VMZoOeWaFN4UwNK4+wn6R/ZEuZkhE6oU44HEvDIT7bzZi5Z255T9edKN+4ep b+aweoHzZlW1dCEEE4L4eusst3oX47mMa2qorTrFvBV/z1YL8mK9OMu4yeiyhmu8uZ7X di0ZDLi1SfeHXk194Ww7yKEtDjZhK8Hdzp28w0nCRy2kegshCD9D2O3fHNfdUoNmnX6I +aYSckHA+sn91eDDjsKoUaTd7MAI6Nfu4J7z6u0uWqMKotKiuqGrBZurCr7IC7CnnBRE 1Ryg== 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=g7CGqoQSLBMUfgIEo/ZdNbil7uC9D2y6Hp3xzo+hWPs=; b=KQZDMz2owqAY+7JwrlumYDRmrs1dp0WeLc22RqAELhJqFnvC9WyYTcJtPvspMZj9if ehw26bhA5MILIHaMOekggoFhF8n5Ny2/SHf4PVaDmlgpmWtqjZsRH6n9XDQcHOco0N9E XOfJMpOa+JaryeytZdkMI6oecQGYoWTx7Wu171zRGYs3mj3Bj+OFvgzM+PAZT44ITZtK xwWMGrLU2v2B6fMyhbSct8H6AajO0BXm5sduBOCQG5BY3nNQ7j+/JgWh3fYLxn2cVyke LJfSe3UvJZ7NqO+B2JNpEIBjvQRk5kmUu4zm5dAoFJxKk6PfJ1GmqYN4ErmUJv/s043y Emug== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@arkena.com header.s=20150421 header.b=iflJv6OF; 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 i5si5630439wre.295.2018.02.12.01.49.46; Mon, 12 Feb 2018 01:49:46 -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=iflJv6OF; 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 82373689AFD; Mon, 12 Feb 2018 11:48:36 +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 CAADC689A46 for ; Mon, 12 Feb 2018 11:48: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 3zg1841rwjzMcYp; 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=Djcp3pszSgBXCIih5cQ+isxyrveJ2/jndkWHb815ino=; h=From:To:Cc:Subject:Date:Message-Id; b=iflJv6OFw+zMBtGun7b9Mumi/xfV1EO040KKl3sfbYoTlBgQn8MNG5dIoKZyiTJhg IoKDzNmwYQ2edgFaYsEiH+s8KOBndo1IQ0iCp51hJNCMEtVcWxxKp8AdZWl3PKMZQ5 qD5Gl/31k0W8beqGhGwsiqU+68WheOYGVcdq7gUE= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 7C9003FA74; Mon, 12 Feb 2018 12:39:29 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Feb 2018 10:48:28 +0100 Message-Id: <20180212094830.9304-6-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 6/8] avfilter/silencedetect: fix for ticket 6968 Fix missing log of silence_end at end of stream 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 | 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, &stime_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,