FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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  double ts_unit;
29 
30 static int config_props_output(AVFilterLink *outlink)
31 {
32  AVFilterContext *ctx = outlink->src;
33  SeparateFieldsContext *sf = ctx->priv;
34  AVFilterLink *inlink = ctx->inputs[0];
35 
37 
38  if (inlink->h & 1) {
39  av_log(ctx, AV_LOG_ERROR, "height must be even\n");
40  return AVERROR_INVALIDDATA;
41  }
42 
43  outlink->time_base.num = inlink->time_base.num;
44  outlink->time_base.den = inlink->time_base.den * 2;
45  outlink->frame_rate.num = inlink->frame_rate.num * 2;
46  outlink->frame_rate.den = inlink->frame_rate.den;
47  outlink->w = inlink->w;
48  outlink->h = inlink->h / 2;
49  sf->ts_unit = av_q2d(av_inv_q(av_mul_q(outlink->frame_rate, outlink->time_base)));
50 
51  return 0;
52 }
53 
54 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
55 {
56  AVFilterContext *ctx = inlink->dst;
57  SeparateFieldsContext *sf = ctx->priv;
58  AVFilterLink *outlink = ctx->outputs[0];
59  AVFrame *second;
60  int i, ret;
61 
62  inpicref->height = outlink->h;
63  inpicref->interlaced_frame = 0;
64 
65  second = av_frame_clone(inpicref);
66  if (!second)
67  return AVERROR(ENOMEM);
68 
69  for (i = 0; i < sf->nb_planes; i++) {
70  if (!inpicref->top_field_first)
71  inpicref->data[i] = inpicref->data[i] + inpicref->linesize[i];
72  else
73  second->data[i] = second->data[i] + second->linesize[i];
74  inpicref->linesize[i] *= 2;
75  second->linesize[i] *= 2;
76  }
77 
78  inpicref->pts = outlink->frame_count * sf->ts_unit;
79  ret = ff_filter_frame(outlink, inpicref);
80  if (ret < 0)
81  return ret;
82 
83  second->pts = outlink->frame_count * sf->ts_unit;
84  return ff_filter_frame(outlink, second);
85 }
86 
88  {
89  .name = "default",
90  .type = AVMEDIA_TYPE_VIDEO,
91  .filter_frame = filter_frame,
92  },
93  { NULL }
94 };
95 
97  {
98  .name = "default",
99  .type = AVMEDIA_TYPE_VIDEO,
100  .config_props = config_props_output,
101  },
102  { NULL }
103 };
104 
106  .name = "separatefields",
107  .description = NULL_IF_CONFIG_SMALL("Split input video frames into fields."),
108  .priv_size = sizeof(SeparateFieldsContext),
109  .inputs = separatefields_inputs,
110  .outputs = separatefields_outputs,
111 };