1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-03-17 20:17:55 +02:00

lavfi/setfield: add support to named options and introspection

This commit is contained in:
Stefano Sabatini 2012-12-08 17:35:37 +01:00
parent 0110108a7c
commit 642a60f1c2
3 changed files with 32 additions and 26 deletions

View File

@ -3632,7 +3632,10 @@ output frames. It does not change the input frame, but only sets the
corresponding property, which affects how the frame is treated by corresponding property, which affects how the frame is treated by
following filters (e.g. @code{fieldorder} or @code{yadif}). following filters (e.g. @code{fieldorder} or @code{yadif}).
It accepts a string parameter, which can assume the following values: This filter accepts a single option @option{mode}, which can be
specified either by setting @code{mode=VALUE} either setting the
value alone. Available values are:
@table @samp @table @samp
@item auto @item auto
Keep the same field property. Keep the same field property.

View File

@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 26 #define LIBAVFILTER_VERSION_MINOR 26
#define LIBAVFILTER_VERSION_MICRO 100 #define LIBAVFILTER_VERSION_MICRO 101
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \ LIBAVFILTER_VERSION_MINOR, \

View File

@ -23,6 +23,7 @@
* set field order * set field order
*/ */
#include "libavutil/opt.h"
#include "avfilter.h" #include "avfilter.h"
#include "internal.h" #include "internal.h"
#include "video.h" #include "video.h"
@ -35,39 +36,39 @@ enum SetFieldMode {
}; };
typedef struct { typedef struct {
const AVClass *class;
enum SetFieldMode mode; enum SetFieldMode mode;
} SetFieldContext; } SetFieldContext;
#define OFFSET(x) offsetof(SetFieldContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
static const AVOption setfield_options[] = {
{"mode", "select interlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_AUTO}, -1, MODE_PROG, FLAGS, "mode"},
{"auto", "keep the same input field", 0, AV_OPT_TYPE_CONST, {.i64=MODE_AUTO}, INT_MIN, INT_MAX, FLAGS, "mode"},
{"bff", "mark as bottom-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_BFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
{"tff", "mark as top-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_TFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
{"prog", "mark as progressive", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PROG}, INT_MIN, INT_MAX, FLAGS, "mode"},
{NULL}
};
AVFILTER_DEFINE_CLASS(setfield);
static av_cold int init(AVFilterContext *ctx, const char *args) static av_cold int init(AVFilterContext *ctx, const char *args)
{ {
SetFieldContext *setfield = ctx->priv; SetFieldContext *setfield = ctx->priv;
static const char *shorthand[] = { "mode", NULL };
setfield->mode = MODE_AUTO; setfield->class = &setfield_class;
av_opt_set_defaults(setfield);
if (args) { return av_opt_set_from_string(setfield, args, shorthand, "=", ":");
char c; }
if (sscanf(args, "%d%c", &setfield->mode, &c) != 1) {
if (!strcmp("tff", args)) setfield->mode = MODE_TFF;
else if (!strcmp("bff", args)) setfield->mode = MODE_BFF;
else if (!strcmp("prog", args)) setfield->mode = MODE_PROG;
else if (!strcmp("auto", args)) setfield->mode = MODE_AUTO;
else {
av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
return AVERROR(EINVAL);
}
} else {
if (setfield->mode < -1 || setfield->mode > 1) {
av_log(ctx, AV_LOG_ERROR,
"Provided integer value %d must be included between -1 and +1\n",
setfield->mode);
return AVERROR(EINVAL);
}
av_log(ctx, AV_LOG_WARNING,
"Using -1/0/1 is deprecated, use auto/tff/bff/prog\n");
}
}
return 0; static av_cold void uninit(AVFilterContext *ctx)
{
SetFieldContext *setfield = ctx->priv;
av_opt_free(setfield);
} }
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
@ -105,8 +106,10 @@ AVFilter avfilter_vf_setfield = {
.name = "setfield", .name = "setfield",
.description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."), .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
.init = init, .init = init,
.uninit = uninit,
.priv_size = sizeof(SetFieldContext), .priv_size = sizeof(SetFieldContext),
.inputs = setfield_inputs, .inputs = setfield_inputs,
.outputs = setfield_outputs, .outputs = setfield_outputs,
.priv_class = &setfield_class,
}; };