[FFmpeg-devel] [PATCH] Add crop filter

Stefano Sabatini stefano.sabatini-lala
Wed Oct 14 20:49:16 CEST 2009


On date Wednesday 2009-10-14 01:37:46 +0200, Michael Niedermayer encoded:
> On Tue, Oct 13, 2009 at 08:47:09PM +0200, Stefano Sabatini wrote:
> > On date Tuesday 2009-10-13 13:16:29 +0200, Michael Niedermayer encoded:
> > > On Mon, Oct 12, 2009 at 08:41:08PM +0200, Stefano Sabatini wrote:
> > > > On date Monday 2009-10-12 09:28:29 +0200, Michael Niedermayer encoded:
> [...]
> > +    if (link->format == PIX_FMT_MONOWHITE || link->format == PIX_FMT_MONOBLACK) {
> > +        crop->x &= ~7;
> > +        crop->y &= ~7;
> > +        crop->w &= ~7;
> > +        crop->h &= ~7;
> 
> the y/h changes are wrong

Fixed, and factorized the following (ab)using the crop->hsub field.
  
> > +    } else {
> > +        avcodec_get_chroma_sub_sample(link->format, &crop->hsub, &crop->vsub);
> > +        crop->x &= ~((1 << crop->hsub) - 1);
> > +        crop->y &= ~((1 << crop->vsub) - 1);
> > +        crop->w &= ~((1 << crop->hsub) - 1);
> > +        crop->h &= ~((1 << crop->vsub) - 1);
> 
> iam not sure this is ideal, i mean if i say crop=1:1:1:1 and i get 2:4:2:4
> without any warning ...
> but iam not sure what would be best so this can maybe be left and
> investigated later

Yes, also we may have nonsense values (e.g. w|h = 0), so I added a check
on that also.

> [...]
> > +static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
> > +{
> > +    CropContext *crop = link->dst->priv;
> > +    AVFilterPicRef *ref2 = avfilter_ref_pic(picref, ~0);
> > +    int i, s;
> > +
> > +    ref2->w        = crop->w;
> > +    ref2->h        = crop->h;
> > +
> > +    ref2->data[0] += (crop->y * ref2->linesize[0]);
> 
> > +    s = link->format == PIX_FMT_MONOWHITE || link->format == PIX_FMT_MONOBLACK ? 3 : 0;
> > +    ref2->data[0] += (crop->x * crop->bpp) >> s;
> 
> please replace s by 3 and set BIT per pixel to its correct value

Done.

Regards.
-- 
FFmpeg = Fantastic Forgiving Maxi Prodigious Epic Gadget
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add-crop-filter.patch
Type: text/x-diff
Size: 8215 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091014/a0ea13a2/attachment.patch>



More information about the ffmpeg-devel mailing list