From 0407a79e412e7e7229d4e70c8c0df86e4db9066e Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 16 Mar 2013 00:07:15 +0100 Subject: lavfi/blackframe: add support for named options --- libavfilter/version.h | 2 +- libavfilter/vf_blackframe.c | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 13 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/version.h b/libavfilter/version.h index 3ec6f2db46..2698b419d9 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MINOR 47 -#define LIBAVFILTER_VERSION_MICRO 100 +#define LIBAVFILTER_VERSION_MICRO 101 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c index 52c56d8bc2..a69ed97a52 100644 --- a/libavfilter/vf_blackframe.c +++ b/libavfilter/vf_blackframe.c @@ -31,6 +31,7 @@ #include #include "libavutil/internal.h" +#include "libavutil/opt.h" #include "avfilter.h" #include "internal.h" #include "formats.h" @@ -38,6 +39,7 @@ #include "video.h" typedef struct { + const AVClass *class; unsigned int bamount; ///< black amount unsigned int bthresh; ///< black threshold unsigned int frame; ///< frame number @@ -45,6 +47,17 @@ typedef struct { unsigned int last_keyframe; ///< frame number of the last received key-frame } BlackFrameContext; +#define OFFSET(x) offsetof(BlackFrameContext, x) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM + +static const AVOption blackframe_options[] = { + { "amount", "set least percentual amount of pixels below the black threshold enabling black detection", OFFSET(bamount), AV_OPT_TYPE_INT, {.i64=98}, 0, 100, FLAGS }, + { "thresh", "set threshold below which a pixel value is considered black", OFFSET(bthresh), AV_OPT_TYPE_INT, {.i64=32}, 0, 255, FLAGS }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(blackframe); + static int query_formats(AVFilterContext *ctx) { static const enum AVPixelFormat pix_fmts[] = { @@ -60,27 +73,27 @@ static int query_formats(AVFilterContext *ctx) static av_cold int init(AVFilterContext *ctx, const char *args) { BlackFrameContext *blackframe = ctx->priv; + static const char *shorthand[] = { "amount", "thresh", NULL }; + int ret; - blackframe->bamount = 98; - blackframe->bthresh = 32; - blackframe->nblack = 0; - blackframe->frame = 0; - blackframe->last_keyframe = 0; + blackframe->class = &blackframe_class; + av_opt_set_defaults(blackframe); - if (args) - sscanf(args, "%u:%u", &blackframe->bamount, &blackframe->bthresh); + if ((ret = av_opt_set_from_string(blackframe, args, shorthand, "=", ":")) < 0) + return ret; av_log(ctx, AV_LOG_VERBOSE, "bamount:%u bthresh:%u\n", blackframe->bamount, blackframe->bthresh); - if (blackframe->bamount > 100 || blackframe->bthresh > 255) { - av_log(ctx, AV_LOG_ERROR, "Too big value for bamount (max is 100) or bthresh (max is 255)\n"); - return AVERROR(EINVAL); - } - return 0; } +static av_cold void uninit(AVFilterContext *ctx) +{ + BlackFrameContext *blackframe = ctx->priv; + av_opt_free(blackframe); +} + static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { AVFilterContext *ctx = inlink->dst; @@ -135,10 +148,13 @@ AVFilter avfilter_vf_blackframe = { .priv_size = sizeof(BlackFrameContext), .init = init, + .uninit = uninit, .query_formats = query_formats, .inputs = avfilter_vf_blackframe_inputs, .outputs = avfilter_vf_blackframe_outputs, + + .priv_class = &blackframe_class, }; -- cgit v1.2.3