]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_setfield.c
lavfi/field: switch to filter_frame API
[ffmpeg] / libavfilter / vf_setfield.c
1 /*
2  * Copyright (c) 2012 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20
21 /**
22  * @file
23  * set field order
24  */
25
26 #include "avfilter.h"
27 #include "video.h"
28
29 enum SetFieldMode {
30     MODE_AUTO = -1,
31     MODE_BFF,
32     MODE_TFF,
33     MODE_PROG,
34 };
35
36 typedef struct {
37     enum SetFieldMode mode;
38 } SetFieldContext;
39
40 static av_cold int init(AVFilterContext *ctx, const char *args)
41 {
42     SetFieldContext *setfield = ctx->priv;
43
44     setfield->mode = MODE_AUTO;
45
46     if (args) {
47         char c;
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;
53             else {
54                 av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
55                 return AVERROR(EINVAL);
56             }
57         } else {
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",
61                        setfield->mode);
62                 return AVERROR(EINVAL);
63             }
64             av_log(ctx, AV_LOG_WARNING,
65                    "Using -1/0/1 is deprecated, use auto/tff/bff/prog\n");
66         }
67     }
68
69     return 0;
70 }
71
72 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
73 {
74     SetFieldContext *setfield = inlink->dst->priv;
75     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
76
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;
82     }
83     return ff_start_frame(inlink->dst->outputs[0], outpicref);
84 }
85
86 static const AVFilterPad setfield_inputs[] = {
87     {
88         .name             = "default",
89         .type             = AVMEDIA_TYPE_VIDEO,
90         .get_video_buffer = ff_null_get_video_buffer,
91         .start_frame      = start_frame,
92     },
93     { NULL }
94 };
95
96 static const AVFilterPad setfield_outputs[] = {
97     {
98         .name = "default",
99         .type = AVMEDIA_TYPE_VIDEO,
100     },
101     { NULL }
102 };
103
104 AVFilter avfilter_vf_setfield = {
105     .name      = "setfield",
106     .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
107     .init      = init,
108
109     .priv_size = sizeof(SetFieldContext),
110     .inputs    = setfield_inputs,
111     .outputs   = setfield_outputs,
112 };