From patchwork Sun Dec 10 19:30:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Baecker X-Patchwork-Id: 6683 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp1975824jah; Sun, 10 Dec 2017 11:30:53 -0800 (PST) X-Google-Smtp-Source: AGs4zMamnTW2XcbjBmZRfQ18r3Gk25zG4QkXgB2D6U+Gye+8+7YHXTQewfR2H3u0OYvKIYKIsiP7 X-Received: by 10.28.18.145 with SMTP id 139mr8949668wms.43.1512934253775; Sun, 10 Dec 2017 11:30:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512934253; cv=none; d=google.com; s=arc-20160816; b=q0MRb4Pbel1VDuooL2CSokSN5A1eDYrSrhcHA/7QcH/YuYyQZF2bXeQIUtCNCBgrkN ANw1r5oqr9OyIWdc9WoTBBVtb7ZoMfBWafGcInOw1IoU6A3qO6lST9T06lMRAN0xhyCB yfNIUoEM5VREabjACnlws1YzwUqs7ID/X7jw1gQHrrOBTxGbEYQoRYcAyHGoDBVsxbk6 b+YDIFKljOWIlUL92sf0zHDY4sJlbXuG/YrXkmCqVF2IzLAgrKpF8tbM4YDf7sAP76jV dyyj3cGUXZLbUpuImCxUwSYWzgZrHVDpm7AhadM6/0iFwADqUaQcW/cuBS+RuzJyapaf JM3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:dkim-signature:delivered-to :arc-authentication-results; bh=n3I5igrJ3GjUGkTwcm0yKrzhLL09qkHtbmMDydiWR5s=; b=uHmOi+cveBuAvnpP5pxHCMxR6heBedm4htbK92FK1kQ4HIqLXy2dfMh45OhbuA6tRy a0SOdk71dzoUb3ZEYa+WPZbBsbbJbn7YCjs+gMwlvnpIwP3Lov062c/OHxSE42Pt0FJN 1GOrcmMWkbYQ1hkPcexD26WRdvBfnmM+GFzNWaG16m8pKetXoRnrHhes6LZqU/tuxZzF YJ09eggLNLVLWxzfZnj32qNI+kuiqif99MZKdIJe2x3GGr3gWmlwTiUoFZBRmpRkAgOQ 6lH76iBofGPMbDME+hDYPRjt18NAiXcsaK2jixPl/tR97zSU01/I1oicalhzjRN11QA1 XaLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=NR2pFKUW; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m1si4302733wmm.250.2017.12.10.11.30.53; Sun, 10 Dec 2017 11:30:53 -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=@gmail.com header.s=20161025 header.b=NR2pFKUW; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6927F68A621; Sun, 10 Dec 2017 21:30:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 48A9B68A5ED for ; Sun, 10 Dec 2017 21:30:39 +0200 (EET) Received: by mail-wm0-f42.google.com with SMTP id f206so10586644wmf.5 for ; Sun, 10 Dec 2017 11:30:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=ZJv47OAZjALIz8jlqGn5v06UTOjLdbxXC8wRmoRcqp0=; b=NR2pFKUWYcZgujeJUhfDuu1COFDqN6H+CQqkBdT7qXZ9vaKVG5UD/kZB+p67X0MpSy rJ+dmMTSApsLOyAD0OS+I92cnZA/xoLXiWZ+s9SU7SNEqfxUnDvnSedcYuMjL3hmoHYt 0nqfuaWpa/m8iXQbaBwPCWBdP+ZXBWbk7kxq2fDR6YpaDFBYSKI9ws5Ina62E5bFUGUt SSb9sjCGRnk+PjUYJKYvW81CiGKwnXrReCsijeatq2+WpR6wmdAKzlCSNfxmiizwrC76 Ql4QvFoNSyPEM8LomxW13x+Nhb+HUSgbtruCgug07CFCRMNIK+bqYZZ3plV/wsQz9gwL jnaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=ZJv47OAZjALIz8jlqGn5v06UTOjLdbxXC8wRmoRcqp0=; b=JcemYD7nGDensx6jlPNZ6LLEHV/BiEsLYL8Y3QUA+xbO7GUOxquYtjaxB/xUiXQzK5 uuOM8pafv+g0fsKZZ96hq7bOEeAX5VjozkvpyRa79V5e4KDZptqPW7ARNNbPX2OLqIYs mAG045JTtkjhfuJ77a+k0P2waSjBrmkpzp3XW0xmSk0OQuk8EUe/3LnmbQN+xLodw/4h Dfd4dEn16GPaE8lwq9JcEZxJmaAr8uX95UhUj7X0PiIE2ZZhmHUeCl8+YUsAd3Buzq32 LOWvQ6jPvheCYufBZm6NZCfGJQLupaVlYsDzIPdJSyI5483O1XLEjcD4pTFwOdRTEdrR JxOA== X-Gm-Message-State: AKGB3mJeSqOOf0ghfBT3UU2Dru9s3Xwf+lmNmJOWvneOF5VRxXJ51pps VP6+T3gglfczTjEaMMb0V/LvhQ== X-Received: by 10.28.67.68 with SMTP id q65mr8714289wma.26.1512934245955; Sun, 10 Dec 2017 11:30:45 -0800 (PST) Received: from [192.168.2.106] (p5B1468E9.dip0.t-ipconnect.de. [91.20.104.233]) by smtp.gmail.com with ESMTPSA id o63sm7065324wmb.4.2017.12.10.11.30.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Dec 2017 11:30:45 -0800 (PST) To: ffmpeg-devel@ffmpeg.org References: <9e2b12db-81f6-d80d-5ed7-8c07e308f9b8@gmail.com> From: Jonathan Baecker Message-ID: <1dc5e901-c4bf-c6b0-5d20-aecc94f4ceea@gmail.com> Date: Sun, 10 Dec 2017 20:30:44 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Subject: [FFmpeg-devel] [PATCH v3] libavfilter/vf_blackdetect.c 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Here the cleanup version from the patch. From b6b6e4ab885f9b35a6696492286e504a4b3d6d92 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 4 Dec 2017 16:05:48 +0100 Subject: [PATCH] unify blackdetect with af_silencedetect. Is more useful for monitoring streams. --- libavfilter/vf_blackdetect.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) -- 2.15.1 diff --git a/libavfilter/vf_blackdetect.c b/libavfilter/vf_blackdetect.c index 06ef9988d..92ea39b33 100644 --- a/libavfilter/vf_blackdetect.c +++ b/libavfilter/vf_blackdetect.c @@ -38,6 +38,7 @@ typedef struct BlackDetectContext { int64_t black_end; ///< pts end time of the last black picture int64_t last_picref_pts; ///< pts of the last input picture int black_started; + int black_match; double picture_black_ratio_th; double pixel_black_th; @@ -107,15 +108,20 @@ static int config_input(AVFilterLink *inlink) return 0; } -static void check_black_end(AVFilterContext *ctx) +static void check_black(AVFilterContext *ctx) { BlackDetectContext *blackdetect = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; - if ((blackdetect->black_end - blackdetect->black_start) >= blackdetect->black_min_duration) { + if (blackdetect->last_picref_pts - blackdetect->black_start >= blackdetect->black_min_duration && blackdetect->black_match == 0) { av_log(blackdetect, AV_LOG_INFO, - "black_start:%s black_end:%s black_duration:%s\n", - av_ts2timestr(blackdetect->black_start, &inlink->time_base), + "black_start:%s\n", + av_ts2timestr(blackdetect->black_start, &inlink->time_base)); + blackdetect->black_match = 1; + } + if (blackdetect->black_end - blackdetect->black_start >= blackdetect->black_min_duration && blackdetect->black_started == 1) { + av_log(blackdetect, AV_LOG_INFO, + "black_end:%s | black_duration:%s\n", av_ts2timestr(blackdetect->black_end, &inlink->time_base), av_ts2timestr(blackdetect->black_end - blackdetect->black_start, &inlink->time_base)); } @@ -131,7 +137,7 @@ static int request_frame(AVFilterLink *outlink) if (ret == AVERROR_EOF && blackdetect->black_started) { // FIXME: black_end should be set to last_picref_pts + last_picref_duration blackdetect->black_end = blackdetect->last_picref_pts; - check_black_end(ctx); + check_black(ctx); } return ret; } @@ -163,15 +169,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) if (!blackdetect->black_started) { /* black starts here */ blackdetect->black_started = 1; + blackdetect->black_match = 0; blackdetect->black_start = picref->pts; av_dict_set(&picref->metadata, "lavfi.black_start", av_ts2timestr(blackdetect->black_start, &inlink->time_base), 0); } + check_black(ctx); } else if (blackdetect->black_started) { /* black ends here */ - blackdetect->black_started = 0; blackdetect->black_end = picref->pts; - check_black_end(ctx); + check_black(ctx); + blackdetect->black_started = 0; av_dict_set(&picref->metadata, "lavfi.black_end", av_ts2timestr(blackdetect->black_end, &inlink->time_base), 0); }