[FFmpeg-devel] [PATCH] lavfi: USPP filter

Michael Niedermayer michaelni at gmx.at
Tue Dec 9 01:18:45 CET 2014


On Mon, Dec 08, 2014 at 11:15:10PM +0530, arwa arif wrote:
[...]
>  doc/filters.texi         |   24 ++
>  libavfilter/Makefile     |    1 
>  libavfilter/allfilters.c |    1 
>  libavfilter/vf_uspp.c    |  514 +++++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/vf_uspp.h    |   55 +++++
>  5 files changed, 594 insertions(+), 1 deletion(-)
> 128eed16f074aa1448d37eea1d32c9bcb10c3796  0001-lavfi-USPP-Filter.patch
> From 0e2778bd848cff1ac4ea5125354c27a4bfcaee1b Mon Sep 17 00:00:00 2001
> From: Arwa Arif <arwaarif1994 at gmail.com>
> Date: Sun, 7 Dec 2014 18:56:46 +0530
> Subject: [PATCH] lavfi: USPP Filter
> 
> ---
>  doc/filters.texi         |   24 ++-
>  libavfilter/Makefile     |    1 +
>  libavfilter/allfilters.c |    1 +
>  libavfilter/vf_uspp.c    |  514 ++++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/vf_uspp.h    |   55 +++++
>  5 files changed, 594 insertions(+), 1 deletion(-)
>  create mode 100644 libavfilter/vf_uspp.c
>  create mode 100644 libavfilter/vf_uspp.h
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 8c16c7a..322899d 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -6120,7 +6120,6 @@ The list of the currently supported filters follows:
>  @item ilpack
>  @item pp7
>  @item softpulldown
> - at item uspp
>  @end table
>  
>  The parameter syntax and behavior for the listed filters are the same
> @@ -8804,6 +8803,29 @@ unsharp=7:7:-2:7:7:-2
>  @end example
>  @end itemize
>  
> + at section uspp
> +
> +Apply ultra slow/simple postprocessing filter that compresses and decompresses
> +the image at several (or - in the case of @option{quality} level @code{8} - all)
> +shifts and average the results.The way this differs from the behavior of spp is
> +that uspp actually encodes & decodes each case with libavcodec Snow, whereas spp
> +uses a simplified intra only 8x8 DCT similar to MJPEG.
> +
> +The filter accepts the following options:
> +
> + at table @option
> + at item quality
> +Set quality. This option defines the number of levels for averaging. It accepts
> +an integer in the range 0-8. If set to @code{0}, the filter will have no
> +effect. A value of @code{8} means the higher quality. For each increment of
> +that value the speed drops by a factor of approximately 2.  Default value is
> + at code{3}.
> +
> + at item qp
> +Force a constant quantization parameter. If not set, the filter will use the QP
> +from the video stream (if available).
> + at end table
> +

[...]

> +static void hardthresh_c(int16_t dst[DEST_SIZE], const int16_t src[DEST_SIZE],
> +                         int qp, const uint8_t *permutation)
> +{
> +    int i;
> +    int bias = 0; // FIXME
> +
> +    unsigned threshold1 = qp * ((1<<4) - bias) - 1;
> +    unsigned threshold2 = threshold1 << 1;
> +
> +    memset(dst, 0, DEST_SIZE * sizeof(dst[0]));
> +    dst[0] = (src[0] + 4) >> 3;
> +
> +    for (i = 1; i < DEST_SIZE; i++) {
> +        int level = src[i];
> +        if (((unsigned)(level + threshold1)) > threshold2) {
> +            const int j = permutation[i];
> +            dst[j] = (level + 4) >> 3;
> +        }
> +    }
> +}
> +
> +static void softthresh_c(int16_t dst[DEST_SIZE], const int16_t src[DEST_SIZE],
> +                         int qp, const uint8_t *permutation)
> +{
> +    int i;
> +    int bias = 0; //FIXME
> +
> +    unsigned threshold1 = qp * ((1<<4) - bias) - 1;
> +    unsigned threshold2 = threshold1 << 1;
> +
> +    memset(dst, 0, DEST_SIZE * sizeof(dst[0]));
> +    dst[0] = (src[0] + 4) >> 3;
> +
> +    for (i = 1; i < DEST_SIZE; i++) {
> +        int level = src[i];
> +        if (((unsigned)(level + threshold1)) > threshold2) {
> +            const int j = permutation[i];
> +            if (level > 0) dst[j] = (level - threshold1 + 4) >> 3;
> +            else           dst[j] = (level + threshold1 + 4) >> 3;
> +        }
> +    }
> +}

these 2 functions are unused, they can be removed


[...]
> +    for(i=0; i<count; i++){
> +        const int x1= offset[i+count-1][0];
> +        const int y1= offset[i+count-1][1];
> +        int offset;
> +        p->frame->data[0]= p->src[0] + x1 + y1 * p->frame->linesize[0];
> +        p->frame->data[1]= p->src[1] + x1/2 + y1/2 * p->frame->linesize[1];
> +        p->frame->data[2]= p->src[2] + x1/2 + y1/2 * p->frame->linesize[2];
> +
> +        avcodec_encode_video(p->avctx_enc[i], p->outbuf, p->outbuf_size, p->frame);
> +        p->frame_dec = p->avctx_enc[i]->coded_frame;
> +
> +        p->frame->format = p->avctx_enc[i]->pix_fmt;

p->frame width and height should be set too


[...]
> diff --git a/libavfilter/vf_uspp.h b/libavfilter/vf_uspp.h
> new file mode 100644
> index 0000000..143e6a5
> --- /dev/null
> +++ b/libavfilter/vf_uspp.h
> @@ -0,0 +1,55 @@
> +/*
> + * Copyright (c) 2003 Michael Niedermayer <michaelni at gmx.at>
> + * Copyright (c) 2014 Arwa Arif <arwaarif1994 at gmail.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#ifndef AVFILTER_USPP_H
> +#define AVFILTER_USPP_H
> +
> +#include "libavcodec/avcodec.h"
> +#include "avfilter.h"
> +
> +#define MAX_LEVEL 8 /* quality levels */
> +#define BLOCK 16
> +
> +typedef struct {
> +    const AVClass *av_class;
> +    int log2_count;
> +    int qp;
> +    int mode;
> +    int qscale_type;
> +    int temp_stride[3];
> +    uint8_t *src[3];
> +    int16_t *temp[3];
> +    int outbuf_size;
> +    uint8_t *outbuf;
> +    AVCodecContext *avctx_enc[BLOCK*BLOCK];
> +    AVFrame *frame;
> +    AVFrame *frame_dec;
> +    uint8_t *non_b_qp_table;
> +    int non_b_qp_alloc_size;
> +    int use_bframe_qp;

> +    void (*requantize)(int16_t dst[64], const int16_t src[64],
> +                       int qp, const uint8_t *permutation);

this function pointer is never called, it can be removed

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

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway
-------------- 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/20141209/c3783608/attachment.asc>


More information about the ffmpeg-devel mailing list