2 * Copyright (c) 2020 Paul B Mahol
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/imgutils.h"
22 #include "libavutil/eval.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/pixfmt.h"
31 enum XFadeTransitions {
73 typedef struct XFadeContext {
98 void (*transitionf)(AVFilterContext *ctx, const AVFrame *a, const AVFrame *b, AVFrame *out, float progress,
99 int slice_start, int slice_end, int jobnr);
104 static const char *const var_names[] = { "X", "Y", "W", "H", "A", "B", "PLANE", "P", NULL };
105 enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_A, VAR_B, VAR_PLANE, VAR_PROGRESS, VAR_VARS_NB };
107 typedef struct ThreadData {
108 const AVFrame *xf[2];
113 static int query_formats(AVFilterContext *ctx)
115 static const enum AVPixelFormat pix_fmts[] = {
119 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_GRAY8,
120 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_GBRP9,
121 AV_PIX_FMT_YUV444P10,
122 AV_PIX_FMT_YUVA444P10,
123 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GRAY10,
124 AV_PIX_FMT_YUV444P12,
125 AV_PIX_FMT_YUVA444P12,
126 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GRAY12,
127 AV_PIX_FMT_YUV444P14, AV_PIX_FMT_GBRP14,
128 AV_PIX_FMT_YUV444P16,
129 AV_PIX_FMT_YUVA444P16,
130 AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, AV_PIX_FMT_GRAY16,
134 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
136 return AVERROR(ENOMEM);
137 return ff_set_common_formats(ctx, fmts_list);
140 static av_cold void uninit(AVFilterContext *ctx)
142 XFadeContext *s = ctx->priv;
147 #define OFFSET(x) offsetof(XFadeContext, x)
148 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
150 static const AVOption xfade_options[] = {
151 { "transition", "set cross fade transition", OFFSET(transition), AV_OPT_TYPE_INT, {.i64=FADE}, -1, NB_TRANSITIONS-1, FLAGS, "transition" },
152 { "custom", "custom transition", 0, AV_OPT_TYPE_CONST, {.i64=CUSTOM}, 0, 0, FLAGS, "transition" },
153 { "fade", "fade transition", 0, AV_OPT_TYPE_CONST, {.i64=FADE}, 0, 0, FLAGS, "transition" },
154 { "wipeleft", "wipe left transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPELEFT}, 0, 0, FLAGS, "transition" },
155 { "wiperight", "wipe right transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPERIGHT}, 0, 0, FLAGS, "transition" },
156 { "wipeup", "wipe up transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPEUP}, 0, 0, FLAGS, "transition" },
157 { "wipedown", "wipe down transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPEDOWN}, 0, 0, FLAGS, "transition" },
158 { "slideleft", "slide left transition", 0, AV_OPT_TYPE_CONST, {.i64=SLIDELEFT}, 0, 0, FLAGS, "transition" },
159 { "slideright", "slide right transition", 0, AV_OPT_TYPE_CONST, {.i64=SLIDERIGHT}, 0, 0, FLAGS, "transition" },
160 { "slideup", "slide up transition", 0, AV_OPT_TYPE_CONST, {.i64=SLIDEUP}, 0, 0, FLAGS, "transition" },
161 { "slidedown", "slide down transition", 0, AV_OPT_TYPE_CONST, {.i64=SLIDEDOWN}, 0, 0, FLAGS, "transition" },
162 { "circlecrop", "circle crop transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLECROP}, 0, 0, FLAGS, "transition" },
163 { "rectcrop", "rect crop transition", 0, AV_OPT_TYPE_CONST, {.i64=RECTCROP}, 0, 0, FLAGS, "transition" },
164 { "distance", "distance transition", 0, AV_OPT_TYPE_CONST, {.i64=DISTANCE}, 0, 0, FLAGS, "transition" },
165 { "fadeblack", "fadeblack transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEBLACK}, 0, 0, FLAGS, "transition" },
166 { "fadewhite", "fadewhite transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEWHITE}, 0, 0, FLAGS, "transition" },
167 { "radial", "radial transition", 0, AV_OPT_TYPE_CONST, {.i64=RADIAL}, 0, 0, FLAGS, "transition" },
168 { "smoothleft", "smoothleft transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHLEFT}, 0, 0, FLAGS, "transition" },
169 { "smoothright","smoothright transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHRIGHT},0, 0, FLAGS, "transition" },
170 { "smoothup", "smoothup transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHUP}, 0, 0, FLAGS, "transition" },
171 { "smoothdown", "smoothdown transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHDOWN}, 0, 0, FLAGS, "transition" },
172 { "circleopen", "circleopen transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLEOPEN}, 0, 0, FLAGS, "transition" },
173 { "circleclose","circleclose transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLECLOSE},0, 0, FLAGS, "transition" },
174 { "vertopen", "vert open transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTOPEN}, 0, 0, FLAGS, "transition" },
175 { "vertclose", "vert close transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTCLOSE}, 0, 0, FLAGS, "transition" },
176 { "horzopen", "horz open transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZOPEN}, 0, 0, FLAGS, "transition" },
177 { "horzclose", "horz close transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZCLOSE}, 0, 0, FLAGS, "transition" },
178 { "dissolve", "dissolve transition", 0, AV_OPT_TYPE_CONST, {.i64=DISSOLVE}, 0, 0, FLAGS, "transition" },
179 { "pixelize", "pixelize transition", 0, AV_OPT_TYPE_CONST, {.i64=PIXELIZE}, 0, 0, FLAGS, "transition" },
180 { "diagtl", "diag tl transition", 0, AV_OPT_TYPE_CONST, {.i64=DIAGTL}, 0, 0, FLAGS, "transition" },
181 { "diagtr", "diag tr transition", 0, AV_OPT_TYPE_CONST, {.i64=DIAGTR}, 0, 0, FLAGS, "transition" },
182 { "diagbl", "diag bl transition", 0, AV_OPT_TYPE_CONST, {.i64=DIAGBL}, 0, 0, FLAGS, "transition" },
183 { "diagbr", "diag br transition", 0, AV_OPT_TYPE_CONST, {.i64=DIAGBR}, 0, 0, FLAGS, "transition" },
184 { "hlslice", "hl slice transition", 0, AV_OPT_TYPE_CONST, {.i64=HLSLICE}, 0, 0, FLAGS, "transition" },
185 { "hrslice", "hr slice transition", 0, AV_OPT_TYPE_CONST, {.i64=HRSLICE}, 0, 0, FLAGS, "transition" },
186 { "vuslice", "vu slice transition", 0, AV_OPT_TYPE_CONST, {.i64=VUSLICE}, 0, 0, FLAGS, "transition" },
187 { "vdslice", "vd slice transition", 0, AV_OPT_TYPE_CONST, {.i64=VDSLICE}, 0, 0, FLAGS, "transition" },
188 { "hblur", "hblur transition", 0, AV_OPT_TYPE_CONST, {.i64=HBLUR}, 0, 0, FLAGS, "transition" },
189 { "fadegrays", "fadegrays transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEGRAYS}, 0, 0, FLAGS, "transition" },
190 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
191 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
192 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
196 AVFILTER_DEFINE_CLASS(xfade);
198 #define CUSTOM_TRANSITION(name, type, div) \
199 static void custom##name##_transition(AVFilterContext *ctx, \
200 const AVFrame *a, const AVFrame *b, AVFrame *out, \
202 int slice_start, int slice_end, int jobnr) \
204 XFadeContext *s = ctx->priv; \
205 const int height = slice_end - slice_start; \
207 double values[VAR_VARS_NB]; \
208 values[VAR_W] = out->width; \
209 values[VAR_H] = out->height; \
210 values[VAR_PROGRESS] = progress; \
212 for (int p = 0; p < s->nb_planes; p++) { \
213 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
214 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
215 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
217 values[VAR_PLANE] = p; \
219 for (int y = 0; y < height; y++) { \
220 values[VAR_Y] = slice_start + y; \
221 for (int x = 0; x < out->width; x++) { \
223 values[VAR_A] = xf0[x]; \
224 values[VAR_B] = xf1[x]; \
225 dst[x] = av_expr_eval(s->e, values, s); \
228 dst += out->linesize[p] / div; \
229 xf0 += a->linesize[p] / div; \
230 xf1 += b->linesize[p] / div; \
235 CUSTOM_TRANSITION(8, uint8_t, 1)
236 CUSTOM_TRANSITION(16, uint16_t, 2)
238 static inline float mix(float a, float b, float mix)
240 return a * mix + b * (1.f - mix);
243 static inline float fract(float a)
245 return a - floorf(a);
248 static inline float smoothstep(float edge0, float edge1, float x)
252 t = av_clipf((x - edge0) / (edge1 - edge0), 0.f, 1.f);
254 return t * t * (3.f - 2.f * t);
257 #define FADE_TRANSITION(name, type, div) \
258 static void fade##name##_transition(AVFilterContext *ctx, \
259 const AVFrame *a, const AVFrame *b, AVFrame *out, \
261 int slice_start, int slice_end, int jobnr) \
263 XFadeContext *s = ctx->priv; \
264 const int height = slice_end - slice_start; \
266 for (int p = 0; p < s->nb_planes; p++) { \
267 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
268 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
269 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
271 for (int y = 0; y < height; y++) { \
272 for (int x = 0; x < out->width; x++) { \
273 dst[x] = mix(xf0[x], xf1[x], progress); \
276 dst += out->linesize[p] / div; \
277 xf0 += a->linesize[p] / div; \
278 xf1 += b->linesize[p] / div; \
283 FADE_TRANSITION(8, uint8_t, 1)
284 FADE_TRANSITION(16, uint16_t, 2)
286 #define WIPELEFT_TRANSITION(name, type, div) \
287 static void wipeleft##name##_transition(AVFilterContext *ctx, \
288 const AVFrame *a, const AVFrame *b, AVFrame *out, \
290 int slice_start, int slice_end, int jobnr) \
292 XFadeContext *s = ctx->priv; \
293 const int height = slice_end - slice_start; \
294 const int z = out->width * progress; \
296 for (int p = 0; p < s->nb_planes; p++) { \
297 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
298 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
299 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
301 for (int y = 0; y < height; y++) { \
302 for (int x = 0; x < out->width; x++) { \
303 dst[x] = x > z ? xf1[x] : xf0[x]; \
306 dst += out->linesize[p] / div; \
307 xf0 += a->linesize[p] / div; \
308 xf1 += b->linesize[p] / div; \
313 WIPELEFT_TRANSITION(8, uint8_t, 1)
314 WIPELEFT_TRANSITION(16, uint16_t, 2)
316 #define WIPERIGHT_TRANSITION(name, type, div) \
317 static void wiperight##name##_transition(AVFilterContext *ctx, \
318 const AVFrame *a, const AVFrame *b, AVFrame *out, \
320 int slice_start, int slice_end, int jobnr) \
322 XFadeContext *s = ctx->priv; \
323 const int height = slice_end - slice_start; \
324 const int z = out->width * (1.f - progress); \
326 for (int p = 0; p < s->nb_planes; p++) { \
327 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
328 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
329 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
331 for (int y = 0; y < height; y++) { \
332 for (int x = 0; x < out->width; x++) { \
333 dst[x] = x > z ? xf0[x] : xf1[x]; \
336 dst += out->linesize[p] / div; \
337 xf0 += a->linesize[p] / div; \
338 xf1 += b->linesize[p] / div; \
343 WIPERIGHT_TRANSITION(8, uint8_t, 1)
344 WIPERIGHT_TRANSITION(16, uint16_t, 2)
346 #define WIPEUP_TRANSITION(name, type, div) \
347 static void wipeup##name##_transition(AVFilterContext *ctx, \
348 const AVFrame *a, const AVFrame *b, AVFrame *out, \
350 int slice_start, int slice_end, int jobnr) \
352 XFadeContext *s = ctx->priv; \
353 const int height = slice_end - slice_start; \
354 const int z = out->height * progress; \
356 for (int p = 0; p < s->nb_planes; p++) { \
357 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
358 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
359 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
361 for (int y = 0; y < height; y++) { \
362 for (int x = 0; x < out->width; x++) { \
363 dst[x] = slice_start + y > z ? xf1[x] : xf0[x]; \
366 dst += out->linesize[p] / div; \
367 xf0 += a->linesize[p] / div; \
368 xf1 += b->linesize[p] / div; \
373 WIPEUP_TRANSITION(8, uint8_t, 1)
374 WIPEUP_TRANSITION(16, uint16_t, 2)
376 #define WIPEDOWN_TRANSITION(name, type, div) \
377 static void wipedown##name##_transition(AVFilterContext *ctx, \
378 const AVFrame *a, const AVFrame *b, AVFrame *out, \
380 int slice_start, int slice_end, int jobnr) \
382 XFadeContext *s = ctx->priv; \
383 const int height = slice_end - slice_start; \
384 const int z = out->height * (1.f - progress); \
386 for (int p = 0; p < s->nb_planes; p++) { \
387 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
388 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
389 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
391 for (int y = 0; y < height; y++) { \
392 for (int x = 0; x < out->width; x++) { \
393 dst[x] = slice_start + y > z ? xf0[x] : xf1[x]; \
396 dst += out->linesize[p] / div; \
397 xf0 += a->linesize[p] / div; \
398 xf1 += b->linesize[p] / div; \
403 WIPEDOWN_TRANSITION(8, uint8_t, 1)
404 WIPEDOWN_TRANSITION(16, uint16_t, 2)
406 #define SLIDELEFT_TRANSITION(name, type, div) \
407 static void slideleft##name##_transition(AVFilterContext *ctx, \
408 const AVFrame *a, const AVFrame *b, AVFrame *out, \
410 int slice_start, int slice_end, int jobnr) \
412 XFadeContext *s = ctx->priv; \
413 const int height = slice_end - slice_start; \
414 const int width = out->width; \
415 const int z = -progress * width; \
417 for (int p = 0; p < s->nb_planes; p++) { \
418 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
419 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
420 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
422 for (int y = 0; y < height; y++) { \
423 for (int x = 0; x < width; x++) { \
424 const int zx = z + x; \
425 const int zz = zx % width + width * (zx < 0); \
426 dst[x] = (zx > 0) && (zx < width) ? xf1[zz] : xf0[zz]; \
429 dst += out->linesize[p] / div; \
430 xf0 += a->linesize[p] / div; \
431 xf1 += b->linesize[p] / div; \
436 SLIDELEFT_TRANSITION(8, uint8_t, 1)
437 SLIDELEFT_TRANSITION(16, uint16_t, 2)
439 #define SLIDERIGHT_TRANSITION(name, type, div) \
440 static void slideright##name##_transition(AVFilterContext *ctx, \
441 const AVFrame *a, const AVFrame *b, AVFrame *out, \
443 int slice_start, int slice_end, int jobnr) \
445 XFadeContext *s = ctx->priv; \
446 const int height = slice_end - slice_start; \
447 const int width = out->width; \
448 const int z = progress * width; \
450 for (int p = 0; p < s->nb_planes; p++) { \
451 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
452 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
453 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
455 for (int y = 0; y < height; y++) { \
456 for (int x = 0; x < out->width; x++) { \
457 const int zx = z + x; \
458 const int zz = zx % width + width * (zx < 0); \
459 dst[x] = (zx > 0) && (zx < width) ? xf1[zz] : xf0[zz]; \
462 dst += out->linesize[p] / div; \
463 xf0 += a->linesize[p] / div; \
464 xf1 += b->linesize[p] / div; \
469 SLIDERIGHT_TRANSITION(8, uint8_t, 1)
470 SLIDERIGHT_TRANSITION(16, uint16_t, 2)
472 #define SLIDEUP_TRANSITION(name, type, div) \
473 static void slideup##name##_transition(AVFilterContext *ctx, \
474 const AVFrame *a, const AVFrame *b, AVFrame *out, \
476 int slice_start, int slice_end, int jobnr) \
478 XFadeContext *s = ctx->priv; \
479 const int height = out->height; \
480 const int z = -progress * height; \
482 for (int p = 0; p < s->nb_planes; p++) { \
483 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
485 for (int y = slice_start; y < slice_end; y++) { \
486 const int zy = z + y; \
487 const int zz = zy % height + height * (zy < 0); \
488 const type *xf0 = (const type *)(a->data[p] + zz * a->linesize[p]); \
489 const type *xf1 = (const type *)(b->data[p] + zz * b->linesize[p]); \
491 for (int x = 0; x < out->width; x++) { \
492 dst[x] = (zy > 0) && (zy < height) ? xf1[x] : xf0[x]; \
495 dst += out->linesize[p] / div; \
500 SLIDEUP_TRANSITION(8, uint8_t, 1)
501 SLIDEUP_TRANSITION(16, uint16_t, 2)
503 #define SLIDEDOWN_TRANSITION(name, type, div) \
504 static void slidedown##name##_transition(AVFilterContext *ctx, \
505 const AVFrame *a, const AVFrame *b, AVFrame *out, \
507 int slice_start, int slice_end, int jobnr) \
509 XFadeContext *s = ctx->priv; \
510 const int height = out->height; \
511 const int z = progress * height; \
513 for (int p = 0; p < s->nb_planes; p++) { \
514 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
516 for (int y = slice_start; y < slice_end; y++) { \
517 const int zy = z + y; \
518 const int zz = zy % height + height * (zy < 0); \
519 const type *xf0 = (const type *)(a->data[p] + zz * a->linesize[p]); \
520 const type *xf1 = (const type *)(b->data[p] + zz * b->linesize[p]); \
522 for (int x = 0; x < out->width; x++) { \
523 dst[x] = (zy > 0) && (zy < height) ? xf1[x] : xf0[x]; \
526 dst += out->linesize[p] / div; \
531 SLIDEDOWN_TRANSITION(8, uint8_t, 1)
532 SLIDEDOWN_TRANSITION(16, uint16_t, 2)
534 #define CIRCLECROP_TRANSITION(name, type, div) \
535 static void circlecrop##name##_transition(AVFilterContext *ctx, \
536 const AVFrame *a, const AVFrame *b, AVFrame *out, \
538 int slice_start, int slice_end, int jobnr) \
540 XFadeContext *s = ctx->priv; \
541 const int width = out->width; \
542 const int height = out->height; \
543 float z = powf(2.f * fabsf(progress - 0.5f), 3.f) * hypotf(width/2, height/2); \
545 for (int p = 0; p < s->nb_planes; p++) { \
546 const int bg = s->black[p]; \
547 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
549 for (int y = slice_start; y < slice_end; y++) { \
550 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
551 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
553 for (int x = 0; x < width; x++) { \
554 float dist = hypotf(x - width / 2, y - height / 2); \
555 int val = progress < 0.5f ? xf1[x] : xf0[x]; \
556 dst[x] = (z < dist) ? bg : val; \
559 dst += out->linesize[p] / div; \
564 CIRCLECROP_TRANSITION(8, uint8_t, 1)
565 CIRCLECROP_TRANSITION(16, uint16_t, 2)
567 #define RECTCROP_TRANSITION(name, type, div) \
568 static void rectcrop##name##_transition(AVFilterContext *ctx, \
569 const AVFrame *a, const AVFrame *b, AVFrame *out, \
571 int slice_start, int slice_end, int jobnr) \
573 XFadeContext *s = ctx->priv; \
574 const int width = out->width; \
575 const int height = out->height; \
576 int zh = fabsf(progress - 0.5f) * height; \
577 int zw = fabsf(progress - 0.5f) * width; \
579 for (int p = 0; p < s->nb_planes; p++) { \
580 const int bg = s->black[p]; \
581 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
583 for (int y = slice_start; y < slice_end; y++) { \
584 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
585 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
587 for (int x = 0; x < width; x++) { \
588 int dist = FFABS(x - width / 2) < zw && \
589 FFABS(y - height / 2) < zh; \
590 int val = progress < 0.5f ? xf1[x] : xf0[x]; \
591 dst[x] = !dist ? bg : val; \
594 dst += out->linesize[p] / div; \
599 RECTCROP_TRANSITION(8, uint8_t, 1)
600 RECTCROP_TRANSITION(16, uint16_t, 2)
602 #define DISTANCE_TRANSITION(name, type, div) \
603 static void distance##name##_transition(AVFilterContext *ctx, \
604 const AVFrame *a, const AVFrame *b, AVFrame *out, \
606 int slice_start, int slice_end, int jobnr) \
608 XFadeContext *s = ctx->priv; \
609 const int width = out->width; \
610 const float max = s->max_value; \
612 for (int y = slice_start; y < slice_end; y++) { \
613 for (int x = 0; x < width; x++) { \
615 for (int p = 0; p < s->nb_planes; p++) { \
616 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
617 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
619 dist += (xf0[x] / max - xf1[x] / max) * \
620 (xf0[x] / max - xf1[x] / max); \
623 dist = sqrtf(dist) <= progress; \
624 for (int p = 0; p < s->nb_planes; p++) { \
625 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
626 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
627 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
628 dst[x] = mix(mix(xf0[x], xf1[x], dist), xf1[x], progress); \
634 DISTANCE_TRANSITION(8, uint8_t, 1)
635 DISTANCE_TRANSITION(16, uint16_t, 2)
637 #define FADEBLACK_TRANSITION(name, type, div) \
638 static void fadeblack##name##_transition(AVFilterContext *ctx, \
639 const AVFrame *a, const AVFrame *b, AVFrame *out, \
641 int slice_start, int slice_end, int jobnr) \
643 XFadeContext *s = ctx->priv; \
644 const int height = slice_end - slice_start; \
645 const float phase = 0.2f; \
647 for (int p = 0; p < s->nb_planes; p++) { \
648 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
649 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
650 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
651 const int bg = s->black[p]; \
653 for (int y = 0; y < height; y++) { \
654 for (int x = 0; x < out->width; x++) { \
655 dst[x] = mix(mix(xf0[x], bg, smoothstep(1.f-phase, 1.f, progress)), \
656 mix(bg, xf1[x], smoothstep(phase, 1.f, progress)), \
660 dst += out->linesize[p] / div; \
661 xf0 += a->linesize[p] / div; \
662 xf1 += b->linesize[p] / div; \
667 FADEBLACK_TRANSITION(8, uint8_t, 1)
668 FADEBLACK_TRANSITION(16, uint16_t, 2)
670 #define FADEWHITE_TRANSITION(name, type, div) \
671 static void fadewhite##name##_transition(AVFilterContext *ctx, \
672 const AVFrame *a, const AVFrame *b, AVFrame *out, \
674 int slice_start, int slice_end, int jobnr) \
676 XFadeContext *s = ctx->priv; \
677 const int height = slice_end - slice_start; \
678 const float phase = 0.2f; \
680 for (int p = 0; p < s->nb_planes; p++) { \
681 const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
682 const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
683 type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
684 const int bg = s->white[p]; \
686 for (int y = 0; y < height; y++) { \
687 for (int x = 0; x < out->width; x++) { \
688 dst[x] = mix(mix(xf0[x], bg, smoothstep(1.f-phase, 1.f, progress)), \
689 mix(bg, xf1[x], smoothstep(phase, 1.f, progress)), \
693 dst += out->linesize[p] / div; \
694 xf0 += a->linesize[p] / div; \
695 xf1 += b->linesize[p] / div; \
700 FADEWHITE_TRANSITION(8, uint8_t, 1)
701 FADEWHITE_TRANSITION(16, uint16_t, 2)
703 #define RADIAL_TRANSITION(name, type, div) \
704 static void radial##name##_transition(AVFilterContext *ctx, \
705 const AVFrame *a, const AVFrame *b, AVFrame *out, \
707 int slice_start, int slice_end, int jobnr) \
709 XFadeContext *s = ctx->priv; \
710 const int width = out->width; \
711 const int height = out->height; \
713 for (int y = slice_start; y < slice_end; y++) { \
714 for (int x = 0; x < width; x++) { \
715 const float smooth = atan2f(x - width / 2, y - height / 2) - \
716 (progress - 0.5f) * (M_PI * 2.5f); \
717 for (int p = 0; p < s->nb_planes; p++) { \
718 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
719 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
720 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
722 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
728 RADIAL_TRANSITION(8, uint8_t, 1)
729 RADIAL_TRANSITION(16, uint16_t, 2)
731 #define SMOOTHLEFT_TRANSITION(name, type, div) \
732 static void smoothleft##name##_transition(AVFilterContext *ctx, \
733 const AVFrame *a, const AVFrame *b, AVFrame *out, \
735 int slice_start, int slice_end, int jobnr) \
737 XFadeContext *s = ctx->priv; \
738 const int width = out->width; \
739 const float w = width; \
741 for (int y = slice_start; y < slice_end; y++) { \
742 for (int x = 0; x < width; x++) { \
743 const float smooth = 1.f + x / w - progress * 2.f; \
745 for (int p = 0; p < s->nb_planes; p++) { \
746 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
747 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
748 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
750 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
756 SMOOTHLEFT_TRANSITION(8, uint8_t, 1)
757 SMOOTHLEFT_TRANSITION(16, uint16_t, 2)
759 #define SMOOTHRIGHT_TRANSITION(name, type, div) \
760 static void smoothright##name##_transition(AVFilterContext *ctx, \
761 const AVFrame *a, const AVFrame *b, AVFrame *out, \
763 int slice_start, int slice_end, int jobnr) \
765 XFadeContext *s = ctx->priv; \
766 const int width = out->width; \
767 const float w = width; \
769 for (int y = slice_start; y < slice_end; y++) { \
770 for (int x = 0; x < width; x++) { \
771 const float smooth = 1.f + (w - 1 - x) / w - progress * 2.f; \
773 for (int p = 0; p < s->nb_planes; p++) { \
774 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
775 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
776 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
778 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
784 SMOOTHRIGHT_TRANSITION(8, uint8_t, 1)
785 SMOOTHRIGHT_TRANSITION(16, uint16_t, 2)
787 #define SMOOTHUP_TRANSITION(name, type, div) \
788 static void smoothup##name##_transition(AVFilterContext *ctx, \
789 const AVFrame *a, const AVFrame *b, AVFrame *out, \
791 int slice_start, int slice_end, int jobnr) \
793 XFadeContext *s = ctx->priv; \
794 const int width = out->width; \
795 const float h = out->height; \
797 for (int y = slice_start; y < slice_end; y++) { \
798 const float smooth = 1.f + y / h - progress * 2.f; \
799 for (int x = 0; x < width; x++) { \
800 for (int p = 0; p < s->nb_planes; p++) { \
801 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
802 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
803 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
805 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
811 SMOOTHUP_TRANSITION(8, uint8_t, 1)
812 SMOOTHUP_TRANSITION(16, uint16_t, 2)
814 #define SMOOTHDOWN_TRANSITION(name, type, div) \
815 static void smoothdown##name##_transition(AVFilterContext *ctx, \
816 const AVFrame *a, const AVFrame *b, AVFrame *out, \
818 int slice_start, int slice_end, int jobnr) \
820 XFadeContext *s = ctx->priv; \
821 const int width = out->width; \
822 const float h = out->height; \
824 for (int y = slice_start; y < slice_end; y++) { \
825 const float smooth = 1.f + (h - 1 - y) / h - progress * 2.f; \
826 for (int x = 0; x < width; x++) { \
827 for (int p = 0; p < s->nb_planes; p++) { \
828 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
829 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
830 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
832 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
838 SMOOTHDOWN_TRANSITION(8, uint8_t, 1)
839 SMOOTHDOWN_TRANSITION(16, uint16_t, 2)
841 #define CIRCLEOPEN_TRANSITION(name, type, div) \
842 static void circleopen##name##_transition(AVFilterContext *ctx, \
843 const AVFrame *a, const AVFrame *b, AVFrame *out, \
845 int slice_start, int slice_end, int jobnr) \
847 XFadeContext *s = ctx->priv; \
848 const int width = out->width; \
849 const int height = out->height; \
850 const float z = hypotf(width / 2, height / 2); \
851 const float p = (progress - 0.5f) * 3.f; \
853 for (int y = slice_start; y < slice_end; y++) { \
854 for (int x = 0; x < width; x++) { \
855 const float smooth = hypotf(x - width / 2, y - height / 2) / z + p; \
856 for (int p = 0; p < s->nb_planes; p++) { \
857 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
858 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
859 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
861 dst[x] = mix(xf0[x], xf1[x], smoothstep(0.f, 1.f, smooth)); \
867 CIRCLEOPEN_TRANSITION(8, uint8_t, 1)
868 CIRCLEOPEN_TRANSITION(16, uint16_t, 2)
870 #define CIRCLECLOSE_TRANSITION(name, type, div) \
871 static void circleclose##name##_transition(AVFilterContext *ctx, \
872 const AVFrame *a, const AVFrame *b, AVFrame *out, \
874 int slice_start, int slice_end, int jobnr) \
876 XFadeContext *s = ctx->priv; \
877 const int width = out->width; \
878 const int height = out->height; \
879 const float z = hypotf(width / 2, height / 2); \
880 const float p = (1.f - progress - 0.5f) * 3.f; \
882 for (int y = slice_start; y < slice_end; y++) { \
883 for (int x = 0; x < width; x++) { \
884 const float smooth = hypotf(x - width / 2, y - height / 2) / z + p; \
885 for (int p = 0; p < s->nb_planes; p++) { \
886 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
887 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
888 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
890 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
896 CIRCLECLOSE_TRANSITION(8, uint8_t, 1)
897 CIRCLECLOSE_TRANSITION(16, uint16_t, 2)
899 #define VERTOPEN_TRANSITION(name, type, div) \
900 static void vertopen##name##_transition(AVFilterContext *ctx, \
901 const AVFrame *a, const AVFrame *b, AVFrame *out, \
903 int slice_start, int slice_end, int jobnr) \
905 XFadeContext *s = ctx->priv; \
906 const int width = out->width; \
907 const float w2 = out->width / 2; \
909 for (int y = slice_start; y < slice_end; y++) { \
910 for (int x = 0; x < width; x++) { \
911 const float smooth = 2.f - fabsf((x - w2) / w2) - progress * 2.f; \
912 for (int p = 0; p < s->nb_planes; p++) { \
913 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
914 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
915 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
917 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
923 VERTOPEN_TRANSITION(8, uint8_t, 1)
924 VERTOPEN_TRANSITION(16, uint16_t, 2)
926 #define VERTCLOSE_TRANSITION(name, type, div) \
927 static void vertclose##name##_transition(AVFilterContext *ctx, \
928 const AVFrame *a, const AVFrame *b, AVFrame *out, \
930 int slice_start, int slice_end, int jobnr) \
932 XFadeContext *s = ctx->priv; \
933 const int width = out->width; \
934 const float w2 = out->width / 2; \
936 for (int y = slice_start; y < slice_end; y++) { \
937 for (int x = 0; x < width; x++) { \
938 const float smooth = 1.f + fabsf((x - w2) / w2) - progress * 2.f; \
939 for (int p = 0; p < s->nb_planes; p++) { \
940 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
941 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
942 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
944 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
950 VERTCLOSE_TRANSITION(8, uint8_t, 1)
951 VERTCLOSE_TRANSITION(16, uint16_t, 2)
953 #define HORZOPEN_TRANSITION(name, type, div) \
954 static void horzopen##name##_transition(AVFilterContext *ctx, \
955 const AVFrame *a, const AVFrame *b, AVFrame *out, \
957 int slice_start, int slice_end, int jobnr) \
959 XFadeContext *s = ctx->priv; \
960 const int width = out->width; \
961 const float h2 = out->height / 2; \
963 for (int y = slice_start; y < slice_end; y++) { \
964 const float smooth = 2.f - fabsf((y - h2) / h2) - progress * 2.f; \
965 for (int x = 0; x < width; x++) { \
966 for (int p = 0; p < s->nb_planes; p++) { \
967 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
968 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
969 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
971 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
977 HORZOPEN_TRANSITION(8, uint8_t, 1)
978 HORZOPEN_TRANSITION(16, uint16_t, 2)
980 #define HORZCLOSE_TRANSITION(name, type, div) \
981 static void horzclose##name##_transition(AVFilterContext *ctx, \
982 const AVFrame *a, const AVFrame *b, AVFrame *out, \
984 int slice_start, int slice_end, int jobnr) \
986 XFadeContext *s = ctx->priv; \
987 const int width = out->width; \
988 const float h2 = out->height / 2; \
990 for (int y = slice_start; y < slice_end; y++) { \
991 const float smooth = 1.f + fabsf((y - h2) / h2) - progress * 2.f; \
992 for (int x = 0; x < width; x++) { \
993 for (int p = 0; p < s->nb_planes; p++) { \
994 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
995 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
996 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
998 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
1004 HORZCLOSE_TRANSITION(8, uint8_t, 1)
1005 HORZCLOSE_TRANSITION(16, uint16_t, 2)
1007 static float frand(int x, int y)
1009 const float r = sinf(x * 12.9898f + y * 78.233f) * 43758.545f;
1011 return r - floorf(r);
1014 #define DISSOLVE_TRANSITION(name, type, div) \
1015 static void dissolve##name##_transition(AVFilterContext *ctx, \
1016 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1018 int slice_start, int slice_end, int jobnr) \
1020 XFadeContext *s = ctx->priv; \
1021 const int width = out->width; \
1023 for (int y = slice_start; y < slice_end; y++) { \
1024 for (int x = 0; x < width; x++) { \
1025 const float smooth = frand(x, y) * 2.f + progress * 2.f - 1.5f; \
1026 for (int p = 0; p < s->nb_planes; p++) { \
1027 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1028 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1029 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1031 dst[x] = smooth >= 0.5f ? xf0[x] : xf1[x]; \
1037 DISSOLVE_TRANSITION(8, uint8_t, 1)
1038 DISSOLVE_TRANSITION(16, uint16_t, 2)
1040 #define PIXELIZE_TRANSITION(name, type, div) \
1041 static void pixelize##name##_transition(AVFilterContext *ctx, \
1042 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1044 int slice_start, int slice_end, int jobnr) \
1046 XFadeContext *s = ctx->priv; \
1047 const int w = out->width; \
1048 const int h = out->height; \
1049 const float d = fminf(progress, 1.f - progress); \
1050 const float dist = ceilf(d * 50.f) / 50.f; \
1051 const float sqx = 2.f * dist * FFMIN(w, h) / 20.f; \
1052 const float sqy = 2.f * dist * FFMIN(w, h) / 20.f; \
1054 for (int y = slice_start; y < slice_end; y++) { \
1055 for (int x = 0; x < w; x++) { \
1056 int sx = dist > 0.f ? FFMIN((floorf(x / sqx) + .5f) * sqx, w - 1) : x; \
1057 int sy = dist > 0.f ? FFMIN((floorf(y / sqy) + .5f) * sqy, h - 1) : y; \
1058 for (int p = 0; p < s->nb_planes; p++) { \
1059 const type *xf0 = (const type *)(a->data[p] + sy * a->linesize[p]); \
1060 const type *xf1 = (const type *)(b->data[p] + sy * b->linesize[p]); \
1061 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1063 dst[x] = mix(xf0[sx], xf1[sx], progress); \
1069 PIXELIZE_TRANSITION(8, uint8_t, 1)
1070 PIXELIZE_TRANSITION(16, uint16_t, 2)
1072 #define DIAGTL_TRANSITION(name, type, div) \
1073 static void diagtl##name##_transition(AVFilterContext *ctx, \
1074 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1076 int slice_start, int slice_end, int jobnr) \
1078 XFadeContext *s = ctx->priv; \
1079 const int width = out->width; \
1080 const float w = width; \
1081 const float h = out->height; \
1083 for (int y = slice_start; y < slice_end; y++) { \
1084 for (int x = 0; x < width; x++) { \
1085 const float smooth = 1.f + x / w * y / h - progress * 2.f; \
1087 for (int p = 0; p < s->nb_planes; p++) { \
1088 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1089 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1090 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1092 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
1098 DIAGTL_TRANSITION(8, uint8_t, 1)
1099 DIAGTL_TRANSITION(16, uint16_t, 2)
1101 #define DIAGTR_TRANSITION(name, type, div) \
1102 static void diagtr##name##_transition(AVFilterContext *ctx, \
1103 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1105 int slice_start, int slice_end, int jobnr) \
1107 XFadeContext *s = ctx->priv; \
1108 const int width = out->width; \
1109 const float w = width; \
1110 const float h = out->height; \
1112 for (int y = slice_start; y < slice_end; y++) { \
1113 for (int x = 0; x < width; x++) { \
1114 const float smooth = 1.f + (w - 1 - x) / w * y / h - progress * 2.f; \
1116 for (int p = 0; p < s->nb_planes; p++) { \
1117 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1118 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1119 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1121 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
1127 DIAGTR_TRANSITION(8, uint8_t, 1)
1128 DIAGTR_TRANSITION(16, uint16_t, 2)
1130 #define DIAGBL_TRANSITION(name, type, div) \
1131 static void diagbl##name##_transition(AVFilterContext *ctx, \
1132 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1134 int slice_start, int slice_end, int jobnr) \
1136 XFadeContext *s = ctx->priv; \
1137 const int width = out->width; \
1138 const float w = width; \
1139 const float h = out->height; \
1141 for (int y = slice_start; y < slice_end; y++) { \
1142 for (int x = 0; x < width; x++) { \
1143 const float smooth = 1.f + x / w * (h - 1 - y) / h - progress * 2.f; \
1145 for (int p = 0; p < s->nb_planes; p++) { \
1146 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1147 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1148 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1150 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
1156 DIAGBL_TRANSITION(8, uint8_t, 1)
1157 DIAGBL_TRANSITION(16, uint16_t, 2)
1159 #define DIAGBR_TRANSITION(name, type, div) \
1160 static void diagbr##name##_transition(AVFilterContext *ctx, \
1161 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1163 int slice_start, int slice_end, int jobnr) \
1165 XFadeContext *s = ctx->priv; \
1166 const int width = out->width; \
1167 const float w = width; \
1168 const float h = out->height; \
1170 for (int y = slice_start; y < slice_end; y++) { \
1171 for (int x = 0; x < width; x++) { \
1172 const float smooth = 1.f + (w - 1 - x) / w * (h - 1 - y) / h - \
1175 for (int p = 0; p < s->nb_planes; p++) { \
1176 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1177 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1178 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1180 dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
1186 DIAGBR_TRANSITION(8, uint8_t, 1)
1187 DIAGBR_TRANSITION(16, uint16_t, 2)
1189 #define HLSLICE_TRANSITION(name, type, div) \
1190 static void hlslice##name##_transition(AVFilterContext *ctx, \
1191 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1193 int slice_start, int slice_end, int jobnr) \
1195 XFadeContext *s = ctx->priv; \
1196 const int width = out->width; \
1197 const float w = width; \
1199 for (int y = slice_start; y < slice_end; y++) { \
1200 for (int x = 0; x < width; x++) { \
1201 const float smooth = smoothstep(-0.5f, 0.f, x / w - progress * 1.5f); \
1202 const float ss = smooth <= fract(10.f * x / w) ? 0.f : 1.f; \
1204 for (int p = 0; p < s->nb_planes; p++) { \
1205 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1206 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1207 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1209 dst[x] = mix(xf1[x], xf0[x], ss); \
1215 HLSLICE_TRANSITION(8, uint8_t, 1)
1216 HLSLICE_TRANSITION(16, uint16_t, 2)
1218 #define HRSLICE_TRANSITION(name, type, div) \
1219 static void hrslice##name##_transition(AVFilterContext *ctx, \
1220 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1222 int slice_start, int slice_end, int jobnr) \
1224 XFadeContext *s = ctx->priv; \
1225 const int width = out->width; \
1226 const float w = width; \
1228 for (int y = slice_start; y < slice_end; y++) { \
1229 for (int x = 0; x < width; x++) { \
1230 const float xx = (w - 1 - x) / w; \
1231 const float smooth = smoothstep(-0.5f, 0.f, xx - progress * 1.5f); \
1232 const float ss = smooth <= fract(10.f * xx) ? 0.f : 1.f; \
1234 for (int p = 0; p < s->nb_planes; p++) { \
1235 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1236 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1237 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1239 dst[x] = mix(xf1[x], xf0[x], ss); \
1245 HRSLICE_TRANSITION(8, uint8_t, 1)
1246 HRSLICE_TRANSITION(16, uint16_t, 2)
1248 #define VUSLICE_TRANSITION(name, type, div) \
1249 static void vuslice##name##_transition(AVFilterContext *ctx, \
1250 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1252 int slice_start, int slice_end, int jobnr) \
1254 XFadeContext *s = ctx->priv; \
1255 const int width = out->width; \
1256 const float h = out->height; \
1258 for (int y = slice_start; y < slice_end; y++) { \
1259 const float smooth = smoothstep(-0.5f, 0.f, y / h - progress * 1.5f); \
1260 const float ss = smooth <= fract(10.f * y / h) ? 0.f : 1.f; \
1262 for (int x = 0; x < width; x++) { \
1263 for (int p = 0; p < s->nb_planes; p++) { \
1264 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1265 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1266 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1268 dst[x] = mix(xf1[x], xf0[x], ss); \
1274 VUSLICE_TRANSITION(8, uint8_t, 1)
1275 VUSLICE_TRANSITION(16, uint16_t, 2)
1277 #define VDSLICE_TRANSITION(name, type, div) \
1278 static void vdslice##name##_transition(AVFilterContext *ctx, \
1279 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1281 int slice_start, int slice_end, int jobnr) \
1283 XFadeContext *s = ctx->priv; \
1284 const int width = out->width; \
1285 const float h = out->height; \
1287 for (int y = slice_start; y < slice_end; y++) { \
1288 const float yy = (h - 1 - y) / h; \
1289 const float smooth = smoothstep(-0.5f, 0.f, yy - progress * 1.5f); \
1290 const float ss = smooth <= fract(10.f * yy) ? 0.f : 1.f; \
1292 for (int x = 0; x < width; x++) { \
1293 for (int p = 0; p < s->nb_planes; p++) { \
1294 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1295 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1296 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1298 dst[x] = mix(xf1[x], xf0[x], ss); \
1304 VDSLICE_TRANSITION(8, uint8_t, 1)
1305 VDSLICE_TRANSITION(16, uint16_t, 2)
1307 #define HBLUR_TRANSITION(name, type, div) \
1308 static void hblur##name##_transition(AVFilterContext *ctx, \
1309 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1311 int slice_start, int slice_end, int jobnr) \
1313 XFadeContext *s = ctx->priv; \
1314 const int width = out->width; \
1315 const float prog = progress <= 0.5f ? progress * 2.f : (1.f - progress) * 2.f; \
1316 const int size = 1 + (width / 2) * prog; \
1318 for (int y = slice_start; y < slice_end; y++) { \
1319 for (int p = 0; p < s->nb_planes; p++) { \
1320 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1321 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1322 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1327 for (int x = 0; x < size; x++) { \
1332 for (int x = 0; x < width; x++) { \
1333 dst[x] = mix(sum0 / cnt, sum1 / cnt, progress); \
1335 if (x + size < width) { \
1336 sum0 += xf0[x + size] - xf0[x]; \
1337 sum1 += xf1[x + size] - xf1[x]; \
1348 HBLUR_TRANSITION(8, uint8_t, 1)
1349 HBLUR_TRANSITION(16, uint16_t, 2)
1351 #define FADEGRAYS_TRANSITION(name, type, div) \
1352 static void fadegrays##name##_transition(AVFilterContext *ctx, \
1353 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1355 int slice_start, int slice_end, int jobnr) \
1357 XFadeContext *s = ctx->priv; \
1358 const int width = out->width; \
1359 const int is_rgb = s->is_rgb; \
1360 const int mid = (s->max_value + 1) / 2; \
1361 const float phase = 0.2f; \
1363 for (int y = slice_start; y < slice_end; y++) { \
1364 for (int x = 0; x < width; x++) { \
1367 for (int p = 0; p < s->nb_planes; p++) { \
1368 const type *xf0 = (const type *)(a->data[p] + \
1369 y * a->linesize[p]); \
1370 const type *xf1 = (const type *)(b->data[p] + \
1371 y * b->linesize[p]); \
1372 bg[0][0] += xf0[x]; \
1373 bg[1][0] += xf1[x]; \
1375 bg[0][3] = xf0[x]; \
1376 bg[1][3] = xf1[x]; \
1379 bg[0][0] = bg[0][0] / s->nb_planes; \
1380 bg[1][0] = bg[1][0] / s->nb_planes; \
1381 bg[0][1] = bg[0][2] = bg[0][0]; \
1382 bg[1][1] = bg[1][2] = bg[1][0]; \
1384 const type *yf0 = (const type *)(a->data[0] + \
1385 y * a->linesize[0]); \
1386 const type *yf1 = (const type *)(b->data[0] + \
1387 y * a->linesize[0]); \
1388 bg[0][0] = yf0[x]; \
1389 bg[1][0] = yf1[x]; \
1390 if (s->nb_planes == 4) { \
1391 const type *af0 = (const type *)(a->data[3] + \
1392 y * a->linesize[3]); \
1393 const type *af1 = (const type *)(b->data[3] + \
1394 y * a->linesize[3]); \
1395 bg[0][3] = af0[x]; \
1396 bg[1][3] = af1[x]; \
1398 bg[0][1] = bg[1][1] = mid; \
1399 bg[0][2] = bg[1][2] = mid; \
1402 for (int p = 0; p < s->nb_planes; p++) { \
1403 const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1404 const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1405 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1407 dst[x] = mix(mix(xf0[x], bg[0][p], \
1408 smoothstep(1.f-phase, 1.f, progress)), \
1409 mix(bg[1][p], xf1[x], smoothstep(phase, 1.f, progress)), \
1416 FADEGRAYS_TRANSITION(8, uint8_t, 1)
1417 FADEGRAYS_TRANSITION(16, uint16_t, 2)
1419 static inline double getpix(void *priv, double x, double y, int plane, int nb)
1421 XFadeContext *s = priv;
1422 AVFrame *in = s->xf[nb];
1423 const uint8_t *src = in->data[FFMIN(plane, s->nb_planes - 1)];
1424 int linesize = in->linesize[FFMIN(plane, s->nb_planes - 1)];
1425 const int w = in->width;
1426 const int h = in->height;
1430 xi = av_clipd(x, 0, w - 1);
1431 yi = av_clipd(y, 0, h - 1);
1434 const uint16_t *src16 = (const uint16_t*)src;
1437 return src16[xi + yi * linesize];
1439 return src[xi + yi * linesize];
1443 static double a0(void *priv, double x, double y) { return getpix(priv, x, y, 0, 0); }
1444 static double a1(void *priv, double x, double y) { return getpix(priv, x, y, 1, 0); }
1445 static double a2(void *priv, double x, double y) { return getpix(priv, x, y, 2, 0); }
1446 static double a3(void *priv, double x, double y) { return getpix(priv, x, y, 3, 0); }
1448 static double b0(void *priv, double x, double y) { return getpix(priv, x, y, 0, 1); }
1449 static double b1(void *priv, double x, double y) { return getpix(priv, x, y, 1, 1); }
1450 static double b2(void *priv, double x, double y) { return getpix(priv, x, y, 2, 1); }
1451 static double b3(void *priv, double x, double y) { return getpix(priv, x, y, 3, 1); }
1453 static int config_output(AVFilterLink *outlink)
1455 AVFilterContext *ctx = outlink->src;
1456 AVFilterLink *inlink0 = ctx->inputs[0];
1457 AVFilterLink *inlink1 = ctx->inputs[1];
1458 XFadeContext *s = ctx->priv;
1459 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink0->format);
1461 if (inlink0->format != inlink1->format) {
1462 av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
1463 return AVERROR(EINVAL);
1465 if (inlink0->w != inlink1->w || inlink0->h != inlink1->h) {
1466 av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
1467 "(size %dx%d) do not match the corresponding "
1468 "second input link %s parameters (size %dx%d)\n",
1469 ctx->input_pads[0].name, inlink0->w, inlink0->h,
1470 ctx->input_pads[1].name, inlink1->w, inlink1->h);
1471 return AVERROR(EINVAL);
1474 if (inlink0->time_base.num != inlink1->time_base.num ||
1475 inlink0->time_base.den != inlink1->time_base.den) {
1476 av_log(ctx, AV_LOG_ERROR, "First input link %s timebase "
1477 "(%d/%d) do not match the corresponding "
1478 "second input link %s timebase (%d/%d)\n",
1479 ctx->input_pads[0].name, inlink0->time_base.num, inlink0->time_base.den,
1480 ctx->input_pads[1].name, inlink1->time_base.num, inlink1->time_base.den);
1481 return AVERROR(EINVAL);
1484 if (!inlink0->frame_rate.num || !inlink0->frame_rate.den) {
1485 av_log(ctx, AV_LOG_ERROR, "The inputs needs to be a constant frame rate; "
1486 "current rate of %d/%d is invalid\n", inlink0->frame_rate.num, inlink0->frame_rate.den);
1487 return AVERROR(EINVAL);
1490 if (inlink0->frame_rate.num != inlink1->frame_rate.num ||
1491 inlink0->frame_rate.den != inlink1->frame_rate.den) {
1492 av_log(ctx, AV_LOG_ERROR, "First input link %s frame rate "
1493 "(%d/%d) do not match the corresponding "
1494 "second input link %s frame rate (%d/%d)\n",
1495 ctx->input_pads[0].name, inlink0->frame_rate.num, inlink0->frame_rate.den,
1496 ctx->input_pads[1].name, inlink1->frame_rate.num, inlink1->frame_rate.den);
1497 return AVERROR(EINVAL);
1500 outlink->w = inlink0->w;
1501 outlink->h = inlink0->h;
1502 outlink->time_base = inlink0->time_base;
1503 outlink->sample_aspect_ratio = inlink0->sample_aspect_ratio;
1504 outlink->frame_rate = inlink0->frame_rate;
1506 s->depth = pix_desc->comp[0].depth;
1507 s->is_rgb = !!(pix_desc->flags & AV_PIX_FMT_FLAG_RGB);
1508 s->nb_planes = av_pix_fmt_count_planes(inlink0->format);
1509 s->max_value = (1 << s->depth) - 1;
1511 s->black[1] = s->black[2] = s->is_rgb ? 0 : s->max_value / 2;
1512 s->black[3] = s->max_value;
1513 s->white[0] = s->white[3] = s->max_value;
1514 s->white[1] = s->white[2] = s->is_rgb ? s->max_value : s->max_value / 2;
1516 s->first_pts = s->last_pts = s->pts = AV_NOPTS_VALUE;
1519 s->duration_pts = av_rescale_q(s->duration, AV_TIME_BASE_Q, outlink->time_base);
1521 s->offset_pts = av_rescale_q(s->offset, AV_TIME_BASE_Q, outlink->time_base);
1523 switch (s->transition) {
1524 case CUSTOM: s->transitionf = s->depth <= 8 ? custom8_transition : custom16_transition; break;
1525 case FADE: s->transitionf = s->depth <= 8 ? fade8_transition : fade16_transition; break;
1526 case WIPELEFT: s->transitionf = s->depth <= 8 ? wipeleft8_transition : wipeleft16_transition; break;
1527 case WIPERIGHT: s->transitionf = s->depth <= 8 ? wiperight8_transition : wiperight16_transition; break;
1528 case WIPEUP: s->transitionf = s->depth <= 8 ? wipeup8_transition : wipeup16_transition; break;
1529 case WIPEDOWN: s->transitionf = s->depth <= 8 ? wipedown8_transition : wipedown16_transition; break;
1530 case SLIDELEFT: s->transitionf = s->depth <= 8 ? slideleft8_transition : slideleft16_transition; break;
1531 case SLIDERIGHT: s->transitionf = s->depth <= 8 ? slideright8_transition : slideright16_transition; break;
1532 case SLIDEUP: s->transitionf = s->depth <= 8 ? slideup8_transition : slideup16_transition; break;
1533 case SLIDEDOWN: s->transitionf = s->depth <= 8 ? slidedown8_transition : slidedown16_transition; break;
1534 case CIRCLECROP: s->transitionf = s->depth <= 8 ? circlecrop8_transition : circlecrop16_transition; break;
1535 case RECTCROP: s->transitionf = s->depth <= 8 ? rectcrop8_transition : rectcrop16_transition; break;
1536 case DISTANCE: s->transitionf = s->depth <= 8 ? distance8_transition : distance16_transition; break;
1537 case FADEBLACK: s->transitionf = s->depth <= 8 ? fadeblack8_transition : fadeblack16_transition; break;
1538 case FADEWHITE: s->transitionf = s->depth <= 8 ? fadewhite8_transition : fadewhite16_transition; break;
1539 case RADIAL: s->transitionf = s->depth <= 8 ? radial8_transition : radial16_transition; break;
1540 case SMOOTHLEFT: s->transitionf = s->depth <= 8 ? smoothleft8_transition : smoothleft16_transition; break;
1541 case SMOOTHRIGHT:s->transitionf = s->depth <= 8 ? smoothright8_transition: smoothright16_transition;break;
1542 case SMOOTHUP: s->transitionf = s->depth <= 8 ? smoothup8_transition : smoothup16_transition; break;
1543 case SMOOTHDOWN: s->transitionf = s->depth <= 8 ? smoothdown8_transition : smoothdown16_transition; break;
1544 case CIRCLEOPEN: s->transitionf = s->depth <= 8 ? circleopen8_transition : circleopen16_transition; break;
1545 case CIRCLECLOSE:s->transitionf = s->depth <= 8 ? circleclose8_transition: circleclose16_transition;break;
1546 case VERTOPEN: s->transitionf = s->depth <= 8 ? vertopen8_transition : vertopen16_transition; break;
1547 case VERTCLOSE: s->transitionf = s->depth <= 8 ? vertclose8_transition : vertclose16_transition; break;
1548 case HORZOPEN: s->transitionf = s->depth <= 8 ? horzopen8_transition : horzopen16_transition; break;
1549 case HORZCLOSE: s->transitionf = s->depth <= 8 ? horzclose8_transition : horzclose16_transition; break;
1550 case DISSOLVE: s->transitionf = s->depth <= 8 ? dissolve8_transition : dissolve16_transition; break;
1551 case PIXELIZE: s->transitionf = s->depth <= 8 ? pixelize8_transition : pixelize16_transition; break;
1552 case DIAGTL: s->transitionf = s->depth <= 8 ? diagtl8_transition : diagtl16_transition; break;
1553 case DIAGTR: s->transitionf = s->depth <= 8 ? diagtr8_transition : diagtr16_transition; break;
1554 case DIAGBL: s->transitionf = s->depth <= 8 ? diagbl8_transition : diagbl16_transition; break;
1555 case DIAGBR: s->transitionf = s->depth <= 8 ? diagbr8_transition : diagbr16_transition; break;
1556 case HLSLICE: s->transitionf = s->depth <= 8 ? hlslice8_transition : hlslice16_transition; break;
1557 case HRSLICE: s->transitionf = s->depth <= 8 ? hrslice8_transition : hrslice16_transition; break;
1558 case VUSLICE: s->transitionf = s->depth <= 8 ? vuslice8_transition : vuslice16_transition; break;
1559 case VDSLICE: s->transitionf = s->depth <= 8 ? vdslice8_transition : vdslice16_transition; break;
1560 case HBLUR: s->transitionf = s->depth <= 8 ? hblur8_transition : hblur16_transition; break;
1561 case FADEGRAYS: s->transitionf = s->depth <= 8 ? fadegrays8_transition : fadegrays16_transition; break;
1564 if (s->transition == CUSTOM) {
1565 static const char *const func2_names[] = {
1566 "a0", "a1", "a2", "a3",
1567 "b0", "b1", "b2", "b3",
1570 double (*func2[])(void *, double, double) = {
1577 return AVERROR(EINVAL);
1578 ret = av_expr_parse(&s->e, s->custom_str, var_names,
1579 NULL, NULL, func2_names, func2, 0, ctx);
1587 static int xfade_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
1589 XFadeContext *s = ctx->priv;
1590 AVFilterLink *outlink = ctx->outputs[0];
1591 ThreadData *td = arg;
1592 int slice_start = (outlink->h * jobnr ) / nb_jobs;
1593 int slice_end = (outlink->h * (jobnr+1)) / nb_jobs;
1595 s->transitionf(ctx, td->xf[0], td->xf[1], td->out, td->progress, slice_start, slice_end, jobnr);
1600 static int xfade_frame(AVFilterContext *ctx, AVFrame *a, AVFrame *b)
1602 XFadeContext *s = ctx->priv;
1603 AVFilterLink *outlink = ctx->outputs[0];
1604 float progress = av_clipf(1.f - ((float)(s->pts - s->first_pts - s->offset_pts) / s->duration_pts), 0.f, 1.f);
1608 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
1610 return AVERROR(ENOMEM);
1612 td.xf[0] = a, td.xf[1] = b, td.out = out, td.progress = progress;
1613 ctx->internal->execute(ctx, xfade_slice, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
1617 return ff_filter_frame(outlink, out);
1620 static int xfade_activate(AVFilterContext *ctx)
1622 XFadeContext *s = ctx->priv;
1623 AVFilterLink *outlink = ctx->outputs[0];
1625 int ret = 0, status;
1628 FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
1630 if (s->xfade_is_over) {
1631 ret = ff_inlink_consume_frame(ctx->inputs[1], &in);
1634 } else if (ret > 0) {
1635 in->pts = (in->pts - s->last_pts) + s->pts;
1636 return ff_filter_frame(outlink, in);
1637 } else if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) {
1638 ff_outlink_set_status(outlink, status, s->pts);
1641 if (ff_outlink_frame_wanted(outlink)) {
1642 ff_inlink_request_frame(ctx->inputs[1]);
1648 if (ff_inlink_queued_frames(ctx->inputs[0]) > 0) {
1649 s->xf[0] = ff_inlink_peek_frame(ctx->inputs[0], 0);
1651 if (s->first_pts == AV_NOPTS_VALUE) {
1652 s->first_pts = s->xf[0]->pts;
1654 s->pts = s->xf[0]->pts;
1655 if (s->first_pts + s->offset_pts > s->xf[0]->pts) {
1658 ff_inlink_consume_frame(ctx->inputs[0], &in);
1659 return ff_filter_frame(outlink, in);
1666 if (s->xf[0] && ff_inlink_queued_frames(ctx->inputs[1]) > 0) {
1667 ff_inlink_consume_frame(ctx->inputs[0], &s->xf[0]);
1668 ff_inlink_consume_frame(ctx->inputs[1], &s->xf[1]);
1670 s->last_pts = s->xf[1]->pts;
1671 s->pts = s->xf[0]->pts;
1672 if (s->xf[0]->pts - (s->first_pts + s->offset_pts) > s->duration_pts)
1673 s->xfade_is_over = 1;
1674 ret = xfade_frame(ctx, s->xf[0], s->xf[1]);
1675 av_frame_free(&s->xf[0]);
1676 av_frame_free(&s->xf[1]);
1680 if (ff_inlink_queued_frames(ctx->inputs[0]) > 0 &&
1681 ff_inlink_queued_frames(ctx->inputs[1]) > 0) {
1682 ff_filter_set_ready(ctx, 100);
1686 if (ff_outlink_frame_wanted(outlink)) {
1687 if (!s->eof[0] && ff_outlink_get_status(ctx->inputs[0])) {
1689 s->xfade_is_over = 1;
1691 if (!s->eof[1] && ff_outlink_get_status(ctx->inputs[1])) {
1694 if (!s->eof[0] && !s->xf[0])
1695 ff_inlink_request_frame(ctx->inputs[0]);
1696 if (!s->eof[1] && (s->need_second || s->eof[0]))
1697 ff_inlink_request_frame(ctx->inputs[1]);
1698 if (s->eof[0] && s->eof[1] && (
1699 ff_inlink_queued_frames(ctx->inputs[0]) <= 0 ||
1700 ff_inlink_queued_frames(ctx->inputs[1]) <= 0))
1701 ff_outlink_set_status(outlink, AVERROR_EOF, AV_NOPTS_VALUE);
1705 return FFERROR_NOT_READY;
1708 static const AVFilterPad xfade_inputs[] = {
1711 .type = AVMEDIA_TYPE_VIDEO,
1715 .type = AVMEDIA_TYPE_VIDEO,
1720 static const AVFilterPad xfade_outputs[] = {
1723 .type = AVMEDIA_TYPE_VIDEO,
1724 .config_props = config_output,
1729 AVFilter ff_vf_xfade = {
1731 .description = NULL_IF_CONFIG_SMALL("Cross fade one video with another video."),
1732 .priv_size = sizeof(XFadeContext),
1733 .priv_class = &xfade_class,
1734 .query_formats = query_formats,
1735 .activate = xfade_activate,
1737 .inputs = xfade_inputs,
1738 .outputs = xfade_outputs,
1739 .flags = AVFILTER_FLAG_SLICE_THREADS,