X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_xmedian.c;h=8b6dd69709bc75adc51a4f9be762da6cdd629cce;hb=c67d2a287502845baadf986a9c63e6117a25be3f;hp=15857d6f149448e39372fd8d984abb4d886f11a6;hpb=9987f6d01e6d50eba378b64b890a6f5885e27989;p=ffmpeg diff --git a/libavfilter/vf_xmedian.c b/libavfilter/vf_xmedian.c index 15857d6f149..8b6dd69709b 100644 --- a/libavfilter/vf_xmedian.c +++ b/libavfilter/vf_xmedian.c @@ -244,14 +244,20 @@ static int process_frame(FFFrameSync *fs) return ret; } - out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (ctx->is_disabled) { + out = av_frame_clone(in[0]); + } else { + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + } if (!out) return AVERROR(ENOMEM); out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base); - td.in = in; - td.out = out; - ctx->internal->execute(ctx, s->median_frames, &td, NULL, FFMIN(s->height[1], ff_filter_get_nb_threads(ctx))); + if (!ctx->is_disabled) { + td.in = in; + td.out = out; + ctx->internal->execute(ctx, s->median_frames, &td, NULL, FFMIN(s->height[1], ff_filter_get_nb_threads(ctx))); + } return ff_filter_frame(outlink, out); } @@ -316,7 +322,7 @@ static int config_output(AVFilterLink *outlink) in[i].time_base = inlink->time_base; in[i].sync = 1; in[i].before = EXT_STOP; - in[i].after = EXT_STOP; + in[i].after = EXT_INFINITY; } ret = ff_framesync_configure(&s->fs); @@ -344,13 +350,32 @@ static int activate(AVFilterContext *ctx) return ff_framesync_activate(&s->fs); } +static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, + char *res, int res_len, int flags) +{ + XMedianContext *s = ctx->priv; + int ret; + + ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags); + if (ret < 0) + return ret; + + if (s->nb_inputs & 1) + s->index = s->radius * 2.f * s->percentile; + else + s->index = av_clip(s->radius * 2.f * s->percentile, 1, s->nb_inputs - 1); + + return 0; +} + #define OFFSET(x) offsetof(XMedianContext, x) #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM +#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM static const AVOption xmedian_options[] = { { "inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=3}, 3, 255, .flags = FLAGS }, - { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, .flags = FLAGS }, - { "percentile", "set percentile", OFFSET(percentile),AV_OPT_TYPE_FLOAT,{.dbl=0.5}, 0, 1, .flags = FLAGS }, + { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, .flags =TFLAGS }, + { "percentile", "set percentile", OFFSET(percentile),AV_OPT_TYPE_FLOAT,{.dbl=0.5}, 0, 1, .flags =TFLAGS }, { NULL }, }; @@ -364,7 +389,7 @@ static const AVFilterPad outputs[] = { }; #if CONFIG_XMEDIAN_FILTER -AVFILTER_DEFINE_CLASS(xmedian); +FRAMESYNC_DEFINE_CLASS(xmedian, XMedianContext, fs); AVFilter ff_vf_xmedian = { .name = "xmedian", @@ -373,10 +398,13 @@ AVFilter ff_vf_xmedian = { .priv_class = &xmedian_class, .query_formats = query_formats, .outputs = outputs, + .preinit = xmedian_framesync_preinit, .init = init, .uninit = uninit, .activate = activate, - .flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS, + .flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS | + AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, + .process_command = process_command, }; #endif /* CONFIG_XMEDIAN_FILTER */ @@ -422,8 +450,8 @@ static int tmedian_filter_frame(AVFilterLink *inlink, AVFrame *in) static const AVOption tmedian_options[] = { { "radius", "set median filter radius", OFFSET(radius), AV_OPT_TYPE_INT, {.i64=1}, 1, 127, .flags = FLAGS }, - { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, .flags = FLAGS }, - { "percentile", "set percentile", OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, .flags = FLAGS }, + { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, .flags =TFLAGS }, + { "percentile", "set percentile", OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, .flags =TFLAGS }, { NULL }, }; @@ -458,6 +486,7 @@ AVFilter ff_vf_tmedian = { .init = init, .uninit = uninit, .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS, + .process_command = process_command, }; #endif /* CONFIG_TMEDIAN_FILTER */