From patchwork Thu Apr 1 13:18:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 26684 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 E8F1244ABCD for ; Thu, 1 Apr 2021 16:18:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BBFD668A5B5; Thu, 1 Apr 2021 16:18:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4AA1E689BDC for ; Thu, 1 Apr 2021 16:18:50 +0300 (EEST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4FB3fd6gRbzQjmJ for ; Thu, 1 Apr 2021 15:18:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id AWJ9O1qfCgcc for ; Thu, 1 Apr 2021 15:18:46 +0200 (CEST) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Apr 2021 18:48:30 +0530 Message-Id: <20210401131832.9614-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.26 / 15.00 / 15.00 X-Rspamd-Queue-Id: E82BC4AF X-Rspamd-UID: 9c2cd7 Subject: [FFmpeg-devel] [PATCH 1/3] avfilter/find_rect: improve logging 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" Log now indicates timestamps of frames where a match is made. Loglevel is changed to INFO since the user specifically wants this info. --- libavfilter/vf_find_rect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c index b5f8fbcba6..ea3b7aeee5 100644 --- a/libavfilter/vf_find_rect.c +++ b/libavfilter/vf_find_rect.c @@ -209,7 +209,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) return ff_filter_frame(ctx->outputs[0], in); } - av_log(ctx, AV_LOG_DEBUG, "Found at %d %d score %f\n", best_x, best_y, best_score); + av_log(ctx, AV_LOG_INFO, "Found at n=%lld pts_time=%f x=%d y=%d with score=%f\n", + inlink->frame_count_out, TS2D(in->pts) * av_q2d(inlink->time_base), + best_x, best_y, best_score); foc->last_x = best_x; foc->last_y = best_y; From patchwork Thu Apr 1 13:18:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 26685 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 45D7944ABCD for ; Thu, 1 Apr 2021 16:18:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 229E768A708; Thu, 1 Apr 2021 16:18:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0CFA668A64D for ; Thu, 1 Apr 2021 16:18:50 +0300 (EEST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4FB3ff50qRzQjwV for ; Thu, 1 Apr 2021 15:18:50 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id 7rVhgUzQUNLk for ; Thu, 1 Apr 2021 15:18:47 +0200 (CEST) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Apr 2021 18:48:31 +0530 Message-Id: <20210401131832.9614-2-ffmpeg@gyani.pro> In-Reply-To: <20210401131832.9614-1-ffmpeg@gyani.pro> References: <20210401131832.9614-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.26 / 15.00 / 15.00 X-Rspamd-Queue-Id: BF530186A X-Rspamd-UID: 493e43 Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/find_rect: add option to discard non-matching frames 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" Default is disabled. --- doc/filters.texi | 3 +++ libavfilter/vf_find_rect.c | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/filters.texi b/doc/filters.texi index 64878e15da..5e35fa6467 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12139,6 +12139,9 @@ Number of mipmaps, default is 3. @item xmin, ymin, xmax, ymax Specifies the rectangle in which to search. + +@item discard +Discard frames where object is not detected. Default is disabled. @end table @subsection Examples diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c index ea3b7aeee5..f9129cc140 100644 --- a/libavfilter/vf_find_rect.c +++ b/libavfilter/vf_find_rect.c @@ -40,6 +40,7 @@ typedef struct FOCContext { AVFrame *obj_frame; AVFrame *needle_frame[MAX_MIPMAPS]; AVFrame *haystack_frame[MAX_MIPMAPS]; + int discard; } FOCContext; #define OFFSET(x) offsetof(FOCContext, x) @@ -52,6 +53,7 @@ static const AVOption find_rect_options[] = { { "ymin", "", OFFSET(ymin), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS }, { "xmax", "", OFFSET(xmax), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS }, { "ymax", "", OFFSET(ymax), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS }, + { "discard", "", OFFSET(discard), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { NULL } }; @@ -206,7 +208,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } if (best_score > foc->threshold) { - return ff_filter_frame(ctx->outputs[0], in); + if (foc->discard) { + av_frame_free(&in); + return 0; + } else { + return ff_filter_frame(ctx->outputs[0], in); + } } av_log(ctx, AV_LOG_INFO, "Found at n=%lld pts_time=%f x=%d y=%d with score=%f\n", From patchwork Thu Apr 1 13:18:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 26686 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 7CEE544ABCD for ; Thu, 1 Apr 2021 16:18:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5112168A6F9; Thu, 1 Apr 2021 16:18:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A91C468A6E7 for ; Thu, 1 Apr 2021 16:18:51 +0300 (EEST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4FB3fg2KH9zQjmP for ; Thu, 1 Apr 2021 15:18:51 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id NPjAtR9CzNcn for ; Thu, 1 Apr 2021 15:18:48 +0200 (CEST) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Apr 2021 18:48:32 +0530 Message-Id: <20210401131832.9614-3-ffmpeg@gyani.pro> In-Reply-To: <20210401131832.9614-1-ffmpeg@gyani.pro> References: <20210401131832.9614-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-MBO-SPAM-Probability: *** X-Rspamd-Score: 3.26 / 15.00 / 15.00 X-Rspamd-Queue-Id: 58D5E186B X-Rspamd-UID: 8e13d8 Subject: [FFmpeg-devel] [PATCH 3/3] avfilter/find_rect: write score to metadata 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" --- libavfilter/vf_find_rect.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c index f9129cc140..b6f5a1be29 100644 --- a/libavfilter/vf_find_rect.c +++ b/libavfilter/vf_find_rect.c @@ -187,6 +187,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) float best_score; int best_x, best_y; int i; + char buf[32]; foc->haystack_frame[0] = av_frame_clone(in); for (i=1; imipmaps; i++) { @@ -222,12 +223,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) foc->last_x = best_x; foc->last_y = best_y; + snprintf(buf, sizeof(buf), "%f", best_score); + av_frame_make_writable(in); av_dict_set_int(&in->metadata, "lavfi.rect.w", foc->obj_frame->width, 0); av_dict_set_int(&in->metadata, "lavfi.rect.h", foc->obj_frame->height, 0); av_dict_set_int(&in->metadata, "lavfi.rect.x", best_x, 0); av_dict_set_int(&in->metadata, "lavfi.rect.y", best_y, 0); + av_dict_set(&in->metadata, "lavfi.rect.score", buf, 0); return ff_filter_frame(ctx->outputs[0], in); }