aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_cropdetect.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-12-27 04:27:07 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-12-28 18:10:49 +0100
commit3b1f747238d6ca4bfaeebf1ab68892fb029623d7 (patch)
treed47a66234cfec2aa797ec4f5a5865a076a312c4b /libavfilter/vf_cropdetect.c
parent627f5658b68f2a0fb51b3e7e512a88817a4409c3 (diff)
downloadffmpeg-3b1f747238d6ca4bfaeebf1ab68892fb029623d7.tar.gz
avfilter/vf_cropdetect: add max_outliers parameter
Fixes Ticket3030 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter/vf_cropdetect.c')
-rw-r--r--libavfilter/vf_cropdetect.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index 0ba2a38b0e..c2c1bc4698 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -40,6 +40,7 @@ typedef struct CropDetectContext {
int reset_count;
int frame_nb;
int max_pixsteps[4];
+ int max_outliers;
} CropDetectContext;
static int query_formats(AVFilterContext *ctx)
@@ -123,6 +124,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
int bpp = s->max_pixsteps[0];
int w, h, x, y, shrink_by;
AVDictionary **metadata;
+ int outliers, last_y;
// ignore first 2 frames - they may be empty
if (++s->frame_nb > 0) {
@@ -138,17 +140,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
}
#define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN) \
- for (y = FROM; NOEND; INC) {\
+ outliers = 0;\
+ for (last_y = y = FROM; NOEND; y = y INC) {\
if (checkline(ctx, frame->data[0] + STEP0 * y, STEP1, LEN, bpp) > s->limit) {\
- DST = y;\
- break;\
- }\
+ if (++outliers > s->max_outliers) { \
+ DST = last_y;\
+ break;\
+ }\
+ } else\
+ last_y = y INC;\
}
- FIND(s->y1, 0, y < s->y1, y++, frame->linesize[0], bpp, frame->width);
- FIND(s->y2, frame->height - 1, y > FFMAX(s->y2, s->y1), y--, frame->linesize[0], bpp, frame->width);
- FIND(s->x1, 0, y < s->x1, y++, bpp, frame->linesize[0], frame->height);
- FIND(s->x2, frame->width - 1, y > FFMAX(s->x2, s->x1), y--, bpp, frame->linesize[0], frame->height);
+ FIND(s->y1, 0, y < s->y1, +1, frame->linesize[0], bpp, frame->width);
+ FIND(s->y2, frame->height - 1, y > FFMAX(s->y2, s->y1), -1, frame->linesize[0], bpp, frame->width);
+ FIND(s->x1, 0, y < s->x1, +1, bpp, frame->linesize[0], frame->height);
+ FIND(s->x2, frame->width - 1, y > FFMAX(s->x2, s->x1), -1, bpp, frame->linesize[0], frame->height);
// round x and y (up), important for yuv colorspaces
@@ -201,6 +207,7 @@ static const AVOption cropdetect_options[] = {
{ "round", "Value by which the width/height should be divisible", OFFSET(round), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX, FLAGS },
{ "reset", "Recalculate the crop area after this many frames", OFFSET(reset_count), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ "reset_count", "Recalculate the crop area after this many frames",OFFSET(reset_count),AV_OPT_TYPE_INT,{ .i64 = 0 }, 0, INT_MAX, FLAGS },
+ { "max_outliers", "Threshold count of outliers", OFFSET(max_outliers),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ NULL }
};