FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_setfield.c
Go to the documentation of this file.
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 "libavutil/opt.h"
27 #include "avfilter.h"
28 #include "internal.h"
29 #include "video.h"
30 
32  MODE_AUTO = -1,
36 };
37 
38 typedef struct {
39  const AVClass *class;
42 
43 #define OFFSET(x) offsetof(SetFieldContext, x)
44 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
45 
46 static const AVOption setfield_options[] = {
47  {"mode", "select interlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_AUTO}, -1, MODE_PROG, FLAGS, "mode"},
48  {"auto", "keep the same input field", 0, AV_OPT_TYPE_CONST, {.i64=MODE_AUTO}, INT_MIN, INT_MAX, FLAGS, "mode"},
49  {"bff", "mark as bottom-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_BFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
50  {"tff", "mark as top-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_TFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
51  {"prog", "mark as progressive", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PROG}, INT_MIN, INT_MAX, FLAGS, "mode"},
52  {NULL}
53 };
54 
55 AVFILTER_DEFINE_CLASS(setfield);
56 
57 static av_cold int init(AVFilterContext *ctx, const char *args)
58 {
59  SetFieldContext *setfield = ctx->priv;
60  static const char *shorthand[] = { "mode", NULL };
61 
62  setfield->class = &setfield_class;
63  av_opt_set_defaults(setfield);
64 
65  return av_opt_set_from_string(setfield, args, shorthand, "=", ":");
66 }
67 
68 static av_cold void uninit(AVFilterContext *ctx)
69 {
70  SetFieldContext *setfield = ctx->priv;
71  av_opt_free(setfield);
72 }
73 
74 static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
75 {
76  SetFieldContext *setfield = inlink->dst->priv;
77 
78  if (setfield->mode == MODE_PROG) {
79  picref->video->interlaced = 0;
80  } else if (setfield->mode != MODE_AUTO) {
81  picref->video->interlaced = 1;
82  picref->video->top_field_first = setfield->mode;
83  }
84  return ff_filter_frame(inlink->dst->outputs[0], picref);
85 }
86 
87 static const AVFilterPad setfield_inputs[] = {
88  {
89  .name = "default",
90  .type = AVMEDIA_TYPE_VIDEO,
91  .get_video_buffer = ff_null_get_video_buffer,
92  .filter_frame = filter_frame,
93  },
94  { NULL }
95 };
96 
97 static const AVFilterPad setfield_outputs[] = {
98  {
99  .name = "default",
100  .type = AVMEDIA_TYPE_VIDEO,
101  },
102  { NULL }
103 };
104 
106  .name = "setfield",
107  .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
108  .init = init,
109  .uninit = uninit,
110 
111  .priv_size = sizeof(SetFieldContext),
112  .inputs = setfield_inputs,
113  .outputs = setfield_outputs,
114  .priv_class = &setfield_class,
115 };