[FFmpeg-cvslog] avfilter/vf_cropdetect: add max_outliers parameter
Michael Niedermayer
git at videolan.org
Sun Dec 28 18:12:04 CET 2014
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Dec 27 04:27:07 2014 +0100| [3b1f747238d6ca4bfaeebf1ab68892fb029623d7] | committer: Michael Niedermayer
avfilter/vf_cropdetect: add max_outliers parameter
Fixes Ticket3030
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3b1f747238d6ca4bfaeebf1ab68892fb029623d7
---
libavfilter/vf_cropdetect.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index 0ba2a38..c2c1bc4 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 }
};
More information about the ffmpeg-cvslog
mailing list