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
32 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
34 SetFieldContext *setfield = ctx->priv;
36 setfield->top_field_first = -1;
40 if (sscanf(args, "%d%c", &setfield->top_field_first, &c) != 1) {
41 if (!strcmp("tff", args)) setfield->top_field_first = 1;
42 else if (!strcmp("bff", args)) setfield->top_field_first = 0;
43 else if (!strcmp("auto", args)) setfield->top_field_first = -1;
45 av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
46 return AVERROR(EINVAL);
51 if (setfield->top_field_first < -1 || setfield->top_field_first > 1) {
52 av_log(ctx, AV_LOG_ERROR,
53 "Provided integer value %d must be included between -1 and +1\n",
54 setfield->top_field_first);
55 return AVERROR(EINVAL);
61 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
63 SetFieldContext *setfield = inlink->dst->priv;
64 AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
66 if (setfield->top_field_first != -1) {
67 outpicref->video->interlaced = 1;
68 outpicref->video->top_field_first = setfield->top_field_first;
70 avfilter_start_frame(inlink->dst->outputs[0], outpicref);
73 AVFilter avfilter_vf_setfield = {
75 .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
78 .priv_size = sizeof(SetFieldContext),
80 .inputs = (const AVFilterPad[]) {
82 .type = AVMEDIA_TYPE_VIDEO,
83 .get_video_buffer = avfilter_null_get_video_buffer,
84 .start_frame = start_frame, },
87 .outputs = (const AVFilterPad[]) {
89 .type = AVMEDIA_TYPE_VIDEO, },