[FFmpeg-devel] [PATCH 2/2] mcfps filter WIP

Robert Krüger krueger at lesspain.de
Sat Aug 29 22:44:48 CEST 2015


On Fri, Jul 24, 2015 at 8:50 PM, Michael Niedermayer <michaelni at gmx.at>
wrote:

> Works well with some scenes, works really not well with others
> More work needed
> if you can improve it, i would not be unhappy
>
> this should not be optimized yet except trivial things, first the code
> should work well then it should be made to work fast
>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavcodec/internal.h    |    3 +
>  libavcodec/snow.c        |   30 ++
>  libavcodec/utils.c       |   10 +
>  libavfilter/Makefile     |    1 +
>  libavfilter/allfilters.c |    1 +
>  libavfilter/vf_mcfps.c   |  853
> ++++++++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 898 insertions(+)
>  create mode 100644 libavfilter/vf_mcfps.c
>
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index e0b40f1..62535a7 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -300,4 +300,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame);
>
>  int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t
> *error, int error_count, int pict_type);
>
> +int avpriv_get_mvs(AVCodecContext *avctx, int16_t (*mvs)[2], int8_t
> *refs, int width, int height);
> +int ff_get_mvs_snow(AVCodecContext *avctx, int16_t (*mvs)[2], int8_t
> *refs, int w, int h);
> +
>  #endif /* AVCODEC_INTERNAL_H */
> diff --git a/libavcodec/snow.c b/libavcodec/snow.c
> index fc2e727..de4d816 100644
> --- a/libavcodec/snow.c
> +++ b/libavcodec/snow.c
> @@ -731,3 +731,33 @@ av_cold void ff_snow_common_end(SnowContext *s)
>      av_frame_free(&s->mconly_picture);
>      av_frame_free(&s->current_picture);
>  }
> +
> +int ff_get_mvs_snow(AVCodecContext *avctx, int16_t (*mvs)[2], int8_t
> *refs, int w, int h)
> +{
> +    SnowContext *s = avctx->priv_data;
> +    const int b_width  = s->b_width  << s->block_max_depth;
> +    const int b_height = s->b_height << s->block_max_depth;
> +    const int b_stride= b_width;
> +    int x, y;
> +
> +    if (w != b_width || h != b_height) {
> +        av_log(avctx, AV_LOG_ERROR, "mvs array dimensions mismatch %dx%d
> != %dx%d\n",
> +               w, h, b_width, b_height);
> +        return AVERROR(EINVAL);
> +    }
> +
> +    for (y=0; y<h; y++) {
> +        for (x=0; x<w; x++) {
> +            BlockNode *bn= &s->block[x + y*b_stride];
> +            if (bn->type) {
> +                refs[x + y*w] = -1;
> +            } else {
> +                refs[x + y*w] = bn->ref;
> +                mvs[x + y*w][0] = bn->mx;
> +                mvs[x + y*w][1] = bn->my;
> +            }
> +        }
> +    }
> +
> +    return 0;
> +}
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index d926a26..8bc7b65 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -3906,3 +3906,13 @@ const uint8_t *avpriv_find_start_code(const uint8_t
> *av_restrict p,
>
>      return p + 4;
>  }
> +
> +int avpriv_get_mvs(AVCodecContext *avctx, int16_t (*mvs)[2], int8_t
> *refs, int width, int height)
> +{
> +    switch (avctx->codec_id) {
> +    case AV_CODEC_ID_SNOW:
> +        return ff_get_mvs_snow(avctx, mvs, refs, width, height);
> +    default:
> +        return AVERROR(EINVAL);
> +    }
> +}
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index bec7bdb..e1d9b5b 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -163,6 +163,7 @@ OBJS-$(CONFIG_LUT_FILTER)                    +=
> vf_lut.o
>  OBJS-$(CONFIG_LUTRGB_FILTER)                 += vf_lut.o
>  OBJS-$(CONFIG_LUTYUV_FILTER)                 += vf_lut.o
>  OBJS-$(CONFIG_MCDEINT_FILTER)                += vf_mcdeint.o
> +OBJS-$(CONFIG_MCFPS_FILTER)                  += vf_mcfps.o
>  OBJS-$(CONFIG_MERGEPLANES_FILTER)            += vf_mergeplanes.o
> framesync.o
>  OBJS-$(CONFIG_MPDECIMATE_FILTER)             += vf_mpdecimate.o
>  OBJS-$(CONFIG_NEGATE_FILTER)                 += vf_lut.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index ad7242d..c3428aa 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -179,6 +179,7 @@ void avfilter_register_all(void)
>      REGISTER_FILTER(LUTRGB,         lutrgb,         vf);
>      REGISTER_FILTER(LUTYUV,         lutyuv,         vf);
>      REGISTER_FILTER(MCDEINT,        mcdeint,        vf);
> +    REGISTER_FILTER(MCFPS,          mcfps,          vf);
>      REGISTER_FILTER(MERGEPLANES,    mergeplanes,    vf);
>      REGISTER_FILTER(MPDECIMATE,     mpdecimate,     vf);
>      REGISTER_FILTER(NEGATE,         negate,         vf);
> diff --git a/libavfilter/vf_mcfps.c b/libavfilter/vf_mcfps.c
> new file mode 100644
> index 0000000..784275d
> --- /dev/null
> +++ b/libavfilter/vf_mcfps.c
> @@ -0,0 +1,853 @@
> +/*
> + * Copyright (c) 2014-2015 Michael Niedermayer <michaelni at gmx.at>
> + *
> + * 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
>

Totally your choice, of course, but did you specifically decide against
LGPL or is there GPL code used in it?


More information about the ffmpeg-devel mailing list