FFmpeg
Loading...
Searching...
No Matches
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
34typedef struct FieldContext {
35 const AVClass *class;
36 int type; ///< FieldType
37 int nb_planes; ///< number of planes of the current format
39
40#define OFFSET(x) offsetof(FieldContext, x)
41#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
42
43static 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
53{
54 AVFilterContext *ctx = outlink->src;
55 FieldContext *field = ctx->priv;
56 AVFilterLink *inlink = ctx->inputs[0];
58
59 field->nb_planes = av_pix_fmt_count_planes(outlink->format);
60
61 outlink->w = inlink->w;
62 outlink->h = (inlink->h + (field->type == FIELD_TYPE_TOP)) / 2;
63
64 if (field->type == FIELD_TYPE_BOTTOM &&
65 AV_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h) > AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h) / 2) {
66 av_log(ctx, AV_LOG_ERROR, "The chroma planes of height %d have no complete bottom field\n", inlink->h);
67 return AVERROR(EINVAL);
68 }
69 if (!outlink->h) {
70 av_log(ctx, AV_LOG_ERROR, "Height %d is too small\n", inlink->h);
71 return AVERROR(EINVAL);
72 }
73
74 av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d type:%s -> w:%d h:%d\n",
75 inlink->w, inlink->h, field->type == FIELD_TYPE_BOTTOM ? "bottom" : "top",
76 outlink->w, outlink->h);
77 return 0;
78}
79
80static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
81{
82 FieldContext *field = inlink->dst->priv;
83 AVFilterLink *outlink = inlink->dst->outputs[0];
84 int i;
85
86 inpicref->height = outlink->h;
88
89 for (i = 0; i < field->nb_planes; i++) {
90 if (field->type == FIELD_TYPE_BOTTOM)
91 inpicref->data[i] = inpicref->data[i] + inpicref->linesize[i];
92 inpicref->linesize[i] = 2 * inpicref->linesize[i];
93 }
94 return ff_filter_frame(outlink, inpicref);
95}
96
97static const AVFilterPad field_inputs[] = {
98 {
99 .name = "default",
100 .type = AVMEDIA_TYPE_VIDEO,
101 .filter_frame = filter_frame,
102 },
103};
104
105static const AVFilterPad field_outputs[] = {
106 {
107 .name = "default",
108 .type = AVMEDIA_TYPE_VIDEO,
109 .config_props = config_props_output,
110 },
111};
112
114 .p.name = "field",
115 .p.description = NULL_IF_CONFIG_SMALL("Extract a field from the input video."),
116 .p.priv_class = &field_class,
117 .priv_size = sizeof(FieldContext),
120};
const FFFilter ff_vf_field
Definition vf_field.c:113
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1112
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FLAGS
Definition cmdutils.c:596
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition frame.h:702
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
enum MPFType type
Definition jpegmpfenc.c:55
#define FILTER_INPUTS(array)
Definition filters.h:279
#define FILTER_OUTPUTS(array)
Definition filters.h:280
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:493
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
const char * desc
Definition libsvtav1.c:110
AVOptions.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3524
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:279
void * priv
private data for use by the filter
Definition avfilter.h:294
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:291
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
int height
Definition frame.h:551
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition frame.h:723
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:524
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
int type
FieldType.
Definition vf_field.c:36
int nb_planes
number of planes of the current format
Definition vf_field.c:37
#define av_log(a,...)
static int config_props_output(AVFilterLink *outlink)
static const AVOption field_options[]
Definition vf_field.c:43
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition vf_field.c:80
static const AVFilterPad field_outputs[]
Definition vf_field.c:105
FieldType
Definition vf_field.c:32
@ FIELD_TYPE_BOTTOM
Definition vf_field.c:32
@ FIELD_TYPE_TOP
Definition vf_field.c:32
static int config_props_output(AVFilterLink *outlink)
Definition vf_field.c:52
#define OFFSET(x)
Definition vf_field.c:40
static const AVFilterPad field_inputs[]
Definition vf_field.c:97