]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_setfield.c
Merge remote-tracking branch 'qatar/master'
[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
28 enum SetFieldMode {
29     MODE_AUTO = -1,
30     MODE_BFF,
31     MODE_TFF,
32     MODE_PROG,
33 };
34
35 typedef struct {
36     enum SetFieldMode mode;
37 } SetFieldContext;
38
39 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
40 {
41     SetFieldContext *setfield = ctx->priv;
42
43     setfield->mode = MODE_AUTO;
44
45     if (args) {
46         char c;
47         if (sscanf(args, "%d%c", &setfield->mode, &c) != 1) {
48             if      (!strcmp("tff",  args)) setfield->mode = MODE_TFF;
49             else if (!strcmp("bff",  args)) setfield->mode = MODE_BFF;
50             else if (!strcmp("prog", args)) setfield->mode = MODE_PROG;
51             else if (!strcmp("auto", args)) setfield->mode = MODE_AUTO;
52             else {
53                 av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
54                 return AVERROR(EINVAL);
55             }
56         } else {
57             if (setfield->mode < -1 || setfield->mode > 1) {
58                 av_log(ctx, AV_LOG_ERROR,
59                        "Provided integer value %d must be included between -1 and +1\n",
60                        setfield->mode);
61                 return AVERROR(EINVAL);
62             }
63             av_log(ctx, AV_LOG_WARNING,
64                    "Using -1/0/1 is deprecated, use auto/tff/bff/prog\n");
65         }
66     }
67
68     return 0;
69 }
70
71 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
72 {
73     SetFieldContext *setfield = inlink->dst->priv;
74     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
75
76     if (setfield->mode == MODE_PROG) {
77         outpicref->video->interlaced = 0;
78     } else if (setfield->mode != MODE_AUTO) {
79         outpicref->video->interlaced = 1;
80         outpicref->video->top_field_first = setfield->mode;
81     }
82     avfilter_start_frame(inlink->dst->outputs[0], outpicref);
83 }
84
85 AVFilter avfilter_vf_setfield = {
86     .name      = "setfield",
87     .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
88     .init      = init,
89
90     .priv_size = sizeof(SetFieldContext),
91
92     .inputs = (const AVFilterPad[]) {
93         { .name             = "default",
94           .type             = AVMEDIA_TYPE_VIDEO,
95           .get_video_buffer = avfilter_null_get_video_buffer,
96           .start_frame      = start_frame, },
97         { .name = NULL }
98     },
99     .outputs = (const AVFilterPad[]) {
100         { .name             = "default",
101           .type             = AVMEDIA_TYPE_VIDEO, },
102         { .name = NULL }
103     },
104 };