[FFmpeg-devel] [PATCH] joinfields filter
Clément Bœsch
ubitux at gmail.com
Thu Apr 18 02:53:12 CEST 2013
On Thu, Apr 18, 2013 at 12:26:28AM +0000, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
> libavfilter/Makefile | 1 +
> libavfilter/allfilters.c | 1 +
> libavfilter/vf_joinfields.c | 147 ++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 149 insertions(+)
> create mode 100644 libavfilter/vf_joinfields.c
>
doc, fate
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 33b3f5b..4831267 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -135,6 +135,7 @@ OBJS-$(CONFIG_HUE_FILTER) += vf_hue.o
> OBJS-$(CONFIG_IDET_FILTER) += vf_idet.o
> OBJS-$(CONFIG_IL_FILTER) += vf_il.o
> OBJS-$(CONFIG_INTERLACE_FILTER) += vf_interlace.o
> +OBJS-$(CONFIG_JOINFIELDS_FILTER) += vf_joinfields.o
> OBJS-$(CONFIG_KERNDEINT_FILTER) += vf_kerndeint.o
> OBJS-$(CONFIG_LUT_FILTER) += vf_lut.o
> OBJS-$(CONFIG_LUTRGB_FILTER) += vf_lut.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index a6c8597..fc369bd 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -132,6 +132,7 @@ void avfilter_register_all(void)
> REGISTER_FILTER(HUE, hue, vf);
> REGISTER_FILTER(IDET, idet, vf);
> REGISTER_FILTER(IL, il, vf);
> + REGISTER_FILTER(JOINFIELDS, joinfields, vf);
> REGISTER_FILTER(INTERLACE, interlace, vf);
> REGISTER_FILTER(KERNDEINT, kerndeint, vf);
> REGISTER_FILTER(LUT, lut, vf);
> diff --git a/libavfilter/vf_joinfields.c b/libavfilter/vf_joinfields.c
> new file mode 100644
> index 0000000..5af2eb6
> --- /dev/null
> +++ b/libavfilter/vf_joinfields.c
> @@ -0,0 +1,147 @@
> +/*
> + * Copyright (c) 2013 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
> + */
> +
> +#include "libavutil/imgutils.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "avfilter.h"
> +#include "internal.h"
> +
> +typedef struct {
> + const AVClass *class;
> + int first_field;
> + int64_t frame_count;
> + double ts_unit;
> + int nb_planes;
> + int planeheight[4];
> + int stride[4];
nit: we tend to use "linesize" all over the filters.
> +
> + AVFrame *prev;
> +} JoinFieldsContext;
> +
> +#define OFFSET(x) offsetof(JoinFieldsContext, x)
> +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
> +
> +static const AVOption joinfields_options[] = {
> + {"first_field", "set first field", OFFSET(first_field), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "field"},
> + {"top", "set top field first", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "field"},
> + {"t", "set top field first", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "field"},
> + {"bottom", "set bottom field first", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "field"},
> + {"b", "set bottom field first", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "field"},
> + {NULL}
> +};
> +
> +AVFILTER_DEFINE_CLASS(joinfields);
> +
> +static int config_props_output(AVFilterLink *outlink)
> +{
> + AVFilterContext *ctx = outlink->src;
> + JoinFieldsContext *jf = ctx->priv;
> + AVFilterLink *inlink = ctx->inputs[0];
> + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
> + int ret;
> +
> + outlink->time_base.num = inlink->time_base.num * 2;
> + outlink->time_base.den = inlink->time_base.den;
> + outlink->frame_rate.num = inlink->frame_rate.num;
> + outlink->frame_rate.den = inlink->frame_rate.den * 2;
> + outlink->w = inlink->w;
> + outlink->h = inlink->h * 2;
> + outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
> + jf->ts_unit = av_q2d(av_inv_q(av_mul_q(outlink->frame_rate, outlink->time_base)));
> +
> + if ((ret = av_image_fill_linesizes(jf->stride, inlink->format, inlink->w)) < 0)
> + return ret;
> +
> + jf->planeheight[1] = jf->planeheight[2] = inlink->h >> desc->log2_chroma_h;
> + jf->planeheight[0] = jf->planeheight[3] = inlink->h;
> +
> + jf->nb_planes = av_pix_fmt_count_planes(inlink->format);;
> +
double ;;
> + return 0;
> +}
> +
> +static int filter_frame(AVFilterLink *inlink, AVFrame *cur)
> +{
> + AVFilterContext *ctx = inlink->dst;
> + JoinFieldsContext *jf = ctx->priv;
> + AVFilterLink *outlink = ctx->outputs[0];
> + AVFrame *out;
> + int i;
> +
> + if (!jf->prev) {
> + jf->prev = cur;
> + return 0;
> + }
> +
> + out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
> + if (!out) {
> + av_frame_free(&cur);
> + av_frame_free(&jf->prev);
> + return AVERROR(ENOMEM);
> + }
> + av_frame_copy_props(out, cur);
> +
> + for (i = 0; i < jf->nb_planes; i++) {
> + av_image_copy_plane(out->data[i] + out->linesize[i] * !jf->first_field,
> + out->linesize[i] * 2,
> + cur->data[i], cur->linesize[i],
> + jf->stride[i], jf->planeheight[i]);
> + av_image_copy_plane(out->data[i] + out->linesize[i] * jf->first_field,
> + out->linesize[i] * 2,
> + jf->prev->data[i], jf->prev->linesize[i],
> + jf->stride[i], jf->planeheight[i]);
> + }
> +
> + out->pts = jf->frame_count++ * jf->ts_unit;
> + out->interlaced_frame = 1;
> + out->top_field_first = jf->first_field;
> +
> + av_frame_free(&cur);
> + av_frame_free(&jf->prev);
> + return ff_filter_frame(outlink, out);
> +}
> +
> +static const AVFilterPad joinfields_inputs[] = {
> + {
> + .name = "default",
> + .type = AVMEDIA_TYPE_VIDEO,
> + .filter_frame = filter_frame,
> + },
> + { NULL }
> +};
> +
> +static const AVFilterPad joinfields_outputs[] = {
> + {
> + .name = "default",
> + .type = AVMEDIA_TYPE_VIDEO,
> + .config_props = config_props_output,
> + },
> + { NULL }
> +};
> +
> +AVFilter avfilter_vf_joinfields = {
> + .name = "joinfields",
> + .description = NULL_IF_CONFIG_SMALL("Join input video fields into frames."),
> + .priv_size = sizeof(JoinFieldsContext),
> + .priv_class = &joinfields_class,
> + .inputs = joinfields_inputs,
> + .outputs = joinfields_outputs,
> +};
separatefields,joinfields is a no-op, even for timestamps?
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130418/ca0fcde7/attachment.asc>
More information about the ffmpeg-devel
mailing list