[FFmpeg-devel] [PATCH] Fix vf_cropdetect returning negative rectangles

Michael Niedermayer michaelni at gmx.at
Tue Sep 9 01:57:30 CEST 2014


On Tue, Sep 02, 2014 at 02:20:40PM -0700, hjiodjf 97xgw46 wrote:
> The cropdetect filter is prone to reporting negative-sized rectangles,
> particularly for dark images. This patch adjusts the limits of the
> filter loops, preventing the left/right and top/bottom offsets from
> crossing each other, so that such a zero-sized rectangle is reported
> instead of a negative one. This improves the reliability of using
> cropdetect to find a maximum bounding rectangle.

>  vf_cropdetect.c |   12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 07877d20186041d6ad44359d10c2c079ba954d06  0001-Prevent-vf_cropdetect-from-returning-negative-rectan.patch
> From 971e0ec056e6200064598dbca49c18b8653e08d4 Mon Sep 17 00:00:00 2001
> From: tue46wsdgxfjrt <jfbvxt at gmail.com>
> Date: Tue, 2 Sep 2014 13:57:45 -0700
> Subject: [PATCH] Prevent vf_cropdetect from returning negative rectangle
>  sizes.
> 
> ---
>  libavfilter/vf_cropdetect.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
> index f85a0bb..f554ff8 100644
> --- a/libavfilter/vf_cropdetect.c
> +++ b/libavfilter/vf_cropdetect.c
> @@ -106,8 +106,8 @@ static int config_input(AVFilterLink *inlink)
>  
>      s->x1 = inlink->w - 1;
>      s->y1 = inlink->h - 1;
> -    s->x2 = 0;
> -    s->y2 = 0;
> +    s->x2 = inlink->w - 1;
> +    s->y2 = inlink->h - 1;
>  
>      return 0;
>  }
> @@ -131,8 +131,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>          if (s->reset_count > 0 && s->frame_nb > s->reset_count) {
>              s->x1 = frame->width  - 1;
>              s->y1 = frame->height - 1;
> -            s->x2 = 0;
> -            s->y2 = 0;
> +            s->x2 = frame->width  - 1;
> +            s->y2 = frame->height - 1;
>              s->frame_nb = 1;
>          }
>  

> @@ -143,7 +143,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>              }
>          }
>  
> -        for (y = frame->height - 1; y > s->y2; y--) {
> +        for (y = frame->height - 1; y >= s->y1; y--) {
>              if (checkline(ctx, frame->data[0] + frame->linesize[0] * y, bpp, frame->width, bpp) > s->limit) {
>                  s->y2 = y;
>                  break;

this isnt correct
nor is the change below
both will result in incorrect combination of croping rectangles over
multiple frames



> @@ -157,7 +157,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>              }
>          }
>  
> -        for (y = frame->width - 1; y > s->x2; y--) {
> +        for (y = frame->width - 1; y >= s->x1; y--) {
>              if (checkline(ctx, frame->data[0] + bpp*y, frame->linesize[0], frame->height, bpp) > s->limit) {
>                  s->x2 = y;
>                  break;
> -- 
> 1.8.5.2 (Apple Git-48)
> 

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If a bugfix only changes things apparently unrelated to the bug with no
further explanation, that is a good sign that the bugfix is wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140909/d47ef225/attachment.asc>


More information about the ffmpeg-devel mailing list