+
+#endif /* CONFIG_MIX_FILTER */
+
+#if CONFIG_TMIX_FILTER
+static int tmix_filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+ AVFilterContext *ctx = inlink->dst;
+ AVFilterLink *outlink = ctx->outputs[0];
+ MixContext *s = ctx->priv;
+ ThreadData td;
+ AVFrame *out;
+
+ if (s->nb_frames < s->nb_inputs) {
+ s->frames[s->nb_frames] = in;
+ s->nb_frames++;
+ 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;
+ }
+
+ 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, mix_frames, &td, NULL, FFMIN(s->height[0], ff_filter_get_nb_threads(ctx)));
+
+ return ff_filter_frame(outlink, out);
+}
+
+static const AVOption tmix_options[] = {
+ { "frames", "set number of successive frames to mix", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=3}, 2, 128, .flags = FLAGS },
+ { "weights", "set weight for each frame", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1 1"}, 0, 0, .flags = FLAGS },
+ { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = FLAGS },
+ { NULL },
+};
+
+static const AVFilterPad inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .filter_frame = tmix_filter_frame,
+ },
+ { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(tmix);
+
+AVFilter ff_vf_tmix = {
+ .name = "tmix",
+ .description = NULL_IF_CONFIG_SMALL("Mix successive video frames."),
+ .priv_size = sizeof(MixContext),
+ .priv_class = &tmix_class,
+ .query_formats = query_formats,
+ .outputs = outputs,
+ .inputs = inputs,
+ .init = init,
+ .uninit = uninit,
+ .flags = AVFILTER_FLAG_SLICE_THREADS,
+};
+
+#endif /* CONFIG_TMIX_FILTER */