From patchwork Thu Jun 17 20:23:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 28572 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp976738iol; Thu, 17 Jun 2021 13:23:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJDFfwWaZetb4f3p0JRR4eMFG90Tpe8NqAxl9taVjueDr7LCiQAtji4MRByd3EPxTvWaSo X-Received: by 2002:a50:c8c3:: with SMTP id k3mr136717edh.318.1623961409593; Thu, 17 Jun 2021 13:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623961409; cv=none; d=google.com; s=arc-20160816; b=sdH9YmxY2CFlgIzASxwKVM0ZD7ooC2SyRCyJMoGET2l+Y9qsuwrfD91di1Q+HhPSZ3 qrJ1CTdg1OUvlAvX80HUAUw166MGy7AOtcwo6HsiRotLqo+cDCEy86qa73Nj4Uy5I5wc TLBLyFn+wWsi/L3BCMGW0OaYGNfJKTJLpg1SlRGvSaiWwBKvcMV7WuIk3xvxfwTCIYJO rGY428fCuUx5PpmcH277gBEU7JzYXlqDOckS8+Cs2ty9dDVasRuU8Kc9Ti/mSdaE1AS0 gRS+gHfWNQvKe0gTgppPltNtwOle6ztRCeu2Ub7xqL888iVPRrGqjT87eA61GwTXHNrv AuVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=k/7F1QlsJ8CtTyj6QPYnnZ+tBe5gYG07koW1iV25DO0=; b=hM3oQdPy4sUePTGmpCvLGRUttRmg7JWmA+AyoN+KTBypS8FzspduloCwxpJafaMI1J ysY0F3c67NECw+cT+1FI+kCgCInOW+JLVi56cQ7u4hEKmQCc388U023Lge0ArjMORUsX MDs5TX0UJyexVWqJq1wD9F5VWD9hV/Lul9KWoY3aUKf/BhSbMyXqzxf9CaTC95LOG673 J93Atz9pfhEt0wTD54lKggUMFI489bZ/Rq2XyVUR+IGJv6QnKDBGZZtImImcKuUbVb7H 528MUiJyf8jz/dtxVETMJ4YK66+rVtHCHRX+TVYV5Xz4EaRtX0fnmr2usnYioMFybPvI FAsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=KSb3lozt; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rothenpieler.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w12si6672262eds.6.2021.06.17.13.23.29; Thu, 17 Jun 2021 13:23:29 -0700 (PDT) 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=@rothenpieler.org header.s=mail header.b=KSb3lozt; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rothenpieler.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9749B689767; Thu, 17 Jun 2021 23:23:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [136.243.74.85]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F1C68680C82 for ; Thu, 17 Jun 2021 23:23:19 +0300 (EEST) Received: from Kryux.localdomain (unknown [87.123.110.32]) by btbn.de (Postfix) with ESMTPSA id 53916155A19; Thu, 17 Jun 2021 22:23:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1623961399; bh=O/anuEa/SmHKGVtly/JaRJENnvr/bpMBAaHxNOBk3fA=; h=From:To:Cc:Subject:Date; b=KSb3lozt6t7ryjAwIu06IR3fhu30Uh6ylBst2LPK07g2ggFtFBF0hi2yY1gZ4hBmv n+IkVF/sG1QCW6WElmmiZZVYx+G+LLvE2ZDLQz6eA4bnig9V/4zWO/QSi3zloFJ1VW wMs6LwvU4XnCVWcysASy9oJvZX/b8uFLz6pwR1CMKcyfPwygjpeZdCIyggQ3PvOg6M o1ioGUuLwElNNQBHpup8YQa84WNgUnAY/Xl/TyYVFE5Ii76EewPtvi5j3mH6wXe55X 3gTI39luTYMp6LAbqYZbnjJoPSW4hKMVZjTn0uqdZU1SDmbow95ab4Yaivf3PIIkRZ 89N4cmpHcAFmA== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Jun 2021 22:23:04 +0200 Message-Id: <20210617202304.15639-1-timo@rothenpieler.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/select: evaluate silencedetect metadata X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Timo Rothenpieler Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: kai4sxVyG5O9 --- doc/filters.texi | 6 ++++++ libavfilter/f_select.c | 18 ++++++++++++++++++ libavfilter/version.h | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/filters.texi b/doc/filters.texi index da8f7d7726..db6ecd7c2a 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -5404,6 +5404,7 @@ Set sidechain gain. Default is 1. Range is from 0.015625 to 64. This filter supports the all above options as @ref{commands}. +@anchor{silencedetect} @section silencedetect Detect silence in an audio stream. @@ -25564,6 +25565,11 @@ missing. That basically means that an input frame is selected if its pts is within the interval set by the concat demuxer. +@item silence_detected +Evaluates the metadata added to frames by the @ref{silencedetect} filter. +The @var{silence_detected} variable is -1 if silence was detected for the current +frame, 0 otherwise. + @end table The default value of the select expression is "1". diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c index f0468078e8..1e655290f4 100644 --- a/libavfilter/f_select.c +++ b/libavfilter/f_select.c @@ -86,6 +86,8 @@ static const char *const var_names[] = { "concatdec_select", ///< frame is within the interval set by the concat demuxer + "silence_detected", ///< silencedetect detected silence for this frame + NULL }; @@ -138,6 +140,8 @@ enum var_name { VAR_CONCATDEC_SELECT, + VAR_SILENCE_DETECTED, + VAR_VARS_NB }; @@ -157,6 +161,7 @@ typedef struct SelectContext { double select; int select_out; ///< mark the selected output pad index int nb_outputs; + int silence_detected; } SelectContext; #define OFFSET(x) offsetof(SelectContext, x) @@ -325,6 +330,18 @@ static double get_concatdec_select(AVFrame *frame, int64_t pts) return NAN; } +static double get_silence_detected(SelectContext *select, AVFrame *frame) +{ + AVDictionary *metadata = frame->metadata; + AVDictionaryEntry *start = av_dict_get(metadata, "lavfi.silence_start", NULL, 0); + AVDictionaryEntry *end = av_dict_get(metadata, "lavfi.silence_end", NULL, 0); + if (start) + select->silence_detected = -1; + if (end) + select->silence_detected = 0; + return select->silence_detected; +} + static void select_frame(AVFilterContext *ctx, AVFrame *frame) { SelectContext *select = ctx->priv; @@ -342,6 +359,7 @@ static void select_frame(AVFilterContext *ctx, AVFrame *frame) select->var_values[VAR_POS] = frame->pkt_pos == -1 ? NAN : frame->pkt_pos; select->var_values[VAR_KEY] = frame->key_frame; select->var_values[VAR_CONCATDEC_SELECT] = get_concatdec_select(frame, av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q)); + select->var_values[VAR_SILENCE_DETECTED] = get_silence_detected(select, frame); switch (inlink->type) { case AVMEDIA_TYPE_AUDIO: diff --git a/libavfilter/version.h b/libavfilter/version.h index 5052681653..fbb81ef31c 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -31,7 +31,7 @@ #define LIBAVFILTER_VERSION_MAJOR 8 #define LIBAVFILTER_VERSION_MINOR 0 -#define LIBAVFILTER_VERSION_MICRO 102 +#define LIBAVFILTER_VERSION_MICRO 103 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \