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 "internal.h"
31 
33 
34 typedef struct {
35  const AVClass *class;
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, "field_type" },
45  {"top", "select top field", 0, AV_OPT_TYPE_CONST, {.i64=FIELD_TYPE_TOP}, INT_MIN, INT_MAX, FLAGS, "field_type"},
46  {"bottom", "select bottom field", 0, AV_OPT_TYPE_CONST, {.i64=FIELD_TYPE_BOTTOM}, INT_MIN, INT_MAX, FLAGS, "field_type"},
47 
48  {NULL}
49 };
50 
52 
53 static int config_props_output(AVFilterLink *outlink)
54 {
55  AVFilterContext *ctx = outlink->src;
56  FieldContext *field = ctx->priv;
57  AVFilterLink *inlink = ctx->inputs[0];
58  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
59  int i;
60 
61  for (i = 0; i < desc->nb_components; i++)
62  field->nb_planes = FFMAX(field->nb_planes, desc->comp[i].plane);
63  field->nb_planes++;
64 
65  outlink->w = inlink->w;
66  outlink->h = (inlink->h + (field->type == FIELD_TYPE_TOP)) / 2;
67 
68  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d type:%s -> w:%d h:%d\n",
69  inlink->w, inlink->h, field->type == FIELD_TYPE_BOTTOM ? "bottom" : "top",
70  outlink->w, outlink->h);
71  return 0;
72 }
73 
74 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
75 {
76  FieldContext *field = inlink->dst->priv;
77  AVFilterLink *outlink = inlink->dst->outputs[0];
78  int i;
79 
80  inpicref->height = outlink->h;
81  inpicref->interlaced_frame = 0;
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  .get_video_buffer = ff_null_get_video_buffer,
96  .filter_frame = filter_frame,
97  },
98  { NULL }
99 };
100 
101 static const AVFilterPad field_outputs[] = {
102  {
103  .name = "default",
104  .type = AVMEDIA_TYPE_VIDEO,
105  .config_props = config_props_output,
106  },
107  { NULL }
108 };
109 
111  .name = "field",
112  .description = NULL_IF_CONFIG_SMALL("Extract a field from the input video."),
113 
114  .priv_size = sizeof(FieldContext),
115  .inputs = field_inputs,
116  .outputs = field_outputs,
117  .priv_class = &field_class,
118 };
#define FLAGS
Definition: vf_field.c:41
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_field.c:74
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static const AVFilterPad field_inputs[]
Definition: vf_field.c:91
AVOption.
Definition: opt.h:251
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
#define OFFSET(x)
Definition: vf_field.c:40
const char * name
Pad name.
static const AVOption field_options[]
Definition: vf_field.c:43
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:532
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:86
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
AVOptions.
AVFilter avfilter_vf_field
Definition: vf_field.c:110
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:270
enum FieldType type
Definition: vf_field.c:36
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
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define FFMAX(a, b)
Definition: common.h:56
FieldType
Definition: vf_field.c:32
#define AV_LOG_VERBOSE
Definition: log.h:157
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
AVFILTER_DEFINE_CLASS(field)
NULL
Definition: eval.c:55
static int config_props_output(AVFilterLink *outlink)
Definition: vf_field.c:53
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
synthesis window for stochastic i
int nb_planes
number of planes of the current format
Definition: vf_field.c:37
const char * name
filter name
Definition: avfilter.h:437
#define type
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
uint16_t plane
which of the 4 planes contains the component
Definition: pixdesc.h:29
An instance of a filter.
Definition: avfilter.h:524
int height
Definition: frame.h:122
static const AVFilterPad field_outputs[]
Definition: vf_field.c:101
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