vf_separatefields.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Paul B Mahol
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 #include "libavutil/pixdesc.h"
22 #include "avfilter.h"
23 #include "internal.h"
24 
25 typedef struct {
26  int nb_planes;
27  int64_t frame_count;
28  double ts_unit;
30 
31 static int config_props_output(AVFilterLink *outlink)
32 {
33  AVFilterContext *ctx = outlink->src;
34  SeparateFieldsContext *sf = ctx->priv;
35  AVFilterLink *inlink = ctx->inputs[0];
36 
38 
39  if (inlink->h & 1) {
40  av_log(ctx, AV_LOG_ERROR, "height must be even\n");
41  return AVERROR_INVALIDDATA;
42  }
43 
44  outlink->time_base.num = inlink->time_base.num;
45  outlink->time_base.den = inlink->time_base.den * 2;
46  outlink->frame_rate.num = inlink->frame_rate.num * 2;
47  outlink->frame_rate.den = inlink->frame_rate.den;
48  outlink->w = inlink->w;
49  outlink->h = inlink->h / 2;
50  sf->ts_unit = av_q2d(av_inv_q(av_mul_q(outlink->frame_rate, outlink->time_base)));
51 
52  return 0;
53 }
54 
55 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
56 {
57  AVFilterContext *ctx = inlink->dst;
58  SeparateFieldsContext *sf = ctx->priv;
59  AVFilterLink *outlink = ctx->outputs[0];
60  AVFrame *second;
61  int i, ret;
62 
63  inpicref->height = outlink->h;
64  inpicref->interlaced_frame = 0;
65 
66  second = av_frame_clone(inpicref);
67  if (!second)
68  return AVERROR(ENOMEM);
69 
70  for (i = 0; i < sf->nb_planes; i++) {
71  if (!inpicref->top_field_first)
72  inpicref->data[i] = inpicref->data[i] + inpicref->linesize[i];
73  else
74  second->data[i] = second->data[i] + second->linesize[i];
75  inpicref->linesize[i] *= 2;
76  second->linesize[i] *= 2;
77  }
78 
79  inpicref->pts = sf->frame_count++ * sf->ts_unit;
80  second->pts = sf->frame_count++ * sf->ts_unit;
81 
82  ret = ff_filter_frame(outlink, inpicref);
83  if (ret < 0)
84  return ret;
85  return ff_filter_frame(outlink, second);
86 }
87 
89  {
90  .name = "default",
91  .type = AVMEDIA_TYPE_VIDEO,
92  .filter_frame = filter_frame,
93  },
94  { NULL }
95 };
96 
98  {
99  .name = "default",
100  .type = AVMEDIA_TYPE_VIDEO,
101  .config_props = config_props_output,
102  },
103  { NULL }
104 };
105 
107  .name = "separatefields",
108  .description = NULL_IF_CONFIG_SMALL("Split input video frames into fields."),
109  .priv_size = sizeof(SeparateFieldsContext),
110  .inputs = separatefields_inputs,
111  .outputs = separatefields_outputs,
112 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1818
external API header
int num
numerator
Definition: rational.h:44
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:532
static int config_props_output(AVFilterLink *outlink)
static const AVFilterPad separatefields_outputs[]
static const AVFilterPad separatefields_inputs[]
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
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:270
A filter pad used for either input or output.
AVFilter avfilter_vf_separatefields
#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
ret
Definition: avfilter.c:821
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:317
NULL
Definition: eval.c:55
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
Filter definition.
Definition: avfilter.h:436
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
synthesis window for stochastic i
const char * name
filter name
Definition: avfilter.h:437
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:122
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
int den
denominator
Definition: rational.h:45
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:275
An instance of a filter.
Definition: avfilter.h:524
int height
Definition: frame.h:122
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