2 * Copyright (c) 2012 Stefano Sabatini
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
37 enum SetFieldMode mode;
40 static av_cold int init(AVFilterContext *ctx, const char *args)
42 SetFieldContext *setfield = ctx->priv;
44 setfield->mode = MODE_AUTO;
48 if (sscanf(args, "%d%c", &setfield->mode, &c) != 1) {
49 if (!strcmp("tff", args)) setfield->mode = MODE_TFF;
50 else if (!strcmp("bff", args)) setfield->mode = MODE_BFF;
51 else if (!strcmp("prog", args)) setfield->mode = MODE_PROG;
52 else if (!strcmp("auto", args)) setfield->mode = MODE_AUTO;
54 av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
55 return AVERROR(EINVAL);
58 if (setfield->mode < -1 || setfield->mode > 1) {
59 av_log(ctx, AV_LOG_ERROR,
60 "Provided integer value %d must be included between -1 and +1\n",
62 return AVERROR(EINVAL);
64 av_log(ctx, AV_LOG_WARNING,
65 "Using -1/0/1 is deprecated, use auto/tff/bff/prog\n");
72 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
74 SetFieldContext *setfield = inlink->dst->priv;
75 AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
77 if (setfield->mode == MODE_PROG) {
78 outpicref->video->interlaced = 0;
79 } else if (setfield->mode != MODE_AUTO) {
80 outpicref->video->interlaced = 1;
81 outpicref->video->top_field_first = setfield->mode;
83 return ff_start_frame(inlink->dst->outputs[0], outpicref);
86 static const AVFilterPad setfield_inputs[] = {
89 .type = AVMEDIA_TYPE_VIDEO,
90 .get_video_buffer = ff_null_get_video_buffer,
91 .start_frame = start_frame,
96 static const AVFilterPad setfield_outputs[] = {
99 .type = AVMEDIA_TYPE_VIDEO,
104 AVFilter avfilter_vf_setfield = {
106 .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
109 .priv_size = sizeof(SetFieldContext),
110 .inputs = setfield_inputs,
111 .outputs = setfield_outputs,