[FFmpeg-devel] [PATCH] lavfi: add deinterleave filters

Paul B Mahol onemda at gmail.com
Tue Jan 6 10:49:53 CET 2015


On 1/5/15, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Mon, Jan 05, 2015 at 04:33:44PM +0000, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol <onemda at gmail.com>
>> ---
>>  libavfilter/Makefile         |   2 +
>>  libavfilter/allfilters.c     |   2 +
>>  libavfilter/f_deinterleave.c | 143
>> +++++++++++++++++++++++++++++++++++++++++++
>>  3 files changed, 147 insertions(+)
>>  create mode 100644 libavfilter/f_deinterleave.c
>>
>> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
>> index 0ead6c5..17e49ee 100644
>> --- a/libavfilter/Makefile
>> +++ b/libavfilter/Makefile
>> @@ -29,6 +29,7 @@ OBJS = allfilters.o
>>                \
>>
>>  OBJS-$(CONFIG_AVCODEC)                       += avcodec.o
>>
>> +OBJS-$(CONFIG_ADEINTERLEAVE_FILTER)          += f_deinterleave.o
>>  OBJS-$(CONFIG_ADELAY_FILTER)                 += af_adelay.o
>>  OBJS-$(CONFIG_AECHO_FILTER)                  += af_aecho.o
>>  OBJS-$(CONFIG_AEVAL_FILTER)                  += aeval.o
>> @@ -108,6 +109,7 @@ OBJS-$(CONFIG_CROPDETECT_FILTER)             +=
>> vf_cropdetect.o
>>  OBJS-$(CONFIG_CURVES_FILTER)                 += vf_curves.o
>>  OBJS-$(CONFIG_DCTDNOIZ_FILTER)               += vf_dctdnoiz.o
>>  OBJS-$(CONFIG_DECIMATE_FILTER)               += vf_decimate.o
>> +OBJS-$(CONFIG_DEINTERLEAVE_FILTER)           += f_deinterleave.o
>>  OBJS-$(CONFIG_DEJUDDER_FILTER)               += vf_dejudder.o
>>  OBJS-$(CONFIG_DELOGO_FILTER)                 += vf_delogo.o
>>  OBJS-$(CONFIG_DESHAKE_FILTER)                += vf_deshake.o
>> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
>> index 6543629..66982f5 100644
>> --- a/libavfilter/allfilters.c
>> +++ b/libavfilter/allfilters.c
>> @@ -50,6 +50,7 @@ void avfilter_register_all(void)
>>      REGISTER_FILTER(AEVAL,          aeval,          af);
>>      REGISTER_FILTER(AFADE,          afade,          af);
>>      REGISTER_FILTER(AFORMAT,        aformat,        af);
>> +    REGISTER_FILTER(ADEINTERLEAVE,  adeinterleave,  af);
>>      REGISTER_FILTER(AINTERLEAVE,    ainterleave,    af);
>>      REGISTER_FILTER(ALLPASS,        allpass,        af);
>>      REGISTER_FILTER(AMERGE,         amerge,         af);
>> @@ -124,6 +125,7 @@ void avfilter_register_all(void)
>>      REGISTER_FILTER(CURVES,         curves,         vf);
>>      REGISTER_FILTER(DCTDNOIZ,       dctdnoiz,       vf);
>>      REGISTER_FILTER(DECIMATE,       decimate,       vf);
>> +    REGISTER_FILTER(DEINTERLEAVE,   deinterleave,   vf);
>>      REGISTER_FILTER(DEJUDDER,       dejudder,       vf);
>>      REGISTER_FILTER(DELOGO,         delogo,         vf);
>>      REGISTER_FILTER(DESHAKE,        deshake,        vf);
>> diff --git a/libavfilter/f_deinterleave.c b/libavfilter/f_deinterleave.c
>> new file mode 100644
>> index 0000000..2209390
>> --- /dev/null
>> +++ b/libavfilter/f_deinterleave.c
>> @@ -0,0 +1,143 @@
>> +/*
>> + * Copyright (c) 2015 Paul B Mahol
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 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
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser 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
>> + */
>> +
>> +/**
>> + * @file
>> + * audio and video de-interleaver
>> + */
>> +
>> +#include "libavutil/opt.h"
>> +#include "avfilter.h"
>> +#include "formats.h"
>> +#include "internal.h"
>> +#include "audio.h"
>> +#include "video.h"
>> +
>> +typedef struct {
>> +    const AVClass *class;
>> +    int nb_outputs;
>> +    int index;
>> +} DeinterleaveContext;
>> +
>> +#define OFFSET(x) offsetof(DeinterleaveContext, x)
>> +
>> +#define DEFINE_OPTIONS(filt_name, flags_)                           \
>> +static const AVOption filt_name##_options[] = {                     \
>> +   { "nb_outputs", "set number of outputs", OFFSET(nb_outputs),
>> AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, .flags = flags_ }, \
>> +   { NULL }                                                         \
>> +}
>> +
>> +static av_cold int deinterleave_init(AVFilterContext *ctx)
>> +{
>> +    DeinterleaveContext *s = ctx->priv;
>> +    int i;
>> +
>> +    for (i = 0; i < s->nb_outputs; i++) {
>> +        char name[32];
>> +        AVFilterPad pad = { 0 };
>> +
>> +        snprintf(name, sizeof(name), "output%d", i);
>> +        pad.type = ctx->filter->inputs[0].type;
>> +        pad.name = av_strdup(name);
>> +
>> +        ff_insert_outpad(ctx, i, &pad);
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>> +static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>> +{
>> +    AVFilterContext *ctx = inlink->dst;
>> +    DeinterleaveContext *s = ctx->priv;
>> +    int ret;
>> +
>> +    ret = ff_filter_frame(ctx->outputs[s->index], frame);
>> +
>
>> +    s->index++;
>> +    if (s->index >= s->nb_outputs)
>> +        s->index = 0;
>
> s->index = (s->index + 1) % s->nb_outputs;
>
> about audio, is it intended to deinterleave based on filter_frame()
> calls instead of samples ?

Same like interleave it works with frames.
>
> otherwise patch LGTM
>
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Freedom in capitalist society always remains about the same as it was in
> ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
>


More information about the ffmpeg-devel mailing list