]> 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 typedef struct {
29     int top_field_first;
30 } SetFieldContext;
31
32 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
33 {
34     SetFieldContext *setfield = ctx->priv;
35
36     setfield->top_field_first = -1;
37
38     if (args) {
39         char c;
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;
44             else {
45                 av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
46                 return AVERROR(EINVAL);
47             }
48         }
49     }
50
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);
56     }
57
58     return 0;
59 }
60
61 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
62 {
63     SetFieldContext *setfield = inlink->dst->priv;
64     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
65
66     if (setfield->top_field_first != -1) {
67         outpicref->video->interlaced = 1;
68         outpicref->video->top_field_first = setfield->top_field_first;
69     }
70     avfilter_start_frame(inlink->dst->outputs[0], outpicref);
71 }
72
73 AVFilter avfilter_vf_setfield = {
74     .name      = "setfield",
75     .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
76     .init      = init,
77
78     .priv_size = sizeof(SetFieldContext),
79
80     .inputs = (const AVFilterPad[]) {
81         { .name             = "default",
82           .type             = AVMEDIA_TYPE_VIDEO,
83           .get_video_buffer = avfilter_null_get_video_buffer,
84           .start_frame      = start_frame, },
85         { .name = NULL }
86     },
87     .outputs = (const AVFilterPad[]) {
88         { .name             = "default",
89           .type             = AVMEDIA_TYPE_VIDEO, },
90         { .name = NULL }
91     },
92 };