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 int filter_frame(AVFilterLink *inlink, AVFrame *picref)
58 {
59  SetFieldContext *setfield = inlink->dst->priv;
60 
61  if (setfield->mode == MODE_PROG) {
62  picref->interlaced_frame = 0;
63  } else if (setfield->mode != MODE_AUTO) {
64  picref->interlaced_frame = 1;
65  picref->top_field_first = setfield->mode;
66  }
67  return ff_filter_frame(inlink->dst->outputs[0], picref);
68 }
69 
70 static const AVFilterPad setfield_inputs[] = {
71  {
72  .name = "default",
73  .type = AVMEDIA_TYPE_VIDEO,
74  .get_video_buffer = ff_null_get_video_buffer,
75  .filter_frame = filter_frame,
76  },
77  { NULL }
78 };
79 
80 static const AVFilterPad setfield_outputs[] = {
81  {
82  .name = "default",
83  .type = AVMEDIA_TYPE_VIDEO,
84  },
85  { NULL }
86 };
87 
89  .name = "setfield",
90  .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
91  .priv_size = sizeof(SetFieldContext),
92  .inputs = setfield_inputs,
93  .outputs = setfield_outputs,
94  .priv_class = &setfield_class,
95 };
#define FLAGS
Definition: vf_setfield.c:44
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
AVOption.
Definition: opt.h:251
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
Definition: vf_setfield.c:57
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:35
const char * name
Pad name.
enum SetFieldMode mode
Definition: vf_setfield.c:40
#define OFFSET(x)
Definition: vf_setfield.c:43
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
mode
Definition: f_perms.c:27
AVOptions.
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:270
A filter pad used for either input or output.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
Definition: avfilter.h:545
static const AVOption setfield_options[]
Definition: vf_setfield.c:46
static const AVFilterPad setfield_outputs[]
Definition: vf_setfield.c:80
SetFieldMode
Definition: vf_setfield.c:31
NULL
Definition: eval.c:55
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
const char * name
filter name
Definition: avfilter.h:437
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
static const AVFilterPad setfield_inputs[]
Definition: vf_setfield.c:70
AVFilter avfilter_vf_setfield
Definition: vf_setfield.c:88
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:275
AVFILTER_DEFINE_CLASS(setfield)
internal API functions
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs