From f7dc6aa6b194ea7b8e0d6f475f8ba04c3cd50a99 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Wed, 2 Jan 2013 11:40:02 +0100 Subject: [PATCH] lavfi/yadif: add support to named options and options introspection Also rename the "enable_auto" field to "deint", to match the name of the option. --- doc/filters.texi | 24 +++++++++++++++++------- libavfilter/version.h | 2 +- libavfilter/vf_yadif.c | 36 ++++++++++++++++++++++++++---------- libavfilter/yadif.h | 4 +++- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 76e8fb53bb..d24abec7bc 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -4290,10 +4290,17 @@ ffmpeg -i in.avi -vf "vflip" out.avi Deinterlace the input video ("yadif" means "yet another deinterlacing filter"). -It accepts the optional parameters: @var{mode}:@var{parity}:@var{auto}. +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". If the key of the first options is omitted, +the arguments are interpreted according to syntax +@var{mode}:@var{parity}:@var{deint}. -@var{mode} specifies the interlacing mode to adopt, accepts one of the -following values: +The description of the accepted parameters follows. + +@table @option +@item mode +Specify the interlacing mode to adopt. Accept one of the following +values: @table @option @item 0 @@ -4308,8 +4315,9 @@ like 1 but skips spatial interlacing check Default value is 0. -@var{parity} specifies the picture field parity assumed for the input -interlaced video, accepts one of the following values: +@item parity +Specify the picture field parity assumed for the input interlaced +video. Accept one of the following values: @table @option @item 0 @@ -4324,8 +4332,9 @@ Default value is -1. If interlacing is unknown or decoder does not export this information, top field first will be assumed. -@var{auto} specifies if deinterlacer should trust the interlaced flag -and only deinterlace frames marked as interlaced +@item deint +Specify which frames to deinterlace. Accept one of the following +values: @table @option @item 0 @@ -4335,6 +4344,7 @@ only deinterlace frames marked as interlaced @end table Default value is 0. +@end table @c man end VIDEO FILTERS diff --git a/libavfilter/version.h b/libavfilter/version.h index 3cc91fbeea..505cea0ded 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MINOR 30 -#define LIBAVFILTER_VERSION_MICRO 102 +#define LIBAVFILTER_VERSION_MICRO 103 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 040c6230f9..824137b178 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -20,6 +20,7 @@ #include "libavutil/avassert.h" #include "libavutil/cpu.h" #include "libavutil/common.h" +#include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" @@ -231,7 +232,7 @@ static int filter_frame(AVFilterLink *link, AVFilterBufferRef *picref) if (!yadif->cur) return 0; - if (yadif->auto_enable && !yadif->cur->video->interlaced) { + if (yadif->deint && !yadif->cur->video->interlaced) { yadif->out = avfilter_ref_buffer(yadif->cur, ~AV_PERM_WRITE); if (!yadif->out) return AVERROR(ENOMEM); @@ -296,6 +297,18 @@ static int request_frame(AVFilterLink *link) return 0; } +#define OFFSET(x) offsetof(YADIFContext, x) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM + +static const AVOption yadif_options[] = { + { "mode", "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS }, + { "parity", "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=-1}, -1, 1, FLAGS }, + { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS }, + {NULL}, +}; + +AVFILTER_DEFINE_CLASS(yadif); + static av_cold void uninit(AVFilterContext *ctx) { YADIFContext *yadif = ctx->priv; @@ -304,6 +317,7 @@ static av_cold void uninit(AVFilterContext *ctx) avfilter_unref_bufferp(&yadif->cur ); avfilter_unref_bufferp(&yadif->next); av_freep(&yadif->temp_line); yadif->temp_line_size = 0; + av_opt_free(yadif); } static int query_formats(AVFilterContext *ctx) @@ -341,23 +355,24 @@ static int query_formats(AVFilterContext *ctx) static av_cold int init(AVFilterContext *ctx, const char *args) { YADIFContext *yadif = ctx->priv; + static const char *shorthand[] = { "mode", "parity", "enable", NULL }; + int ret; - yadif->mode = 0; - yadif->parity = -1; - yadif->auto_enable = 0; yadif->csp = NULL; - if (args) - sscanf(args, "%d:%d:%d", - &yadif->mode, &yadif->parity, &yadif->auto_enable); + yadif->class = &yadif_class; + av_opt_set_defaults(yadif); + + if ((ret = av_opt_set_from_string(yadif, args, shorthand, "=", ":")) < 0) + return ret; yadif->filter_line = filter_line_c; if (ARCH_X86) ff_yadif_init_x86(yadif); - av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d auto_enable:%d\n", - yadif->mode, yadif->parity, yadif->auto_enable); + av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d deint:%d\n", + yadif->mode, yadif->parity, yadif->deint); return 0; } @@ -413,6 +428,7 @@ AVFilter avfilter_vf_yadif = { .query_formats = query_formats, .inputs = avfilter_vf_yadif_inputs, - .outputs = avfilter_vf_yadif_outputs, + + .priv_class = &yadif_class, }; diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h index 41691de65d..22904fb660 100644 --- a/libavfilter/yadif.h +++ b/libavfilter/yadif.h @@ -23,6 +23,8 @@ #include "avfilter.h" typedef struct YADIFContext { + const AVClass *class; + /** * 0: send 1 frame for each frame * 1: send 1 frame for each field @@ -44,7 +46,7 @@ typedef struct YADIFContext { * 0: deinterlace all frames * 1: only deinterlace frames marked as interlaced */ - int auto_enable; + int deint; AVFilterBufferRef *cur; AVFilterBufferRef *next;