FFmpeg
vf_field.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 Rich Felker
3  * Copyright (c) 2012 Stefano Sabatini
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * field filter, based on libmpcodecs/vf_field.c by Rich Felker
25  */
26 
27 #include "libavutil/opt.h"
28 #include "libavutil/pixdesc.h"
29 #include "avfilter.h"
30 #include "filters.h"
31 
33 
34 typedef struct FieldContext {
35  const AVClass *class;
36  int type; ///< FieldType
37  int nb_planes; ///< number of planes of the current format
38 } FieldContext;
39 
40 #define OFFSET(x) offsetof(FieldContext, x)
41 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
42 
43 static const AVOption field_options[] = {
44  {"type", "set field type (top or bottom)", OFFSET(type), AV_OPT_TYPE_INT, {.i64=FIELD_TYPE_TOP}, 0, 1, FLAGS, .unit = "field_type" },
45  {"top", "select top field", 0, AV_OPT_TYPE_CONST, {.i64=FIELD_TYPE_TOP}, INT_MIN, INT_MAX, FLAGS, .unit = "field_type"},
46  {"bottom", "select bottom field", 0, AV_OPT_TYPE_CONST, {.i64=FIELD_TYPE_BOTTOM}, INT_MIN, INT_MAX, FLAGS, .unit = "field_type"},
47  {NULL}
48 };
49 
51 
52 static int config_props_output(AVFilterLink *outlink)
53 {
54  AVFilterContext *ctx = outlink->src;
55  FieldContext *field = ctx->priv;
56  AVFilterLink *inlink = ctx->inputs[0];
57 
58  field->nb_planes = av_pix_fmt_count_planes(outlink->format);
59 
60  outlink->w = inlink->w;
61  outlink->h = (inlink->h + (field->type == FIELD_TYPE_TOP)) / 2;
62 
63  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d type:%s -> w:%d h:%d\n",
64  inlink->w, inlink->h, field->type == FIELD_TYPE_BOTTOM ? "bottom" : "top",
65  outlink->w, outlink->h);
66  return 0;
67 }
68 
69 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
70 {
71  FieldContext *field = inlink->dst->priv;
72  AVFilterLink *outlink = inlink->dst->outputs[0];
73  int i;
74 
75  inpicref->height = outlink->h;
76 #if FF_API_INTERLACED_FRAME
78  inpicref->interlaced_frame = 0;
80 #endif
81  inpicref->flags &= ~AV_FRAME_FLAG_INTERLACED;
82 
83  for (i = 0; i < field->nb_planes; i++) {
84  if (field->type == FIELD_TYPE_BOTTOM)
85  inpicref->data[i] = inpicref->data[i] + inpicref->linesize[i];
86  inpicref->linesize[i] = 2 * inpicref->linesize[i];
87  }
88  return ff_filter_frame(outlink, inpicref);
89 }
90 
91 static const AVFilterPad field_inputs[] = {
92  {
93  .name = "default",
94  .type = AVMEDIA_TYPE_VIDEO,
95  .filter_frame = filter_frame,
96  },
97 };
98 
99 static const AVFilterPad field_outputs[] = {
100  {
101  .name = "default",
102  .type = AVMEDIA_TYPE_VIDEO,
103  .config_props = config_props_output,
104  },
105 };
106 
108  .name = "field",
109  .description = NULL_IF_CONFIG_SMALL("Extract a field from the input video."),
110  .priv_size = sizeof(FieldContext),
113  .priv_class = &field_class,
114 };
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
opt.h
FLAGS
#define FLAGS
Definition: vf_field.c:41
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1061
field_inputs
static const AVFilterPad field_inputs[]
Definition: vf_field.c:91
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
pixdesc.h
AVOption
AVOption.
Definition: opt.h:429
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_field.c:69
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:661
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
field_options
static const AVOption field_options[]
Definition: vf_field.c:43
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3210
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
OFFSET
#define OFFSET(x)
Definition: vf_field.c:40
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
AVFrame::interlaced_frame
attribute_deprecated int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:566
FieldType
FieldType
Definition: vf_field.c:32
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
field
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
Definition: writing_filters.txt:78
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
FieldContext
Definition: vf_field.c:34
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
config_props_output
static int config_props_output(AVFilterLink *outlink)
Definition: vf_field.c:52
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(field)
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_vf_field
const AVFilter ff_vf_field
Definition: vf_field.c:107
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:648
AVFilter
Filter definition.
Definition: avfilter.h:201
field_outputs
static const AVFilterPad field_outputs[]
Definition: vf_field.c:99
FIELD_TYPE_TOP
@ FIELD_TYPE_TOP
Definition: vf_field.c:32
AVFrame::height
int height
Definition: frame.h:461
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
FieldContext::type
int type
FieldType.
Definition: vf_field.c:36
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:434
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FIELD_TYPE_BOTTOM
@ FIELD_TYPE_BOTTOM
Definition: vf_field.c:32
FieldContext::nb_planes
int nb_planes
number of planes of the current format
Definition: vf_field.c:37
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299