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

Michael Niedermayer michaelni at gmx.at
Wed Sep 10 22:24:38 CEST 2014


On Wed, Sep 10, 2014 at 11:45:48AM -0700, hjiodjf 97xgw46 wrote:
> On Wed, Sep 10, 2014 at 11:26 AM, Michael Niedermayer <michaelni at gmx.at> wrote:
> > On Wed, Sep 10, 2014 at 10:35:23AM -0700, hjiodjf 97xgw46 wrote:
> >> It appears to work for me:
> >
> >
> > ./ffmpeg -i matrixbench_mpeg2.mpg -vframes 5 -an -vf "cropdetect" -f null -
> >
> > before patch:
> > [Parsed_cropdetect_0 @ 0x27a46e0] x1:91 x2:719 y1:201 y2:437 w:624 h:224 x:94 y:208 pts:7200 t:0.080000 crop=624:224:94:208
> > [Parsed_cropdetect_0 @ 0x27a46e0] x1:91 x2:719 y1:198 y2:437 w:624 h:240 x:94 y:198 pts:10800 t:0.120000 crop=624:240:94:198
> > [Parsed_cropdetect_0 @ 0x27a46e0] x1:91 x2:719 y1:198 y2:437 w:624 h:240 x:94 y:198 pts:14400 t:0.160000 crop=624:240:94:198
> > [Parsed_cropdetect_0 @ 0x27a46e0] x1:91 x2:719 y1:198 y2:437 w:624 h:240 x:94 y:198 pts:18000 t:0.200000 crop=624:240:94:198
> >
> > after patch:
> > [Parsed_cropdetect_0 @ 0x1e686e0] x1:91 x2:719 y1:201 y2:575 w:624 h:368 x:94 y:206 pts:7200 t:0.080000 crop=624:368:94:206
> > [Parsed_cropdetect_0 @ 0x1e686e0] x1:91 x2:719 y1:198 y2:575 w:624 h:368 x:94 y:204 pts:10800 t:0.120000 crop=624:368:94:204
> > [Parsed_cropdetect_0 @ 0x1e686e0] x1:91 x2:719 y1:198 y2:575 w:624 h:368 x:94 y:204 pts:14400 t:0.160000 crop=624:368:94:204
> > [Parsed_cropdetect_0 @ 0x1e686e0] x1:91 x2:719 y1:198 y2:575 w:624 h:368 x:94 y:204 pts:18000 t:0.200000 crop=624:368:94:204
> >
> >
> >
> > [...]
> > --
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > Good people do not need laws to tell them to act responsibly, while bad
> > people will find a way around the laws. -- Plato
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> 
> Sorry about that. That was a brainfart on my end. I will leave the
> s->[x1,x2,y1,y2] parameters as they are and just change the reporting
> of w/h/x/y. Amended patch attached.

>  vf_cropdetect.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 014f97e9d8a29154e5f7fba9e54e550692f4416d  0001-Avoid-returning-negative-rectangles-from-cropdetect.patch
> From 5281e57c62a13973c778c9296c98632de8bd5864 Mon Sep 17 00:00:00 2001
> From: tue46wsdgxfjrt <jfbvxt at gmail.com>
> Date: Tue, 9 Sep 2014 18:05:44 -0700
> Subject: [PATCH] Avoid returning negative rectangles from cropdetect
> 
> ---
>  libavfilter/vf_cropdetect.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
> index 76aa7b2..70d7d66 100644
> --- a/libavfilter/vf_cropdetect.c
> +++ b/libavfilter/vf_cropdetect.c
> @@ -120,7 +120,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>      AVFilterContext *ctx = inlink->dst;
>      CropDetectContext *s = ctx->priv;
>      int bpp = s->max_pixsteps[0];
> -    int w, h, x, y, shrink_by;
> +    int w, h, x, y, x2, y2, shrink_by;
>      AVDictionary **metadata;
>  
>      // ignore first 2 frames - they may be empty
> @@ -168,9 +168,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>          // make sure they stay rounded!
>          x = (s->x1+1) & ~1;
>          y = (s->y1+1) & ~1;
> +        x2 = FFMAX(x, (s->x2+1) & ~1);
> +        y2 = FFMAX(y, (s->y2+1) & ~1);
>  
> -        w = s->x2 - x + 1;
> -        h = s->y2 - y + 1;
> +        w = x2 - x + 1;
> +        h = y2 - y + 1;

this can result in a width and height larger than the input


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.
-------------- 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/20140910/0302d81a/attachment.asc>


More information about the ffmpeg-devel mailing list