2 * Copyright (c) 2013 Paul B Mahol
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/pixdesc.h"
29 } SeparateFieldsContext;
31 static int config_props_output(AVFilterLink *outlink)
33 AVFilterContext *ctx = outlink->src;
34 SeparateFieldsContext *sf = ctx->priv;
35 AVFilterLink *inlink = ctx->inputs[0];
37 sf->nb_planes = av_pix_fmt_count_planes(inlink->format);;
40 av_log(ctx, AV_LOG_ERROR, "height must be even\n");
41 return AVERROR_INVALIDDATA;
44 outlink->time_base.num = inlink->time_base.num;
45 outlink->time_base.den = inlink->time_base.den * 2;
46 outlink->frame_rate.num = inlink->frame_rate.num * 2;
47 outlink->frame_rate.den = inlink->frame_rate.den;
48 outlink->w = inlink->w;
49 outlink->h = inlink->h / 2;
50 sf->ts_unit = av_q2d(av_inv_q(av_mul_q(outlink->frame_rate, outlink->time_base)));
55 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
57 AVFilterContext *ctx = inlink->dst;
58 SeparateFieldsContext *sf = ctx->priv;
59 AVFilterLink *outlink = ctx->outputs[0];
63 inpicref->height = outlink->h;
64 inpicref->interlaced_frame = 0;
66 second = av_frame_clone(inpicref);
68 return AVERROR(ENOMEM);
70 for (i = 0; i < sf->nb_planes; i++) {
71 if (!inpicref->top_field_first)
72 inpicref->data[i] = inpicref->data[i] + inpicref->linesize[i];
74 second->data[i] = second->data[i] + second->linesize[i];
75 inpicref->linesize[i] *= 2;
76 second->linesize[i] *= 2;
79 inpicref->pts = sf->frame_count++ * sf->ts_unit;
80 second->pts = sf->frame_count++ * sf->ts_unit;
82 ret = ff_filter_frame(outlink, inpicref);
85 return ff_filter_frame(outlink, second);
88 static const AVFilterPad separatefields_inputs[] = {
91 .type = AVMEDIA_TYPE_VIDEO,
92 .filter_frame = filter_frame,
97 static const AVFilterPad separatefields_outputs[] = {
100 .type = AVMEDIA_TYPE_VIDEO,
101 .config_props = config_props_output,
106 AVFilter avfilter_vf_separatefields = {
107 .name = "separatefields",
108 .description = NULL_IF_CONFIG_SMALL("Split input video frames into fields."),
109 .priv_size = sizeof(SeparateFieldsContext),
110 .inputs = separatefields_inputs,
111 .outputs = separatefields_outputs,