[FFmpeg-devel] [PATCH] Add scale filter

Michael Niedermayer michaelni
Tue Oct 27 13:34:06 CET 2009


On Tue, Oct 27, 2009 at 02:59:38AM +0100, Stefano Sabatini wrote:
> On date Monday 2009-10-26 11:18:49 +0100, Michael Niedermayer encoded:
> > On Sun, Oct 25, 2009 at 11:45:12AM +0100, Stefano Sabatini wrote:
> > > On date Sunday 2009-10-18 22:39:28 +0200, Michael Niedermayer encoded:
> > > > On Sun, Oct 11, 2009 at 11:29:35PM +0200, Stefano Sabatini wrote:
> > > [...] 
> > > > as a bug in slices in reverse order has been found the vf_scale patch 
> > > > is on hold until that is fixed
> > > 
> > > I'll resume the problem with the scale filter:
> > > 
> > > it assumes all the slices arrive in *sequential* order, and precisely
> > > from the top to the bottom.
> > > 
> > > Currently it (libavfilter SOC repo filter) does:
> > > 
> > >     outH = sws_scale(scale->sws, data, link->cur_pic->linesize,
> > >                      y, h, link->dst->outputs[0]->outpic->data,
> > >                      link->dst->outputs[0]->outpic->linesize);
> > >     avfilter_draw_slice(link->dst->outputs[0], scale->sliceY, outH);
> > >     scale->sliceY += outH;
> > > 
> > > scale->sliceY is inited to 0.
> > > 
> > > In the case the slices arrive in reverse order, this doesn't work
> > > anymore.
> 
> Fixed using the same logic implemented in libswscale for detecting if
> the first slice is the top or the bottom one, not very elegant, an
> alternative was to add a slice_dir parameter to start_frame(), but
> that was complicating the API for little gain.
> 
> Regards.
[...]
> +static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
> +{
> +    ScaleContext *scale = link->dst->priv;
> +    AVFilterLink *out = link->dst->outputs[0];
> +    int64_t gcd;
> +
> +    out->outpic = avfilter_get_video_buffer(out, AV_PERM_WRITE, out->w, out->h);
> +    out->outpic->pts = picref->pts;
> +

> +    out->outpic->pixel_aspect.num = picref->pixel_aspect.num * out->h * link->w;
> +    out->outpic->pixel_aspect.den = picref->pixel_aspect.den * out->w * link->h;
> +
> +    gcd = av_gcd(out->outpic->pixel_aspect.num, out->outpic->pixel_aspect.den);
> +    if (gcd > 1) {
> +        out->outpic->pixel_aspect.num /= gcd;
> +        out->outpic->pixel_aspect.den /= gcd;
> +    }

this can overflow and it should use av_reduce()


> +
> +    scale->slice_dir = 0;
> +    avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0));
> +}
> +
> +static void draw_slice(AVFilterLink *link, int y, int h)
> +{
> +    ScaleContext *scale = link->dst->priv;
> +    int out_h;
> +    AVFilterPicRef *cur_pic = link->cur_pic;
> +    uint8_t *data[4];
> +

> +    if (!scale->slice_dir && y != 0 && y + h != link->h) {
> +        av_log(scale, AV_LOG_ERROR, "Slices start in the middle!\n");
> +        return;
> +    }
> +    if (!scale->slice_dir) {

this check can be factored out


> +        scale->slice_dir = y ? -1 : 1;
> +        scale->slice_y   = y ? link->dst->outputs[0]->h : y;
> +    }
> +
> +    data[0] = cur_pic->data[0] + y * cur_pic->linesize[0];
> +    data[3] = cur_pic->data[3] + y * cur_pic->linesize[3];
> +
> +    if (link->format == PIX_FMT_PAL8) {

> +        data[1] = cur_pic->data[1];
> +        data[2] = cur_pic->data[2];

can be factored out


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091027/bb610e23/attachment.pgp>



More information about the ffmpeg-devel mailing list