]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_find_rect.c
avfilter/vf_psnr: remove unnecessary check
[ffmpeg] / libavfilter / vf_find_rect.c
index ea3b7aeee50108280707bfe059b335295a34d0e4..1a94655b6b19609e52f9b4ec76adbe3d9f92ca84 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 }
 };
 
@@ -185,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; i<foc->mipmaps; i++) {
@@ -206,21 +209,29 @@ 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",
+    av_log(ctx, AV_LOG_INFO, "Found at n=%"PRId64" 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;
 
+    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);
 }
@@ -292,7 +303,7 @@ static const AVFilterPad foc_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_vf_find_rect = {
+const AVFilter ff_vf_find_rect = {
     .name            = "find_rect",
     .description     = NULL_IF_CONFIG_SMALL("Find a user specified object."),
     .priv_size       = sizeof(FOCContext),