Commit 0407a79e authored by Stefano Sabatini's avatar Stefano Sabatini

lavfi/blackframe: add support for named options

parent 356922e2
...@@ -1801,16 +1801,22 @@ the position in the file if known or -1 and the timestamp in seconds. ...@@ -1801,16 +1801,22 @@ the position in the file if known or -1 and the timestamp in seconds.
In order to display the output lines, you need to set the loglevel at In order to display the output lines, you need to set the loglevel at
least to the AV_LOG_INFO value. least to the AV_LOG_INFO value.
The filter accepts the syntax: The filter accepts parameters as a list of @var{key}=@var{value}
@example pairs, separated by ":". If the key of the first options is omitted,
blackframe[=@var{amount}:[@var{threshold}]] the arguments are interpreted according to the syntax
@end example blackframe[=@var{amount}[:@var{threshold}]].
@var{amount} is the percentage of the pixels that have to be below the A description of the accepted options follows.
threshold, and defaults to 98.
@table @option
@item amount
Set the percentage of pixels that have to be below the
threshold to enable black detection. Default value is 98.
@var{threshold} is the threshold below which a pixel value is @item threshold
considered black, and defaults to 32. Set the threshold below which a pixel value is considered
black. Default value is 32.
@end table
@section blend @section blend
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 47 #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, \ #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \ LIBAVFILTER_VERSION_MINOR, \
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "libavutil/internal.h" #include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "avfilter.h" #include "avfilter.h"
#include "internal.h" #include "internal.h"
#include "formats.h" #include "formats.h"
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
#include "video.h" #include "video.h"
typedef struct { typedef struct {
const AVClass *class;
unsigned int bamount; ///< black amount unsigned int bamount; ///< black amount
unsigned int bthresh; ///< black threshold unsigned int bthresh; ///< black threshold
unsigned int frame; ///< frame number unsigned int frame; ///< frame number
...@@ -45,6 +47,17 @@ typedef struct { ...@@ -45,6 +47,17 @@ typedef struct {
unsigned int last_keyframe; ///< frame number of the last received key-frame unsigned int last_keyframe; ///< frame number of the last received key-frame
} BlackFrameContext; } 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 int query_formats(AVFilterContext *ctx)
{ {
static const enum AVPixelFormat pix_fmts[] = { static const enum AVPixelFormat pix_fmts[] = {
...@@ -60,27 +73,27 @@ static int query_formats(AVFilterContext *ctx) ...@@ -60,27 +73,27 @@ static int query_formats(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx, const char *args) static av_cold int init(AVFilterContext *ctx, const char *args)
{ {
BlackFrameContext *blackframe = ctx->priv; BlackFrameContext *blackframe = ctx->priv;
static const char *shorthand[] = { "amount", "thresh", NULL };
int ret;
blackframe->bamount = 98; blackframe->class = &blackframe_class;
blackframe->bthresh = 32; av_opt_set_defaults(blackframe);
blackframe->nblack = 0;
blackframe->frame = 0;
blackframe->last_keyframe = 0;
if (args) if ((ret = av_opt_set_from_string(blackframe, args, shorthand, "=", ":")) < 0)
sscanf(args, "%u:%u", &blackframe->bamount, &blackframe->bthresh); return ret;
av_log(ctx, AV_LOG_VERBOSE, "bamount:%u bthresh:%u\n", av_log(ctx, AV_LOG_VERBOSE, "bamount:%u bthresh:%u\n",
blackframe->bamount, blackframe->bthresh); 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; 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) static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
...@@ -135,10 +148,13 @@ AVFilter avfilter_vf_blackframe = { ...@@ -135,10 +148,13 @@ AVFilter avfilter_vf_blackframe = {
.priv_size = sizeof(BlackFrameContext), .priv_size = sizeof(BlackFrameContext),
.init = init, .init = init,
.uninit = uninit,
.query_formats = query_formats, .query_formats = query_formats,
.inputs = avfilter_vf_blackframe_inputs, .inputs = avfilter_vf_blackframe_inputs,
.outputs = avfilter_vf_blackframe_outputs, .outputs = avfilter_vf_blackframe_outputs,
.priv_class = &blackframe_class,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment