1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-15 14:13:16 +02:00

avfilter/find_rect: add option to discard non-matching frames

Default is disabled.
This commit is contained in:
Gyan Doshi
2021-04-01 18:22:03 +05:30
parent aff23c3474
commit abdafca9ad
2 changed files with 11 additions and 1 deletions

View File

@@ -12139,6 +12139,9 @@ Number of mipmaps, default is 3.
@item xmin, ymin, xmax, ymax @item xmin, ymin, xmax, ymax
Specifies the rectangle in which to search. Specifies the rectangle in which to search.
@item discard
Discard frames where object is not detected. Default is disabled.
@end table @end table
@subsection Examples @subsection Examples

View File

@@ -40,6 +40,7 @@ typedef struct FOCContext {
AVFrame *obj_frame; AVFrame *obj_frame;
AVFrame *needle_frame[MAX_MIPMAPS]; AVFrame *needle_frame[MAX_MIPMAPS];
AVFrame *haystack_frame[MAX_MIPMAPS]; AVFrame *haystack_frame[MAX_MIPMAPS];
int discard;
} FOCContext; } FOCContext;
#define OFFSET(x) offsetof(FOCContext, x) #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 }, { "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 }, { "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 }, { "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 } { NULL }
}; };
@@ -206,8 +208,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
} }
if (best_score > foc->threshold) { if (best_score > foc->threshold) {
if (foc->discard) {
av_frame_free(&in);
return 0;
} else {
return ff_filter_frame(ctx->outputs[0], in); 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=%lld pts_time=%f x=%d y=%d with score=%f\n",
inlink->frame_count_out, TS2D(in->pts) * av_q2d(inlink->time_base), inlink->frame_count_out, TS2D(in->pts) * av_q2d(inlink->time_base),