]> git.sesse.net Git - ffmpeg/commitdiff
avfilter/find_rect: add option to discard non-matching frames
authorGyan Doshi <ffmpeg@gyani.pro>
Thu, 1 Apr 2021 12:52:03 +0000 (18:22 +0530)
committerGyan Doshi <ffmpeg@gyani.pro>
Sun, 4 Apr 2021 05:17:09 +0000 (10:47 +0530)
Default is disabled.

doc/filters.texi
libavfilter/vf_find_rect.c

index 64878e15da3d02cc5eff7fe7a886f206a7e9f147..5e35fa64676e24a9650f15244ae068d5d387f98b 100644 (file)
@@ -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
index ea3b7aeee50108280707bfe059b335295a34d0e4..f9129cc140f85338837ebf850f9e8588093b4a45 100644 (file)
@@ -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",