1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

lavfi: add field filter

The filter is a port of libmpcodecs/vf_field.c, since there is no common
code I relicensed it as LGPL, while keeping the original author
copyright.
This commit is contained in:
Stefano Sabatini 2012-10-30 12:15:28 +01:00
parent dc239b3b40
commit 3c4aa50620
9 changed files with 278 additions and 2 deletions

View File

@ -18,6 +18,7 @@ version <next>:
- LVF demuxer
- ffescape tool
- metadata (info chunk) support in CAF muxer
- field filter ported from libmpcodecs
version 1.0:

View File

@ -2128,6 +2128,31 @@ fade=in:5:20
fade=in:0:25:alpha=1
@end example
@section field
Extract a single field from an interlaced image using stride
arithmetic to avoid wasting CPU time. The output frames are marked as
non-interlaced.
This filter accepts the following named options:
@table @option
@item type
Specify whether to extract the top (if the value is @code{0} or
@code{top}) or the bottom field (if the value is @code{1} or
@code{bottom}).
@end table
If the option key is not specified, the first value sets the @var{type}
option. For example:
@example
field=bottom
@end example
is equivalent to:
@example
field=type=bottom
@end example
@section fieldorder
Transform the field order of the input video.

View File

@ -98,6 +98,7 @@ OBJS-$(CONFIG_DRAWBOX_FILTER) += vf_drawbox.o
OBJS-$(CONFIG_DRAWTEXT_FILTER) += vf_drawtext.o
OBJS-$(CONFIG_EDGEDETECT_FILTER) += vf_edgedetect.o
OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o
OBJS-$(CONFIG_FIELD_FILTER) += vf_field.o
OBJS-$(CONFIG_FIELDORDER_FILTER) += vf_fieldorder.o
OBJS-$(CONFIG_FIFO_FILTER) += fifo.o
OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o

View File

@ -90,6 +90,7 @@ void avfilter_register_all(void)
REGISTER_FILTER (DRAWTEXT, drawtext, vf);
REGISTER_FILTER (EDGEDETECT, edgedetect, vf);
REGISTER_FILTER (FADE, fade, vf);
REGISTER_FILTER (FIELD, field, vf);
REGISTER_FILTER (FIELDORDER, fieldorder, vf);
REGISTER_FILTER (FIFO, fifo, vf);
REGISTER_FILTER (FORMAT, format, vf);

View File

@ -29,8 +29,8 @@
#include "libavutil/avutil.h"
#define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 20
#define LIBAVFILTER_VERSION_MICRO 113
#define LIBAVFILTER_VERSION_MINOR 21
#define LIBAVFILTER_VERSION_MICRO 100
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \

145
libavfilter/vf_field.c Normal file
View File

@ -0,0 +1,145 @@
/*
* Copyright (c) 2003 Rich Felker
* Copyright (c) 2012 Stefano Sabatini
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* field filter, based on libmpcodecs/vf_field.c by Rich Felker
*/
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "internal.h"
enum FieldType { FIELD_TYPE_TOP = 0, FIELD_TYPE_BOTTOM };
typedef struct {
const AVClass *class;
enum FieldType type;
int nb_planes; ///< number of planes of the current format
} FieldContext;
#define OFFSET(x) offsetof(FieldContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
static const AVOption field_options[] = {
{"type", "set field type (top or bottom)", OFFSET(type), AV_OPT_TYPE_INT, {.i64=FIELD_TYPE_TOP}, 0, 1, FLAGS, "field_type" },
{"top", "select top field", 0, AV_OPT_TYPE_CONST, {.i64=FIELD_TYPE_TOP}, INT_MIN, INT_MAX, FLAGS, "field_type"},
{"bottom", "select bottom field", 0, AV_OPT_TYPE_CONST, {.i64=FIELD_TYPE_BOTTOM}, INT_MIN, INT_MAX, FLAGS, "field_type"},
{NULL}
};
AVFILTER_DEFINE_CLASS(field);
static av_cold int init(AVFilterContext *ctx, const char *args)
{
FieldContext *field = ctx->priv;
static const char *shorthand[] = { "type", NULL };
field->class = &field_class;
av_opt_set_defaults(field);
return av_opt_set_from_string(field, args, shorthand, "=", ":");
}
static int config_props_output(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
FieldContext *field = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
int i;
for (i = 0; i < desc->nb_components; i++)
field->nb_planes = FFMAX(field->nb_planes, desc->comp[i].plane);
field->nb_planes++;
outlink->w = inlink->w;
outlink->h = (inlink->h + (field->type == FIELD_TYPE_TOP)) / 2;
av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d type:%s -> w:%d h:%d\n",
inlink->w, inlink->h, field->type == FIELD_TYPE_BOTTOM ? "bottom" : "top",
outlink->w, outlink->h);
return 0;
}
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
{
FieldContext *field = inlink->dst->priv;
AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
AVFilterLink *outlink = inlink->dst->outputs[0];
int i;
if (!outpicref)
return AVERROR(ENOMEM);
outpicref->video->h = outlink->h;
outpicref->video->interlaced = 0;
for (i = 0; i < field->nb_planes; i++) {
if (field->type == FIELD_TYPE_BOTTOM)
outpicref->data[i] = inpicref->data[i] + inpicref->linesize[i];
outpicref->linesize[i] = 2 * inpicref->linesize[i];
}
return ff_start_frame(outlink, outpicref);
}
static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{
FieldContext *field = inlink->dst->priv;
int y1 = (y + (field->type == FIELD_TYPE_TOP)) / 2;
int h1 = (h + (field->type == FIELD_TYPE_TOP)) / 2;
return ff_draw_slice(inlink->dst->outputs[0], y1, h1, slice_dir);
}
static const AVFilterPad field_inputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.get_video_buffer = ff_null_get_video_buffer,
.start_frame = start_frame,
.draw_slice = draw_slice,
.end_frame = ff_null_end_frame,
},
{ NULL }
};
static const AVFilterPad field_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.config_props = config_props_output,
},
{ NULL }
};
AVFilter avfilter_vf_field = {
.name = "field",
.description = NULL_IF_CONFIG_SMALL("Extract a field from the input video."),
.priv_size = sizeof(FieldContext),
.init = init,
.inputs = field_inputs,
.outputs = field_outputs,
.priv_class = &field_class,
};

View File

@ -11,6 +11,7 @@ FATE_LAVFI = fate-lavfi-alphaextract_rgb \
fate-lavfi-drawbox \
fate-lavfi-edgedetect \
fate-lavfi-fade \
fate-lavfi-field \
fate-lavfi-idet \
fate-lavfi-life \
fate-lavfi-null \

View File

@ -111,6 +111,7 @@ do_lavfi_pixfmts(){
do_lavfi_pixfmts "copy" ""
do_lavfi_pixfmts "crop" "100:100:100:100"
do_lavfi_pixfmts "hflip" ""
do_lavfi_pixfmts "field" "field" "bottom"
do_lavfi_pixfmts "null" ""
do_lavfi_pixfmts "pad" "500:400:20:20"
do_lavfi_pixfmts "pixdesctest" ""

101
tests/ref/lavfi/field Normal file
View File

@ -0,0 +1,101 @@
0bgr 57434af4bddb691877f2400c704604eb
0rgb fc2ba950163aeee98590181e31fcd202
abgr 3c78d0a72484a1ecd3cae245b9fa988c
argb d5057a2be412864719ffb8ba129c1f2c
bgr0 b33c6b58b0d7bf6ce07d5a2d7c267040
bgr24 bd6620738df19410d5df5f31e7451709
bgr444be 219e318b7e0e05050181e71df6b9539d
bgr444le 8354f2cf5b30de0233d302a74816649d
bgr48be 22be50bd0aa39f07ad1b1aa57cb741ce
bgr48le c4b0f8057b3eac237e9228e83bdc4c66
bgr4_byte d4c3304b4b823a130c335379e4d3444d
bgr555be c3072da465233dbfc8f61dc7a9766d2c
bgr555le be83adcf0b802b061442f0c564fd5987
bgr565be bf955b9a035af0e613cf1de249f55f9d
bgr565le 6dd85cd5e19266c53a54cbcf06d396a7
bgr8 9669f6974f0fc1c0afa1c7d4df093c0b
bgra f7cabae31dd7465dab2203f45db646f8
gray 66a09b53f7d3f79dcb6096f3ec3740c5
gray16be a447af6482b922c9997ac02e5d3535f1
gray16le c1dd0db327295898ff282d07f48c105d
monob 1b7fb7e69a913a0a1c0dffc54e5899ea
monow b5d3778a054fc73d515d36f8a6bc693b
nv12 b3829e9ae2a15349432b7efac4236068
nv21 963cf5780e07301ff2906bf345b6d0ff
pal8 bfedafc3bf19c2c12eeb87125833142a
rgb0 d7481143742ff68abfbac4195edbede0
rgb24 908d5494062c617bc87149c9daaf2167
rgb444be 281a8f186a2726c2b31aa7e09e21c865
rgb444le 93f9ee6265d8ad5e744ab652563f9b78
rgb48be 0d1d60e1639edb2758ad776cb5583970
rgb48le c958b5e98324263e97de2bb528f5bda4
rgb4_byte 2ec97bf65649e3d47eb6812701544593
rgb555be 21b9138b229d4065b02d38b5b62f18d1
rgb555le 0307ee34e562b2fb2b1c6988ae18b2b2
rgb565be e8f3ebcbb9a5fff000eca8a312f89782
rgb565le 53bbd558fb0dcd82f1fad83ea855c3ad
rgb8 67bfdd4fa88b1ab9be876f42dfc75683
rgba d0ebdf1495bc6b7e9d3bfbe2813a9d16
uyvy422 a6a52504a16f09b8f2ec2405bc8190b5
yuv410p 3feb55b1e2a385b488c82e808a12587b
yuv411p ab3dd8e6cf1452afe2d2e976e4726370
yuv420p 52e26ad198368e2326bef97cdfa6a2bb
yuv420p10be 04353bfc21e9b88cd7776e83be756742
yuv420p10le 3f8e7167dbd12976c6ee516b8c952363
yuv420p12be b058ac076c8a5fe522b9fd9b8422054e
yuv420p12le ad0bf28e69eeb14eac5d8f9ea8b801f1
yuv420p14be c7a435d42f07928332ecb21a7d96ad7a
yuv420p14le 5507e8db4e58c9517012686a7408996b
yuv420p16be 5241d64e9fa2fd6590fd23ea0e8a6f90
yuv420p16le 78da606f761a4fb62fdac05aa5092742
yuv420p9be e4bcaf5d6a7030f950b08501327f6175
yuv420p9le bbf80e57389578be66d4a7a12335a613
yuv422p e461a21995da361b88202339a2ebb879
yuv422p10be a3e13070215f5a016ac9bae7e7115417
yuv422p10le 8e9e3d9adc8fdb8a0a03d79bdc31eefe
yuv422p12be 4c339f71d79d2dac1dabc6121e1cf021
yuv422p12le 69d336fccbe1ffa88106ea5bde0c8743
yuv422p14be f20c21dbfda632d26816fce27c1cb6e9
yuv422p14le 70dddb8bdad188079a05113059d139f8
yuv422p16be 55cfed8fa610f82b6625e16871dab235
yuv422p16le e2488df0f22987fe7ed12a5ef2adf835
yuv422p9be 80fcdd7fd9cdd79632104dcc32f78b4b
yuv422p9le e0ec9f94c875297ee5d0546274df40e9
yuv440p f8e80596babcdb94378ec8bebf2dd46d
yuv444p 572bad9e12ed53e242658fa613412279
yuv444p10be c5304f086afc4624d4fffb66a3cf3cb8
yuv444p10le d1754974b936f74028752d49413d30aa
yuv444p12be 206d6b0fbd84d4e013b9b074cbd65135
yuv444p12le dc2b1bfbecba71eba50e7e4da470a8d0
yuv444p14be 19cd2ef75ed5698898c55040e51def88
yuv444p14le 8d47c9575d1355572ee9bfc873d46753
yuv444p16be 3a67c28325978db734ba03b1828c15da
yuv444p16le c6dc275a4277fd3c65535253bb298263
yuv444p9be f47357cdd775fc399aeab3ae58712fb9
yuv444p9le e29799ecb6fac9f5b6d85bc34d248d4b
yuva420p 82ab09bb7a3a24bf95aeb3fa9d939847
yuva420p10be f4559039e99ecf74a58e7063b1e7c5d3
yuva420p10le b1eb7df29134936450c2c312ae23a1a4
yuva420p16be c580495d34c6ac6e3e3b81772a0f3070
yuva420p16le 1c49deeafb8f81e9186f3906c9b1a670
yuva420p9be a788d7cc6ad67ad52619a08da126569a
yuva420p9le c1579a5c015908f26b76480d82f6a648
yuva422p c162b37ce05360c47b2a2224ea0748ad
yuva422p10be 6df70d1018e8c0c9fa377f72f49bf81b
yuva422p10le 2eb54f20d3e5f180c539d92a75fe66e9
yuva422p16be 1c61492076be33404894c1d3ec578d87
yuva422p16le 1c085c9479a57eea35e74c264c947d73
yuva422p9be 271c6cc091052731373ef5313bc76435
yuva422p9le b8c2e963ac35371e8aa6a05d5c252b37
yuva444p 4a85f1f17e95829cd53c9a28928fd8eb
yuva444p10be d312f0d30a88fdd18e992362ea3b5f81
yuva444p10le d12aed62a367bc7735e59503a3cf8cc6
yuva444p16be ac5c17adeb0ef6730a0de1dbd1d14a1a
yuva444p16le 41f1a82eb686d7191bdb00206f723247
yuva444p9be 413d01385a8b008031b2ab3ef0b9eff4
yuva444p9le 33ede0bd20bfd85489d266ac81d035d6
yuvj420p 762dc6a157d0bee72da3e3d852668aef
yuvj422p 8cec955c1c62b00b6798361ef82962b7
yuvj440p 7b469444994d8b52766ee461bcb795ea
yuvj444p b395162325af489c465a3e6a31fbb0e7
yuyv422 1efb17cd0a48d2e956fd574ea6f412e7