aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-12-30 21:02:34 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-12-31 00:33:33 +0100
commita288d08d84f66c74984ebc9cc9f2b9f930ef3fdd (patch)
treeb98308d8f67b4ce1f6193b12742babc824829a92
parent081567397e3c585b39c5815e1ed6b45760a42f15 (diff)
downloadffmpeg-a288d08d84f66c74984ebc9cc9f2b9f930ef3fdd.tar.gz
avfilter/vf_cropdetect: adjust Default threshold based on bit depth
Also allow specifying thresholds that are bit depth independant Previous version reviewed by: Reimar Döffinger <Reimar.Doeffinger@gmx.de> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavfilter/vf_cropdetect.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index dd237efc01..e8492cd1f1 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -35,7 +35,7 @@
typedef struct CropDetectContext {
const AVClass *class;
int x1, y1, x2, y2;
- int limit;
+ float limit;
int round;
int reset_count;
int frame_nb;
@@ -127,7 +127,7 @@ static av_cold int init(AVFilterContext *ctx)
s->frame_nb = -2;
- av_log(ctx, AV_LOG_VERBOSE, "limit:%d round:%d reset_count:%d\n",
+ av_log(ctx, AV_LOG_VERBOSE, "limit:%f round:%d reset_count:%d\n",
s->limit, s->round, s->reset_count);
return 0;
@@ -137,9 +137,12 @@ static int config_input(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
CropDetectContext *s = ctx->priv;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
- av_image_fill_max_pixsteps(s->max_pixsteps, NULL,
- av_pix_fmt_desc_get(inlink->format));
+ av_image_fill_max_pixsteps(s->max_pixsteps, NULL, desc);
+
+ if (s->limit < 1.0)
+ s->limit *= (1 << (desc->comp[0].depth_minus1 + 1)) - 1;
s->x1 = inlink->w - 1;
s->y1 = inlink->h - 1;
@@ -160,6 +163,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
int w, h, x, y, shrink_by;
AVDictionary **metadata;
int outliers, last_y;
+ int limit = round(s->limit);
// ignore first 2 frames - they may be empty
if (++s->frame_nb > 0) {
@@ -177,7 +181,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
#define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN) \
outliers = 0;\
for (last_y = y = FROM; NOEND; y = y INC) {\
- if (checkline(ctx, frame->data[0] + STEP0 * y, STEP1, LEN, bpp) > s->limit) {\
+ if (checkline(ctx, frame->data[0] + STEP0 * y, STEP1, LEN, bpp) > limit) {\
if (++outliers > s->max_outliers) { \
DST = last_y;\
break;\
@@ -238,7 +242,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
static const AVOption cropdetect_options[] = {
- { "limit", "Threshold below which the pixel is considered black", OFFSET(limit), AV_OPT_TYPE_INT, { .i64 = 24 }, 0, 65535, FLAGS },
+ { "limit", "Threshold below which the pixel is considered black", OFFSET(limit), AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, FLAGS },
{ "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 },