From patchwork Tue Oct 8 03:54:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 15553 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D6CDD448F65 for ; Tue, 8 Oct 2019 06:58:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B0A7C687F4C; Tue, 8 Oct 2019 06:58:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C58106809BF for ; Tue, 8 Oct 2019 06:58:26 +0300 (EEST) Received: by mail-pf1-f174.google.com with SMTP id a2so9987217pfo.10 for ; Mon, 07 Oct 2019 20:58:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OwnjPPUO07YVwCW1NhfQzHZ9hwErZRCMLrbqkb052IQ=; b=LhM7ISIfvVP5VKVB9JD1yO9OWC8LiHF7zyzGaFqYvYakZCgM/Te+zAYCeFgKtfae30 zOacbeVuYqXG+K1RkvVXOJ9Nwm2pa/JE5USonyjzOxEz0JVSfW8UP2RFbsceAnm/f0Wo QDdbcBy9aOWFytuxW+xjZIdlbjzQ8v4QqKCTfAqhvc534tTfPIq1AlCmh1xlx3UBNq/R 9+RqQxCfvr0Y/CUGHBCqSBOeplnKzg3ZJCvhmY9D0jHpRTj/8c0fcf4ZGyQ5QDAOnrPn U8l5dWteRG/Rk9cng3PnDShwmDFCdi8MTgXGAbmT47nPLM7wFIEAHPzlnb8Jwm21Sa57 aZHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OwnjPPUO07YVwCW1NhfQzHZ9hwErZRCMLrbqkb052IQ=; b=qZ63fXFV7QVxJmr6ugtYF11bMG1PGrQp76EcjlgrVotdgnf8+UbHLMTNyFqJvVpZE/ +gbMqkv5wXhPkGCAgUotLTl8cW/NKtykjLtLs0HcvLPlfLY4ff6EHsLIrBylsLziLOeD fgu539+U8rv3CRB2wQMYYKsZFriabPk4713YJiuhRwvJXrcZUJj+6yVLgyNb/9Z+QTdQ tYmmSF9/0cUyRs8Z7k9OKkX8q9EoiltbAJ/OrcoFGqI0o+4rJ2CobM92pjgx9r+za+PL /28AlTvhe/EdmeShQmlFbVNJlr5zE/6BGEwBjRmU2Z2934VYR94vD/SoC47MfLkjf7rs 8ebg== X-Gm-Message-State: APjAAAWgyuLW+xYETbfS7Y9HMMy/RkobH2LKke+mkVlDxQ2X17DdAYcy i+uAvBRFnId8zfQBd1Sq6qnZy8Tx X-Google-Smtp-Source: APXvYqyg7eKGqglrki6Jt03eepynj5mQxXi8Xb5k737KMnszNrt4hj0acMkTtLDMJ6r9HjVSZeAdtw== X-Received: by 2002:a63:4d4b:: with SMTP id n11mr33741485pgl.409.1570507103572; Mon, 07 Oct 2019 20:58:23 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id r186sm18205535pfr.40.2019.10.07.20.58.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2019 20:58:22 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Oct 2019 11:54:28 +0800 Message-Id: <20191008035428.19474-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20190930152218.6860-1-lance.lmwang@gmail.com> References: <20190930152218.6860-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2] avfilter/vf_freezedetect: add discard option to force drop freezen frame 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang How to tested it, please try with the following command: ./ffmpeg -f lavfi -i "smptebars=duration=5:size=1280x720:rate=30,freezedetect=d=1:discard=0" -f null - frame= 150 fps=0.0 q=-0.0 Lsize=N/A time=00:00:05.00 bitrate=N/A speed= 234x ./ffmpeg -f lavfi -i "smptebars=duration=5:size=1280x720:rate=30,freezedetect=d=1:discard=1" -f null - frame= 30 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A speed=59.7x Signed-off-by: Limin Wang --- doc/filters.texi | 10 ++++++++++ libavfilter/vf_freezedetect.c | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/filters.texi b/doc/filters.texi index 333f502083..8aa7471f7e 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10678,6 +10678,9 @@ timestamp of the first frame of the freeze. The @code{lavfi.freezedetect.freeze_duration} and @code{lavfi.freezedetect.freeze_end} metadata keys are set on the first frame after the freeze. +In addition, you can choose to discard the freezen frames instead of report +by metadata. Please note the first few freezen frames (the detection interval) +won't be dropped for the filter doesn't buffer any frames. The filter accepts the following options: @@ -10689,6 +10692,13 @@ specified value) or as a difference ratio between 0 and 1. Default is -60dB, or @item duration, d Set freeze duration until notification (default is 2 seconds). + +@item discard +Set force to discard freezen frame. + 0: do nothing + 1: discard freezen frame + +Default is 0 @end table @anchor{frei0r} diff --git a/libavfilter/vf_freezedetect.c b/libavfilter/vf_freezedetect.c index cc086afee6..cc115eb521 100644 --- a/libavfilter/vf_freezedetect.c +++ b/libavfilter/vf_freezedetect.c @@ -45,6 +45,8 @@ typedef struct FreezeDetectContext { double noise; int64_t duration; ///< minimum duration of frozen frame until notification + + int discard; ///< 0: no discard, 1: discard freezen frame } FreezeDetectContext; #define OFFSET(x) offsetof(FreezeDetectContext, x) @@ -56,6 +58,7 @@ static const AVOption freezedetect_options[] = { { "noise", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, 1.0, V|F }, { "d", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, INT64_MAX, V|F }, { "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, INT64_MAX, V|F }, + { "discard", "set frame discard flag", OFFSET(discard), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, V|F }, {NULL} }; @@ -196,7 +199,10 @@ static int activate(AVFilterContext *ctx) return AVERROR(ENOMEM); } } - return ff_filter_frame(outlink, frame); + if (s->discard && s->frozen) { + av_frame_free(&frame); + } else + return ff_filter_frame(outlink, frame); } FF_FILTER_FORWARD_STATUS(inlink, outlink);