[FFmpeg-devel] [PATCH] lavfi: USPP filter
Michael Niedermayer
michaelni at gmx.at
Mon Dec 8 18:35:58 CET 2014
On Mon, Dec 08, 2014 at 10:02:13PM +0530, arwa arif wrote:
> On Sun, Dec 7, 2014 at 9:52 PM, Michael Niedermayer <michaelni at gmx.at>
> wrote:
>
> > On Sun, Dec 07, 2014 at 07:52:59PM +0530, arwa arif wrote:
> > > Hello!
> > > I have ported the uspp filter to FFmpeg.
> > >
> > >
> > > I have attached the patch.
> > >
> > >
> > > Regards,
> > > Arwa Arif
> >
> > > Makefile | 2
> > > allfilters.c | 1
> > > vf_uspp.c | 509
> > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > vf_uspp.h | 55 ++++++
> > > 4 files changed, 566 insertions(+), 1 deletion(-)
> > > 15f575321937c299d2512dfcc4b5b55b2a47d59b 0001-lavfi-USPP-Filter.patch
> > > From 7cafda11d5d402a0490af0a1a74de373445352a1 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
> > >
> > > ---
> > > libavfilter/Makefile | 2 +-
> > > libavfilter/allfilters.c | 1 +
> > > libavfilter/vf_uspp.c | 509
> > ++++++++++++++++++++++++++++++++++++++++++++++
> > > libavfilter/vf_uspp.h | 55 +++++
> > > 4 files changed, 566 insertions(+), 1 deletion(-)
> > > create mode 100644 libavfilter/vf_uspp.c
> > > create mode 100644 libavfilter/vf_uspp.h
> > >
> > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> > > index 2c56e38..6b7291e 100644
> > > --- a/libavfilter/Makefile
> > > +++ b/libavfilter/Makefile
> > > @@ -193,6 +193,7 @@ OBJS-$(CONFIG_TINTERLACE_FILTER) +=
> > vf_tinterlace.o
> > > OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o
> > > OBJS-$(CONFIG_TRIM_FILTER) += trim.o
> > > OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o
> > > +OBJS-$(CONFIG_USPP_FILTER) += vf_uspp.o
> > > OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o
> > > OBJS-$(CONFIG_VIDSTABDETECT_FILTER) += vidstabutils.o
> > vf_vidstabdetect.o
> > > OBJS-$(CONFIG_VIDSTABTRANSFORM_FILTER) += vidstabutils.o
> > vf_vidstabtransform.o
> >
> > > @@ -226,7 +227,6 @@ OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fspp.o
> > > OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ilpack.o
> > > OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pp7.o
> > > OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softpulldown.o
> > > -OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_uspp.o
> > >
> > > # multimedia filters
> > > OBJS-$(CONFIG_AVECTORSCOPE_FILTER) += avf_avectorscope.o
> >
> > this breaks linking as the filter is still referenced
> > maybe you didnt build with --enable-gpl (which could hide that issue)
> >
> >
> >
> If the link is breaking here, do you suggest me to add uspp back, or is
> there any other way to direct the reference to the new filter?
adding it back for now is easiest, we can remove it later
>
> [...]
>
> > > +static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
> > > + int dst_stride[3], int src_stride[3], int width,
> > > + int height, uint8_t *qp_store, int qp_stride){
> > > +
> > > + int x, y, i, j;
> > > + const int count= 1<<p->log2_count;
> > > + for(i=0; i<3; i++){
> > > + int is_chroma= !!i;
> > > + int w= width >>is_chroma;
> > > + int h= height>>is_chroma;
> > > + int stride= p->temp_stride[i];
> > > + int block= BLOCK>>is_chroma;
> > > +
> > > + if (!src[i] || !dst[i])
> > > + continue; // HACK avoid crash for Y8 colourspace
> > > + for(y=0; y<h; y++){
> > > + int index= block + block*stride + y*stride;
> > > + memcpy(p->src[i] + index, src[i] + y*src_stride[i], w);
> > > + for(x=0; x<block; x++){
> > > + p->src[i][index - x - 1]= p->src[i][index + x
> > ];
> > > + p->src[i][index + w + x ]= p->src[i][index + w - x -
> > 1];
> > > + }
> > > + }
> > > + for(y=0; y<block; y++){
> > > + memcpy(p->src[i] + ( block-1-y)*stride, p->src[i] + (
> > y+block )*stride, stride);
> > > + memcpy(p->src[i] + (h+block +y)*stride, p->src[i] +
> > (h-y+block-1)*stride, stride);
> > > + }
> > > +
> > > + p->frame->linesize[i]= stride;
> > > + memset(p->temp[i], 0, (h+2*block)*stride*sizeof(int16_t));
> > > + }
> > > +
> > > + if(p->qp)
> > > + p->frame->quality= p->qp * FF_QP2LAMBDA;
> > > + else
> > > + p->frame->quality= norm_qscale(qp_store[0], p->qscale_type) *
> > FF_QP2LAMBDA;
> > > +// init per MB qscale stuff FIXME
> > > +
> > > + 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];
> > > +
> >
> > p->frame->format should be set to avctx_enc->pix_fmt
> >
> >
> > [...]
> > > +static int config_input(AVFilterLink *inlink)
> > > +{
> > > +
> > > + AVFilterContext *ctx = inlink->dst;
> > > + USPPContext *uspp = ctx->priv;
> > > + const int height = inlink->h;
> > > + const int width = inlink->w;
> > > +
> > > + AVCodec *enc= avcodec_find_encoder(AV_CODEC_ID_SNOW);
> > > + int i;
> > > +
> > > + if (!uspp->use_bframe_qp) {
> > > + /* we are assuming here the qp blocks will not be smaller that
> > 16x16 */
> > > + uspp->non_b_qp_alloc_size = FF_CEIL_RSHIFT(width, 4) *
> > FF_CEIL_RSHIFT(height, 4);
> > > + uspp->non_b_qp_table = av_calloc(uspp->non_b_qp_alloc_size,
> > sizeof(*uspp->non_b_qp_table));
> > > + if (!uspp->non_b_qp_table)
> > > + return AVERROR(ENOMEM);
> > > + }
> > > +
> > > + for(i=0; i<3; i++){
> > > + int is_chroma= !!i;
> > > + int w= ((width + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma;
> > > + int h= ((height + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma;
> > > +
> > > + uspp->temp_stride[i]= w;
> >
> > > + uspp->temp[i]= malloc(uspp->temp_stride[i]*h*sizeof(int16_t));
> > > + uspp->src [i]= malloc(uspp->temp_stride[i]*h*sizeof(uint8_t));
> >
> > these should be av_malloc()
> >
> >
> > > + }
> > > +
> > > + for(i=0; i< (1<<uspp->log2_count); i++){
> > > + AVCodecContext *avctx_enc;
> > > + AVDictionary *opts = NULL;
> > > +
> > > + avctx_enc = uspp->avctx_enc[i]= avcodec_alloc_context3(NULL);
> > > + avctx_enc->width = width + BLOCK;
> > > + avctx_enc->height = height + BLOCK;
> > > + avctx_enc->time_base= (AVRational){1,25}; // meaningless
> > > + avctx_enc->gop_size = 300;
> > > + avctx_enc->max_b_frames= 0;
> > > + avctx_enc->pix_fmt = AV_PIX_FMT_YUV420P;
> > > + avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
> > > + avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
> > > + avctx_enc->global_quality= 123;
> > > + av_dict_set(&opts, "no_bitstream", "1", 0);
> >
> > > + if (avcodec_open2(avctx_enc, enc, &opts) < 0)
> > > + return 0;
> >
> > the error code from avcodec_open2() should be returned
> >
>
> By this you mean av_log?
i meant
ret = avcodec_open2(avctx_enc, enc, &opts);
if (ret < 0)
return ret;
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell
-------------- 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/20141208/dd22f81e/attachment.asc>
More information about the ffmpeg-devel
mailing list