[FFmpeg-devel] [PATCH] lavfi: Port fspp to FFmpeg

Michael Niedermayer michaelni at gmx.at
Tue Dec 16 12:45:04 CET 2014


On Tue, Dec 16, 2014 at 11:14:58AM +0530, arwa arif wrote:
> On Tue, Dec 16, 2014 at 6:06 AM, Michael Niedermayer <michaelni at gmx.at>
> wrote:
> >
> > On Mon, Dec 15, 2014 at 10:55:26PM +0530, arwa arif wrote:
> > > This patch seems to be working. Sorry for the previous one.
> >
> > >  doc/filters.texi                  |   24
> > >  libavfilter/Makefile              |    1
> > >  libavfilter/allfilters.c          |    1
> > >  libavfilter/libmpcodecs/vf_fspp.c |    4
> > >  libavfilter/version.h             |    2
> > >  libavfilter/vf_fspp.c             |  400 ++++++++++
> > >  libavfilter/vf_fspp.h             |  352 +++++++++
> > >  libavfilter/x86/Makefile          |    1
> > >  libavfilter/x86/vf_fspp.c         | 1391
> > ++++++++++++++++++++++++++++++++++++++
> > >  9 files changed, 2173 insertions(+), 3 deletions(-)
> > > d945d17d2227a2628acbcba387267734c3914841  0001-Port-fspp-to-FFmpeg.patch
> > > From 97d90c5a1a8c10a1b19a5250c90d02fb74e79735 Mon Sep 17 00:00:00 2001
> > > From: Arwa Arif <arwaarif1994 at gmail.com>
> > > Date: Sun, 14 Dec 2014 12:03:31 +0530
> > > Subject: [PATCH] Port fspp to FFmpeg
> >
> > [...]
> > > +    if (fspp->log2_count && !ctx->is_disabled) {
> > > +        if (!fspp->use_bframe_qp && fspp->non_b_qp_table)
> > > +            qp_table = fspp->non_b_qp_table;
> > > +
> > > +        if (qp_table || fspp->qp) {
> > > +
> > > +            /* get a new frame if in-place is not possible or if the
> > dimensions
> > > +             * are not multiple of 8 */
> > > +            if (!av_frame_is_writable(in) || (inlink->w & 7) ||
> > (inlink->h & 7)) {
> > > +                const int aligned_w = FFALIGN(inlink->w, 8);
> > > +                const int aligned_h = FFALIGN(inlink->h, 8);
> > > +
> > > +                out = ff_get_video_buffer(outlink, aligned_w,
> > aligned_h);
> > > +                if (!out) {
> > > +                    av_frame_free(&in);
> > > +                    return AVERROR(ENOMEM);
> > > +                }
> > > +                av_frame_copy_props(out, in);
> > > +                out->width  = in->width;
> > > +                out->height = in->height;
> > > +            }
> > > +
> >
> > > +            filter(fspp , out->data[0] , in->data[0] , out->linesize[0]
> > , in->linesize[0] ,
> > > +                   inlink->w , inlink->h , qp_table , qp_stride , 1);
> >
> > > +            filter(fspp , out->data[1] , in->data[1] , out->linesize[1]
> > , in->linesize[1] ,
> > > +                   inlink->w , inlink->h , qp_table , qp_stride , 0);
> > > +            filter(fspp , out->data[2] , in->data[2] , out->linesize[2]
> > , in->linesize[2] ,
> > > +                   inlink->w , inlink->h , qp_table , qp_stride , 0);
> >
> > the 2 chroma planes are smaller than luma, thus
> > "inlink->w , inlink->h" is wrong for them
> >
> > you can calculate the sizes of the chroma plane with
> > log2_chroma_w and log2_chroma_h from av_pix_fmt_desc_get()
> > see similar code in other filters
> >
> > [...]
> >
> > --
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > No human being will ever know the Truth, for even if they happen to say it
> > by chance, they would not even known they had done so. -- Xenophanes
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> >

>  configure                         |    1 
>  doc/filters.texi                  |   24 
>  libavfilter/Makefile              |    1 
>  libavfilter/allfilters.c          |    1 
>  libavfilter/libmpcodecs/vf_fspp.c |    4 
>  libavfilter/version.h             |    2 
>  libavfilter/vf_fspp.c             |  662 ++++++++++++++++++
>  libavfilter/vf_fspp.h             |   95 ++
>  libavfilter/x86/Makefile          |    1 
>  libavfilter/x86/vf_fspp.c         | 1397 ++++++++++++++++++++++++++++++++++++++
>  10 files changed, 2185 insertions(+), 3 deletions(-)
> 629ed1fb3bebe6f56eefc9515a14178c09f5d6ba  0001-Port-fspp-to-FFmpeg.patch
> From d17fd6e84ee1d20d498975f8de26fe963e2baa57 Mon Sep 17 00:00:00 2001
> From: Arwa Arif <arwaarif1994 at gmail.com>
> Date: Sun, 14 Dec 2014 12:03:31 +0530
> Subject: [PATCH] Port fspp to FFmpeg
> 
> ---
>  configure                         |    1 +
>  doc/filters.texi                  |   24 +
>  libavfilter/Makefile              |    1 +
>  libavfilter/allfilters.c          |    1 +
>  libavfilter/libmpcodecs/vf_fspp.c |    4 +-
>  libavfilter/version.h             |    2 +-
>  libavfilter/vf_fspp.c             |  662 ++++++++++++++++++
>  libavfilter/vf_fspp.h             |   95 +++
>  libavfilter/x86/Makefile          |    1 +
>  libavfilter/x86/vf_fspp.c         | 1397 +++++++++++++++++++++++++++++++++++++
>  10 files changed, 2185 insertions(+), 3 deletions(-)
>  create mode 100644 libavfilter/vf_fspp.c
>  create mode 100644 libavfilter/vf_fspp.h
>  create mode 100644 libavfilter/x86/vf_fspp.c
> 
> diff --git a/configure b/configure
> index e37285a..29f5534 100755
> --- a/configure
> +++ b/configure
> @@ -2575,6 +2575,7 @@ ebur128_filter_deps="gpl"
>  flite_filter_deps="libflite"
>  frei0r_filter_deps="frei0r dlopen"
>  frei0r_src_filter_deps="frei0r dlopen"
> +fspp_filter_deps="gpl"
>  geq_filter_deps="gpl"
>  histeq_filter_deps="gpl"
>  hqdn3d_filter_deps="gpl"
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 882caa0..eefc507 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -4997,6 +4997,30 @@ frei0r=perspective:0.2/0.2|0.8/0.2
>  For more information, see
>  @url{http://frei0r.dyne.org}
>  
> + at section fspp
> +
> +Faster version of the simple postprocessing filter - @ref{spp}.

*** Undefined node `spp' in @ref (in doc/filters.texi l. 5002)
i think this needs a @anchor{}


[...]

> +static void filter(FSPPContext *p , uint8_t *dst , uint8_t *src,
> +                   int dst_stride , int src_stride ,
> +                   int width , int height ,
> +                   uint8_t *qp_store , int qp_stride , int is_luma) {
> +
> +    int x, x0, y, es, qy, t;
> +
> +    const int stride = is_luma ? p->temp_stride : (width+16);
> +    const int step = 6 - p->log2_count;

> +    const int qps = 3 + is_luma;

this should be something like
qpsh = 4 - hsub * !is_luma
qpsv = 4 - vsub * !is_luma



[...]
> +static int config_input(AVFilterLink *inlink)
> +{
> +
> +    AVFilterContext *ctx = inlink->dst;
> +    FSPPContext *fspp = ctx->priv;
> +    const int h = FFALIGN(inlink->h + 16, 16);
> +    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
> +
> +    fspp->hsub = desc->log2_chroma_w;
> +    fspp->vsub = desc->log2_chroma_h;
> +
> +    fspp->temp_stride = FFALIGN(inlink->w + 16, 16);
> +    fspp->temp = av_malloc_array(fspp->temp_stride, h * sizeof(*fspp->temp));
> +    fspp->src  = av_malloc_array(fspp->temp_stride, h * sizeof(*fspp->src));

> +    if (!fspp->use_bframe_qp) {
> +        /* we are assuming here the qp blocks will not be smaller that 16x16 */
> +        fspp->non_b_qp_alloc_size = FF_CEIL_RSHIFT(inlink->w, 4) * FF_CEIL_RSHIFT(inlink->h, 4);
> +        fspp->non_b_qp_table = av_calloc(fspp->non_b_qp_alloc_size, sizeof(*fspp->non_b_qp_table));
> +        if (!fspp->non_b_qp_table)
> +            return AVERROR(ENOMEM);
> +    }

this can allocate a too small array, this bug is in the original spp
filter
see e8dbecb99569e2054babab973e74a69017d02f09


> +
> +    if (!fspp->temp || !fspp->src)
> +        return AVERROR(ENOMEM);
> +
> +    fspp->store_slice  = store_slice_c;
> +    fspp->store_slice2 = store_slice2_c;
> +    fspp->mul_thrmat   = mul_thrmat_c;
> +    fspp->column_fidct = column_fidct_c;
> +    fspp->row_idct     = row_idct_c;
> +    fspp->row_fdct     = row_fdct_c;
> +
> +    if (ARCH_X86)
> +        ff_fspp_init_x86(fspp);
> +
> +    return 0;
> +}
> +
> +static int filter_frame(AVFilterLink *inlink, AVFrame *in)
> +{
> +    AVFilterContext *ctx = inlink->dst;
> +    FSPPContext *fspp = ctx->priv;
> +    AVFilterLink *outlink = ctx->outputs[0];
> +    AVFrame *out = in;
> +
> +    int qp_stride = 0;
> +    uint8_t *qp_table = NULL;
> +
> +    /* if we are not in a constant user quantizer mode and we don't want to use
> +     * the quantizers from the B-frames (B-frames often have a higher QP), we
> +     * need to save the qp table from the last non B-frame; this is what the
> +     * following code block does */
> +    if (!fspp->qp) {
> +        qp_table = av_frame_get_qp_table(in, &qp_stride, &fspp->qscale_type);
> +
> +        if (qp_table && !fspp->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) {
> +            int w, h;
> +
> +            /* if the qp stride is not set, it means the QP are only defined on
> +             * a line basis */
> +            if (!qp_stride) {
> +                w = FF_CEIL_RSHIFT(inlink->w, 4);
> +                h = 1;
> +            } else {
> +                w = FF_CEIL_RSHIFT(qp_stride, 4);

this is another bug from the original code
see 2a8eb0d1565afe1c6f6a805a743987926a8dbaa7

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
-------------- 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/20141216/b4a91855/attachment.asc>


More information about the ffmpeg-devel mailing list