+
+#endif /* CONFIG_XMEDIAN_FILTER */
+
+#if CONFIG_TMEDIAN_FILTER
+static int tmedian_filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+ AVFilterContext *ctx = inlink->dst;
+ AVFilterLink *outlink = ctx->outputs[0];
+ XMedianContext *s = ctx->priv;
+ ThreadData td;
+ AVFrame *out;
+
+ if (s->nb_frames < s->nb_inputs) {
+ s->frames[s->nb_frames] = in;
+ s->nb_frames++;
+ if (s->nb_frames < s->nb_inputs)
+ return 0;
+ } else {
+ av_frame_free(&s->frames[0]);
+ memmove(&s->frames[0], &s->frames[1], sizeof(*s->frames) * (s->nb_inputs - 1));
+ s->frames[s->nb_inputs - 1] = in;
+ }
+
+ if (ctx->is_disabled) {
+ out = av_frame_clone(s->frames[0]);
+ if (!out)
+ return AVERROR(ENOMEM);
+ return ff_filter_frame(outlink, out);
+ }
+
+ out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+ if (!out)
+ return AVERROR(ENOMEM);
+ out->pts = s->frames[0]->pts;
+
+ td.out = out;
+ td.in = s->frames;
+ ctx->internal->execute(ctx, s->median_frames, &td, NULL, FFMIN(s->height[0], ff_filter_get_nb_threads(ctx)));
+
+ return ff_filter_frame(outlink, out);
+}
+
+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 =TFLAGS },
+ { "percentile", "set percentile", OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, .flags =TFLAGS },
+ { NULL },
+};
+
+static const AVFilterPad tmedian_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .filter_frame = tmedian_filter_frame,
+ },
+ { NULL }
+};
+
+static const AVFilterPad tmedian_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .config_props = config_output,
+ },
+ { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(tmedian);
+
+AVFilter ff_vf_tmedian = {
+ .name = "tmedian",
+ .description = NULL_IF_CONFIG_SMALL("Pick median pixels from successive frames."),
+ .priv_size = sizeof(XMedianContext),
+ .priv_class = &tmedian_class,
+ .query_formats = query_formats,
+ .inputs = tmedian_inputs,
+ .outputs = tmedian_outputs,
+ .init = init,
+ .uninit = uninit,
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
+};
+
+#endif /* CONFIG_TMEDIAN_FILTER */