[FFmpeg-devel] [PATCH] lavfi: add deinterleave filters
Paul B Mahol
onemda at gmail.com
Mon Jan 5 17:33:44 CET 2015
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;
+
+ return ret;
+}
+
+static av_cold void deinterleave_uninit(AVFilterContext *ctx)
+{
+ int i;
+
+ for (i = 0; i < ctx->nb_outputs; i++)
+ av_freep(&ctx->output_pads[i].name);
+}
+
+#if CONFIG_DEINTERLEAVE_FILTER
+
+DEFINE_OPTIONS(deinterleave, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM);
+AVFILTER_DEFINE_CLASS(deinterleave);
+
+static const AVFilterPad avfilter_vf_deinterleave_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .filter_frame = filter_frame,
+ },
+ { NULL }
+};
+
+AVFilter ff_vf_deinterleave = {
+ .name = "deinterleave",
+ .description = NULL_IF_CONFIG_SMALL("Deinterleave video inputs."),
+ .priv_size = sizeof(DeinterleaveContext),
+ .priv_class = &deinterleave_class,
+ .init = deinterleave_init,
+ .uninit = deinterleave_uninit,
+ .inputs = avfilter_vf_deinterleave_inputs,
+ .outputs = NULL,
+ .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
+};
+
+#endif
+
+#if CONFIG_ADEINTERLEAVE_FILTER
+
+DEFINE_OPTIONS(adeinterleave, AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM);
+AVFILTER_DEFINE_CLASS(adeinterleave);
+
+static const AVFilterPad avfilter_af_adeinterleave_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .filter_frame = filter_frame,
+ },
+ { NULL }
+};
+
+AVFilter ff_af_adeinterleave = {
+ .name = "adeinterleave",
+ .description = NULL_IF_CONFIG_SMALL("Deinterleave audio inputs."),
+ .priv_size = sizeof(DeinterleaveContext),
+ .priv_class = &adeinterleave_class,
+ .init = deinterleave_init,
+ .uninit = deinterleave_uninit,
+ .inputs = avfilter_af_adeinterleave_inputs,
+ .outputs = NULL,
+ .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
+};
+
+#endif
--
1.7.11.2
More information about the ffmpeg-devel
mailing list