You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1966 lines
128KB

  1. /*
  2. * Copyright (c) 2020 Paul B Mahol
  3. *
  4. * This file is part of FFmpeg.
  5. *
  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.
  10. *
  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.
  15. *
  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
  19. */
  20. #include "libavutil/imgutils.h"
  21. #include "libavutil/eval.h"
  22. #include "libavutil/opt.h"
  23. #include "libavutil/pixfmt.h"
  24. #include "avfilter.h"
  25. #include "formats.h"
  26. #include "internal.h"
  27. #include "filters.h"
  28. #include "video.h"
  29. enum XFadeTransitions {
  30. CUSTOM = -1,
  31. FADE,
  32. WIPELEFT,
  33. WIPERIGHT,
  34. WIPEUP,
  35. WIPEDOWN,
  36. SLIDELEFT,
  37. SLIDERIGHT,
  38. SLIDEUP,
  39. SLIDEDOWN,
  40. CIRCLECROP,
  41. RECTCROP,
  42. DISTANCE,
  43. FADEBLACK,
  44. FADEWHITE,
  45. RADIAL,
  46. SMOOTHLEFT,
  47. SMOOTHRIGHT,
  48. SMOOTHUP,
  49. SMOOTHDOWN,
  50. CIRCLEOPEN,
  51. CIRCLECLOSE,
  52. VERTOPEN,
  53. VERTCLOSE,
  54. HORZOPEN,
  55. HORZCLOSE,
  56. DISSOLVE,
  57. PIXELIZE,
  58. DIAGTL,
  59. DIAGTR,
  60. DIAGBL,
  61. DIAGBR,
  62. HLSLICE,
  63. HRSLICE,
  64. VUSLICE,
  65. VDSLICE,
  66. HBLUR,
  67. FADEGRAYS,
  68. WIPETL,
  69. WIPETR,
  70. WIPEBL,
  71. WIPEBR,
  72. SQUEEZEH,
  73. SQUEEZEV,
  74. NB_TRANSITIONS,
  75. };
  76. typedef struct XFadeContext {
  77. const AVClass *class;
  78. int transition;
  79. int64_t duration;
  80. int64_t offset;
  81. char *custom_str;
  82. int nb_planes;
  83. int depth;
  84. int is_rgb;
  85. int64_t duration_pts;
  86. int64_t offset_pts;
  87. int64_t first_pts;
  88. int64_t last_pts;
  89. int64_t pts;
  90. int xfade_is_over;
  91. int need_second;
  92. int eof[2];
  93. AVFrame *xf[2];
  94. int max_value;
  95. uint16_t black[4];
  96. uint16_t white[4];
  97. void (*transitionf)(AVFilterContext *ctx, const AVFrame *a, const AVFrame *b, AVFrame *out, float progress,
  98. int slice_start, int slice_end, int jobnr);
  99. AVExpr *e;
  100. } XFadeContext;
  101. static const char *const var_names[] = { "X", "Y", "W", "H", "A", "B", "PLANE", "P", NULL };
  102. enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_A, VAR_B, VAR_PLANE, VAR_PROGRESS, VAR_VARS_NB };
  103. typedef struct ThreadData {
  104. const AVFrame *xf[2];
  105. AVFrame *out;
  106. float progress;
  107. } ThreadData;
  108. static int query_formats(AVFilterContext *ctx)
  109. {
  110. static const enum AVPixelFormat pix_fmts[] = {
  111. AV_PIX_FMT_YUVA444P,
  112. AV_PIX_FMT_YUVJ444P,
  113. AV_PIX_FMT_YUV444P,
  114. AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_GRAY8,
  115. AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_GBRP9,
  116. AV_PIX_FMT_YUV444P10,
  117. AV_PIX_FMT_YUVA444P10,
  118. AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GRAY10,
  119. AV_PIX_FMT_YUV444P12,
  120. AV_PIX_FMT_YUVA444P12,
  121. AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GRAY12,
  122. AV_PIX_FMT_YUV444P14, AV_PIX_FMT_GBRP14,
  123. AV_PIX_FMT_YUV444P16,
  124. AV_PIX_FMT_YUVA444P16,
  125. AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, AV_PIX_FMT_GRAY16,
  126. AV_PIX_FMT_NONE
  127. };
  128. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  129. if (!fmts_list)
  130. return AVERROR(ENOMEM);
  131. return ff_set_common_formats(ctx, fmts_list);
  132. }
  133. static av_cold void uninit(AVFilterContext *ctx)
  134. {
  135. XFadeContext *s = ctx->priv;
  136. av_expr_free(s->e);
  137. }
  138. #define OFFSET(x) offsetof(XFadeContext, x)
  139. #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
  140. static const AVOption xfade_options[] = {
  141. { "transition", "set cross fade transition", OFFSET(transition), AV_OPT_TYPE_INT, {.i64=FADE}, -1, NB_TRANSITIONS-1, FLAGS, "transition" },
  142. { "custom", "custom transition", 0, AV_OPT_TYPE_CONST, {.i64=CUSTOM}, 0, 0, FLAGS, "transition" },
  143. { "fade", "fade transition", 0, AV_OPT_TYPE_CONST, {.i64=FADE}, 0, 0, FLAGS, "transition" },
  144. { "wipeleft", "wipe left transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPELEFT}, 0, 0, FLAGS, "transition" },
  145. { "wiperight", "wipe right transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPERIGHT}, 0, 0, FLAGS, "transition" },
  146. { "wipeup", "wipe up transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPEUP}, 0, 0, FLAGS, "transition" },
  147. { "wipedown", "wipe down transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPEDOWN}, 0, 0, FLAGS, "transition" },
  148. { "slideleft", "slide left transition", 0, AV_OPT_TYPE_CONST, {.i64=SLIDELEFT}, 0, 0, FLAGS, "transition" },
  149. { "slideright", "slide right transition", 0, AV_OPT_TYPE_CONST, {.i64=SLIDERIGHT}, 0, 0, FLAGS, "transition" },
  150. { "slideup", "slide up transition", 0, AV_OPT_TYPE_CONST, {.i64=SLIDEUP}, 0, 0, FLAGS, "transition" },
  151. { "slidedown", "slide down transition", 0, AV_OPT_TYPE_CONST, {.i64=SLIDEDOWN}, 0, 0, FLAGS, "transition" },
  152. { "circlecrop", "circle crop transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLECROP}, 0, 0, FLAGS, "transition" },
  153. { "rectcrop", "rect crop transition", 0, AV_OPT_TYPE_CONST, {.i64=RECTCROP}, 0, 0, FLAGS, "transition" },
  154. { "distance", "distance transition", 0, AV_OPT_TYPE_CONST, {.i64=DISTANCE}, 0, 0, FLAGS, "transition" },
  155. { "fadeblack", "fadeblack transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEBLACK}, 0, 0, FLAGS, "transition" },
  156. { "fadewhite", "fadewhite transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEWHITE}, 0, 0, FLAGS, "transition" },
  157. { "radial", "radial transition", 0, AV_OPT_TYPE_CONST, {.i64=RADIAL}, 0, 0, FLAGS, "transition" },
  158. { "smoothleft", "smoothleft transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHLEFT}, 0, 0, FLAGS, "transition" },
  159. { "smoothright","smoothright transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHRIGHT},0, 0, FLAGS, "transition" },
  160. { "smoothup", "smoothup transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHUP}, 0, 0, FLAGS, "transition" },
  161. { "smoothdown", "smoothdown transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHDOWN}, 0, 0, FLAGS, "transition" },
  162. { "circleopen", "circleopen transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLEOPEN}, 0, 0, FLAGS, "transition" },
  163. { "circleclose","circleclose transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLECLOSE},0, 0, FLAGS, "transition" },
  164. { "vertopen", "vert open transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTOPEN}, 0, 0, FLAGS, "transition" },
  165. { "vertclose", "vert close transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTCLOSE}, 0, 0, FLAGS, "transition" },
  166. { "horzopen", "horz open transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZOPEN}, 0, 0, FLAGS, "transition" },
  167. { "horzclose", "horz close transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZCLOSE}, 0, 0, FLAGS, "transition" },
  168. { "dissolve", "dissolve transition", 0, AV_OPT_TYPE_CONST, {.i64=DISSOLVE}, 0, 0, FLAGS, "transition" },
  169. { "pixelize", "pixelize transition", 0, AV_OPT_TYPE_CONST, {.i64=PIXELIZE}, 0, 0, FLAGS, "transition" },
  170. { "diagtl", "diag tl transition", 0, AV_OPT_TYPE_CONST, {.i64=DIAGTL}, 0, 0, FLAGS, "transition" },
  171. { "diagtr", "diag tr transition", 0, AV_OPT_TYPE_CONST, {.i64=DIAGTR}, 0, 0, FLAGS, "transition" },
  172. { "diagbl", "diag bl transition", 0, AV_OPT_TYPE_CONST, {.i64=DIAGBL}, 0, 0, FLAGS, "transition" },
  173. { "diagbr", "diag br transition", 0, AV_OPT_TYPE_CONST, {.i64=DIAGBR}, 0, 0, FLAGS, "transition" },
  174. { "hlslice", "hl slice transition", 0, AV_OPT_TYPE_CONST, {.i64=HLSLICE}, 0, 0, FLAGS, "transition" },
  175. { "hrslice", "hr slice transition", 0, AV_OPT_TYPE_CONST, {.i64=HRSLICE}, 0, 0, FLAGS, "transition" },
  176. { "vuslice", "vu slice transition", 0, AV_OPT_TYPE_CONST, {.i64=VUSLICE}, 0, 0, FLAGS, "transition" },
  177. { "vdslice", "vd slice transition", 0, AV_OPT_TYPE_CONST, {.i64=VDSLICE}, 0, 0, FLAGS, "transition" },
  178. { "hblur", "hblur transition", 0, AV_OPT_TYPE_CONST, {.i64=HBLUR}, 0, 0, FLAGS, "transition" },
  179. { "fadegrays", "fadegrays transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEGRAYS}, 0, 0, FLAGS, "transition" },
  180. { "wipetl", "wipe tl transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPETL}, 0, 0, FLAGS, "transition" },
  181. { "wipetr", "wipe tr transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPETR}, 0, 0, FLAGS, "transition" },
  182. { "wipebl", "wipe bl transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPEBL}, 0, 0, FLAGS, "transition" },
  183. { "wipebr", "wipe br transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPEBR}, 0, 0, FLAGS, "transition" },
  184. { "squeezeh", "squeeze h transition", 0, AV_OPT_TYPE_CONST, {.i64=SQUEEZEH}, 0, 0, FLAGS, "transition" },
  185. { "squeezev", "squeeze v transition", 0, AV_OPT_TYPE_CONST, {.i64=SQUEEZEV}, 0, 0, FLAGS, "transition" },
  186. { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
  187. { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
  188. { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
  189. { NULL }
  190. };
  191. AVFILTER_DEFINE_CLASS(xfade);
  192. #define CUSTOM_TRANSITION(name, type, div) \
  193. static void custom##name##_transition(AVFilterContext *ctx, \
  194. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  195. float progress, \
  196. int slice_start, int slice_end, int jobnr) \
  197. { \
  198. XFadeContext *s = ctx->priv; \
  199. const int height = slice_end - slice_start; \
  200. \
  201. double values[VAR_VARS_NB]; \
  202. values[VAR_W] = out->width; \
  203. values[VAR_H] = out->height; \
  204. values[VAR_PROGRESS] = progress; \
  205. \
  206. for (int p = 0; p < s->nb_planes; p++) { \
  207. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  208. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  209. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  210. \
  211. values[VAR_PLANE] = p; \
  212. \
  213. for (int y = 0; y < height; y++) { \
  214. values[VAR_Y] = slice_start + y; \
  215. for (int x = 0; x < out->width; x++) { \
  216. values[VAR_X] = x; \
  217. values[VAR_A] = xf0[x]; \
  218. values[VAR_B] = xf1[x]; \
  219. dst[x] = av_expr_eval(s->e, values, s); \
  220. } \
  221. \
  222. dst += out->linesize[p] / div; \
  223. xf0 += a->linesize[p] / div; \
  224. xf1 += b->linesize[p] / div; \
  225. } \
  226. } \
  227. }
  228. CUSTOM_TRANSITION(8, uint8_t, 1)
  229. CUSTOM_TRANSITION(16, uint16_t, 2)
  230. static inline float mix(float a, float b, float mix)
  231. {
  232. return a * mix + b * (1.f - mix);
  233. }
  234. static inline float fract(float a)
  235. {
  236. return a - floorf(a);
  237. }
  238. static inline float smoothstep(float edge0, float edge1, float x)
  239. {
  240. float t;
  241. t = av_clipf((x - edge0) / (edge1 - edge0), 0.f, 1.f);
  242. return t * t * (3.f - 2.f * t);
  243. }
  244. #define FADE_TRANSITION(name, type, div) \
  245. static void fade##name##_transition(AVFilterContext *ctx, \
  246. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  247. float progress, \
  248. int slice_start, int slice_end, int jobnr) \
  249. { \
  250. XFadeContext *s = ctx->priv; \
  251. const int height = slice_end - slice_start; \
  252. \
  253. for (int p = 0; p < s->nb_planes; p++) { \
  254. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  255. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  256. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  257. \
  258. for (int y = 0; y < height; y++) { \
  259. for (int x = 0; x < out->width; x++) { \
  260. dst[x] = mix(xf0[x], xf1[x], progress); \
  261. } \
  262. \
  263. dst += out->linesize[p] / div; \
  264. xf0 += a->linesize[p] / div; \
  265. xf1 += b->linesize[p] / div; \
  266. } \
  267. } \
  268. }
  269. FADE_TRANSITION(8, uint8_t, 1)
  270. FADE_TRANSITION(16, uint16_t, 2)
  271. #define WIPELEFT_TRANSITION(name, type, div) \
  272. static void wipeleft##name##_transition(AVFilterContext *ctx, \
  273. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  274. float progress, \
  275. int slice_start, int slice_end, int jobnr) \
  276. { \
  277. XFadeContext *s = ctx->priv; \
  278. const int height = slice_end - slice_start; \
  279. const int z = out->width * progress; \
  280. \
  281. for (int p = 0; p < s->nb_planes; p++) { \
  282. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  283. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  284. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  285. \
  286. for (int y = 0; y < height; y++) { \
  287. for (int x = 0; x < out->width; x++) { \
  288. dst[x] = x > z ? xf1[x] : xf0[x]; \
  289. } \
  290. \
  291. dst += out->linesize[p] / div; \
  292. xf0 += a->linesize[p] / div; \
  293. xf1 += b->linesize[p] / div; \
  294. } \
  295. } \
  296. }
  297. WIPELEFT_TRANSITION(8, uint8_t, 1)
  298. WIPELEFT_TRANSITION(16, uint16_t, 2)
  299. #define WIPERIGHT_TRANSITION(name, type, div) \
  300. static void wiperight##name##_transition(AVFilterContext *ctx, \
  301. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  302. float progress, \
  303. int slice_start, int slice_end, int jobnr) \
  304. { \
  305. XFadeContext *s = ctx->priv; \
  306. const int height = slice_end - slice_start; \
  307. const int z = out->width * (1.f - progress); \
  308. \
  309. for (int p = 0; p < s->nb_planes; p++) { \
  310. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  311. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  312. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  313. \
  314. for (int y = 0; y < height; y++) { \
  315. for (int x = 0; x < out->width; x++) { \
  316. dst[x] = x > z ? xf0[x] : xf1[x]; \
  317. } \
  318. \
  319. dst += out->linesize[p] / div; \
  320. xf0 += a->linesize[p] / div; \
  321. xf1 += b->linesize[p] / div; \
  322. } \
  323. } \
  324. }
  325. WIPERIGHT_TRANSITION(8, uint8_t, 1)
  326. WIPERIGHT_TRANSITION(16, uint16_t, 2)
  327. #define WIPEUP_TRANSITION(name, type, div) \
  328. static void wipeup##name##_transition(AVFilterContext *ctx, \
  329. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  330. float progress, \
  331. int slice_start, int slice_end, int jobnr) \
  332. { \
  333. XFadeContext *s = ctx->priv; \
  334. const int height = slice_end - slice_start; \
  335. const int z = out->height * progress; \
  336. \
  337. for (int p = 0; p < s->nb_planes; p++) { \
  338. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  339. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  340. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  341. \
  342. for (int y = 0; y < height; y++) { \
  343. for (int x = 0; x < out->width; x++) { \
  344. dst[x] = slice_start + y > z ? xf1[x] : xf0[x]; \
  345. } \
  346. \
  347. dst += out->linesize[p] / div; \
  348. xf0 += a->linesize[p] / div; \
  349. xf1 += b->linesize[p] / div; \
  350. } \
  351. } \
  352. }
  353. WIPEUP_TRANSITION(8, uint8_t, 1)
  354. WIPEUP_TRANSITION(16, uint16_t, 2)
  355. #define WIPEDOWN_TRANSITION(name, type, div) \
  356. static void wipedown##name##_transition(AVFilterContext *ctx, \
  357. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  358. float progress, \
  359. int slice_start, int slice_end, int jobnr) \
  360. { \
  361. XFadeContext *s = ctx->priv; \
  362. const int height = slice_end - slice_start; \
  363. const int z = out->height * (1.f - progress); \
  364. \
  365. for (int p = 0; p < s->nb_planes; p++) { \
  366. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  367. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  368. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  369. \
  370. for (int y = 0; y < height; y++) { \
  371. for (int x = 0; x < out->width; x++) { \
  372. dst[x] = slice_start + y > z ? xf0[x] : xf1[x]; \
  373. } \
  374. \
  375. dst += out->linesize[p] / div; \
  376. xf0 += a->linesize[p] / div; \
  377. xf1 += b->linesize[p] / div; \
  378. } \
  379. } \
  380. }
  381. WIPEDOWN_TRANSITION(8, uint8_t, 1)
  382. WIPEDOWN_TRANSITION(16, uint16_t, 2)
  383. #define SLIDELEFT_TRANSITION(name, type, div) \
  384. static void slideleft##name##_transition(AVFilterContext *ctx, \
  385. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  386. float progress, \
  387. int slice_start, int slice_end, int jobnr) \
  388. { \
  389. XFadeContext *s = ctx->priv; \
  390. const int height = slice_end - slice_start; \
  391. const int width = out->width; \
  392. const int z = -progress * width; \
  393. \
  394. for (int p = 0; p < s->nb_planes; p++) { \
  395. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  396. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  397. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  398. \
  399. for (int y = 0; y < height; y++) { \
  400. for (int x = 0; x < width; x++) { \
  401. const int zx = z + x; \
  402. const int zz = zx % width + width * (zx < 0); \
  403. dst[x] = (zx > 0) && (zx < width) ? xf1[zz] : xf0[zz]; \
  404. } \
  405. \
  406. dst += out->linesize[p] / div; \
  407. xf0 += a->linesize[p] / div; \
  408. xf1 += b->linesize[p] / div; \
  409. } \
  410. } \
  411. }
  412. SLIDELEFT_TRANSITION(8, uint8_t, 1)
  413. SLIDELEFT_TRANSITION(16, uint16_t, 2)
  414. #define SLIDERIGHT_TRANSITION(name, type, div) \
  415. static void slideright##name##_transition(AVFilterContext *ctx, \
  416. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  417. float progress, \
  418. int slice_start, int slice_end, int jobnr) \
  419. { \
  420. XFadeContext *s = ctx->priv; \
  421. const int height = slice_end - slice_start; \
  422. const int width = out->width; \
  423. const int z = progress * width; \
  424. \
  425. for (int p = 0; p < s->nb_planes; p++) { \
  426. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  427. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  428. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  429. \
  430. for (int y = 0; y < height; y++) { \
  431. for (int x = 0; x < out->width; x++) { \
  432. const int zx = z + x; \
  433. const int zz = zx % width + width * (zx < 0); \
  434. dst[x] = (zx > 0) && (zx < width) ? xf1[zz] : xf0[zz]; \
  435. } \
  436. \
  437. dst += out->linesize[p] / div; \
  438. xf0 += a->linesize[p] / div; \
  439. xf1 += b->linesize[p] / div; \
  440. } \
  441. } \
  442. }
  443. SLIDERIGHT_TRANSITION(8, uint8_t, 1)
  444. SLIDERIGHT_TRANSITION(16, uint16_t, 2)
  445. #define SLIDEUP_TRANSITION(name, type, div) \
  446. static void slideup##name##_transition(AVFilterContext *ctx, \
  447. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  448. float progress, \
  449. int slice_start, int slice_end, int jobnr) \
  450. { \
  451. XFadeContext *s = ctx->priv; \
  452. const int height = out->height; \
  453. const int z = -progress * height; \
  454. \
  455. for (int p = 0; p < s->nb_planes; p++) { \
  456. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  457. \
  458. for (int y = slice_start; y < slice_end; y++) { \
  459. const int zy = z + y; \
  460. const int zz = zy % height + height * (zy < 0); \
  461. const type *xf0 = (const type *)(a->data[p] + zz * a->linesize[p]); \
  462. const type *xf1 = (const type *)(b->data[p] + zz * b->linesize[p]); \
  463. \
  464. for (int x = 0; x < out->width; x++) { \
  465. dst[x] = (zy > 0) && (zy < height) ? xf1[x] : xf0[x]; \
  466. } \
  467. \
  468. dst += out->linesize[p] / div; \
  469. } \
  470. } \
  471. }
  472. SLIDEUP_TRANSITION(8, uint8_t, 1)
  473. SLIDEUP_TRANSITION(16, uint16_t, 2)
  474. #define SLIDEDOWN_TRANSITION(name, type, div) \
  475. static void slidedown##name##_transition(AVFilterContext *ctx, \
  476. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  477. float progress, \
  478. int slice_start, int slice_end, int jobnr) \
  479. { \
  480. XFadeContext *s = ctx->priv; \
  481. const int height = out->height; \
  482. const int z = progress * height; \
  483. \
  484. for (int p = 0; p < s->nb_planes; p++) { \
  485. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  486. \
  487. for (int y = slice_start; y < slice_end; y++) { \
  488. const int zy = z + y; \
  489. const int zz = zy % height + height * (zy < 0); \
  490. const type *xf0 = (const type *)(a->data[p] + zz * a->linesize[p]); \
  491. const type *xf1 = (const type *)(b->data[p] + zz * b->linesize[p]); \
  492. \
  493. for (int x = 0; x < out->width; x++) { \
  494. dst[x] = (zy > 0) && (zy < height) ? xf1[x] : xf0[x]; \
  495. } \
  496. \
  497. dst += out->linesize[p] / div; \
  498. } \
  499. } \
  500. }
  501. SLIDEDOWN_TRANSITION(8, uint8_t, 1)
  502. SLIDEDOWN_TRANSITION(16, uint16_t, 2)
  503. #define CIRCLECROP_TRANSITION(name, type, div) \
  504. static void circlecrop##name##_transition(AVFilterContext *ctx, \
  505. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  506. float progress, \
  507. int slice_start, int slice_end, int jobnr) \
  508. { \
  509. XFadeContext *s = ctx->priv; \
  510. const int width = out->width; \
  511. const int height = out->height; \
  512. float z = powf(2.f * fabsf(progress - 0.5f), 3.f) * hypotf(width/2, height/2); \
  513. \
  514. for (int p = 0; p < s->nb_planes; p++) { \
  515. const int bg = s->black[p]; \
  516. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  517. \
  518. for (int y = slice_start; y < slice_end; y++) { \
  519. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  520. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  521. \
  522. for (int x = 0; x < width; x++) { \
  523. float dist = hypotf(x - width / 2, y - height / 2); \
  524. int val = progress < 0.5f ? xf1[x] : xf0[x]; \
  525. dst[x] = (z < dist) ? bg : val; \
  526. } \
  527. \
  528. dst += out->linesize[p] / div; \
  529. } \
  530. } \
  531. }
  532. CIRCLECROP_TRANSITION(8, uint8_t, 1)
  533. CIRCLECROP_TRANSITION(16, uint16_t, 2)
  534. #define RECTCROP_TRANSITION(name, type, div) \
  535. static void rectcrop##name##_transition(AVFilterContext *ctx, \
  536. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  537. float progress, \
  538. int slice_start, int slice_end, int jobnr) \
  539. { \
  540. XFadeContext *s = ctx->priv; \
  541. const int width = out->width; \
  542. const int height = out->height; \
  543. int zh = fabsf(progress - 0.5f) * height; \
  544. int zw = fabsf(progress - 0.5f) * width; \
  545. \
  546. for (int p = 0; p < s->nb_planes; p++) { \
  547. const int bg = s->black[p]; \
  548. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  549. \
  550. for (int y = slice_start; y < slice_end; y++) { \
  551. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  552. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  553. \
  554. for (int x = 0; x < width; x++) { \
  555. int dist = FFABS(x - width / 2) < zw && \
  556. FFABS(y - height / 2) < zh; \
  557. int val = progress < 0.5f ? xf1[x] : xf0[x]; \
  558. dst[x] = !dist ? bg : val; \
  559. } \
  560. \
  561. dst += out->linesize[p] / div; \
  562. } \
  563. } \
  564. }
  565. RECTCROP_TRANSITION(8, uint8_t, 1)
  566. RECTCROP_TRANSITION(16, uint16_t, 2)
  567. #define DISTANCE_TRANSITION(name, type, div) \
  568. static void distance##name##_transition(AVFilterContext *ctx, \
  569. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  570. float progress, \
  571. int slice_start, int slice_end, int jobnr) \
  572. { \
  573. XFadeContext *s = ctx->priv; \
  574. const int width = out->width; \
  575. const float max = s->max_value; \
  576. \
  577. for (int y = slice_start; y < slice_end; y++) { \
  578. for (int x = 0; x < width; x++) { \
  579. float dist = 0.f; \
  580. for (int p = 0; p < s->nb_planes; p++) { \
  581. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  582. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  583. \
  584. dist += (xf0[x] / max - xf1[x] / max) * \
  585. (xf0[x] / max - xf1[x] / max); \
  586. } \
  587. \
  588. dist = sqrtf(dist) <= progress; \
  589. for (int p = 0; p < s->nb_planes; p++) { \
  590. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  591. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  592. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  593. dst[x] = mix(mix(xf0[x], xf1[x], dist), xf1[x], progress); \
  594. } \
  595. } \
  596. } \
  597. }
  598. DISTANCE_TRANSITION(8, uint8_t, 1)
  599. DISTANCE_TRANSITION(16, uint16_t, 2)
  600. #define FADEBLACK_TRANSITION(name, type, div) \
  601. static void fadeblack##name##_transition(AVFilterContext *ctx, \
  602. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  603. float progress, \
  604. int slice_start, int slice_end, int jobnr) \
  605. { \
  606. XFadeContext *s = ctx->priv; \
  607. const int height = slice_end - slice_start; \
  608. const float phase = 0.2f; \
  609. \
  610. for (int p = 0; p < s->nb_planes; p++) { \
  611. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  612. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  613. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  614. const int bg = s->black[p]; \
  615. \
  616. for (int y = 0; y < height; y++) { \
  617. for (int x = 0; x < out->width; x++) { \
  618. dst[x] = mix(mix(xf0[x], bg, smoothstep(1.f-phase, 1.f, progress)), \
  619. mix(bg, xf1[x], smoothstep(phase, 1.f, progress)), \
  620. progress); \
  621. } \
  622. \
  623. dst += out->linesize[p] / div; \
  624. xf0 += a->linesize[p] / div; \
  625. xf1 += b->linesize[p] / div; \
  626. } \
  627. } \
  628. }
  629. FADEBLACK_TRANSITION(8, uint8_t, 1)
  630. FADEBLACK_TRANSITION(16, uint16_t, 2)
  631. #define FADEWHITE_TRANSITION(name, type, div) \
  632. static void fadewhite##name##_transition(AVFilterContext *ctx, \
  633. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  634. float progress, \
  635. int slice_start, int slice_end, int jobnr) \
  636. { \
  637. XFadeContext *s = ctx->priv; \
  638. const int height = slice_end - slice_start; \
  639. const float phase = 0.2f; \
  640. \
  641. for (int p = 0; p < s->nb_planes; p++) { \
  642. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  643. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  644. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  645. const int bg = s->white[p]; \
  646. \
  647. for (int y = 0; y < height; y++) { \
  648. for (int x = 0; x < out->width; x++) { \
  649. dst[x] = mix(mix(xf0[x], bg, smoothstep(1.f-phase, 1.f, progress)), \
  650. mix(bg, xf1[x], smoothstep(phase, 1.f, progress)), \
  651. progress); \
  652. } \
  653. \
  654. dst += out->linesize[p] / div; \
  655. xf0 += a->linesize[p] / div; \
  656. xf1 += b->linesize[p] / div; \
  657. } \
  658. } \
  659. }
  660. FADEWHITE_TRANSITION(8, uint8_t, 1)
  661. FADEWHITE_TRANSITION(16, uint16_t, 2)
  662. #define RADIAL_TRANSITION(name, type, div) \
  663. static void radial##name##_transition(AVFilterContext *ctx, \
  664. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  665. float progress, \
  666. int slice_start, int slice_end, int jobnr) \
  667. { \
  668. XFadeContext *s = ctx->priv; \
  669. const int width = out->width; \
  670. const int height = out->height; \
  671. \
  672. for (int y = slice_start; y < slice_end; y++) { \
  673. for (int x = 0; x < width; x++) { \
  674. const float smooth = atan2f(x - width / 2, y - height / 2) - \
  675. (progress - 0.5f) * (M_PI * 2.5f); \
  676. for (int p = 0; p < s->nb_planes; p++) { \
  677. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  678. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  679. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  680. \
  681. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  682. } \
  683. } \
  684. } \
  685. }
  686. RADIAL_TRANSITION(8, uint8_t, 1)
  687. RADIAL_TRANSITION(16, uint16_t, 2)
  688. #define SMOOTHLEFT_TRANSITION(name, type, div) \
  689. static void smoothleft##name##_transition(AVFilterContext *ctx, \
  690. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  691. float progress, \
  692. int slice_start, int slice_end, int jobnr) \
  693. { \
  694. XFadeContext *s = ctx->priv; \
  695. const int width = out->width; \
  696. const float w = width; \
  697. \
  698. for (int y = slice_start; y < slice_end; y++) { \
  699. for (int x = 0; x < width; x++) { \
  700. const float smooth = 1.f + x / w - progress * 2.f; \
  701. \
  702. for (int p = 0; p < s->nb_planes; p++) { \
  703. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  704. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  705. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  706. \
  707. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  708. } \
  709. } \
  710. } \
  711. }
  712. SMOOTHLEFT_TRANSITION(8, uint8_t, 1)
  713. SMOOTHLEFT_TRANSITION(16, uint16_t, 2)
  714. #define SMOOTHRIGHT_TRANSITION(name, type, div) \
  715. static void smoothright##name##_transition(AVFilterContext *ctx, \
  716. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  717. float progress, \
  718. int slice_start, int slice_end, int jobnr) \
  719. { \
  720. XFadeContext *s = ctx->priv; \
  721. const int width = out->width; \
  722. const float w = width; \
  723. \
  724. for (int y = slice_start; y < slice_end; y++) { \
  725. for (int x = 0; x < width; x++) { \
  726. const float smooth = 1.f + (w - 1 - x) / w - progress * 2.f; \
  727. \
  728. for (int p = 0; p < s->nb_planes; p++) { \
  729. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  730. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  731. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  732. \
  733. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  734. } \
  735. } \
  736. } \
  737. }
  738. SMOOTHRIGHT_TRANSITION(8, uint8_t, 1)
  739. SMOOTHRIGHT_TRANSITION(16, uint16_t, 2)
  740. #define SMOOTHUP_TRANSITION(name, type, div) \
  741. static void smoothup##name##_transition(AVFilterContext *ctx, \
  742. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  743. float progress, \
  744. int slice_start, int slice_end, int jobnr) \
  745. { \
  746. XFadeContext *s = ctx->priv; \
  747. const int width = out->width; \
  748. const float h = out->height; \
  749. \
  750. for (int y = slice_start; y < slice_end; y++) { \
  751. const float smooth = 1.f + y / h - progress * 2.f; \
  752. for (int x = 0; x < width; x++) { \
  753. for (int p = 0; p < s->nb_planes; p++) { \
  754. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  755. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  756. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  757. \
  758. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  759. } \
  760. } \
  761. } \
  762. }
  763. SMOOTHUP_TRANSITION(8, uint8_t, 1)
  764. SMOOTHUP_TRANSITION(16, uint16_t, 2)
  765. #define SMOOTHDOWN_TRANSITION(name, type, div) \
  766. static void smoothdown##name##_transition(AVFilterContext *ctx, \
  767. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  768. float progress, \
  769. int slice_start, int slice_end, int jobnr) \
  770. { \
  771. XFadeContext *s = ctx->priv; \
  772. const int width = out->width; \
  773. const float h = out->height; \
  774. \
  775. for (int y = slice_start; y < slice_end; y++) { \
  776. const float smooth = 1.f + (h - 1 - y) / h - progress * 2.f; \
  777. for (int x = 0; x < width; x++) { \
  778. for (int p = 0; p < s->nb_planes; p++) { \
  779. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  780. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  781. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  782. \
  783. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  784. } \
  785. } \
  786. } \
  787. }
  788. SMOOTHDOWN_TRANSITION(8, uint8_t, 1)
  789. SMOOTHDOWN_TRANSITION(16, uint16_t, 2)
  790. #define CIRCLEOPEN_TRANSITION(name, type, div) \
  791. static void circleopen##name##_transition(AVFilterContext *ctx, \
  792. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  793. float progress, \
  794. int slice_start, int slice_end, int jobnr) \
  795. { \
  796. XFadeContext *s = ctx->priv; \
  797. const int width = out->width; \
  798. const int height = out->height; \
  799. const float z = hypotf(width / 2, height / 2); \
  800. const float p = (progress - 0.5f) * 3.f; \
  801. \
  802. for (int y = slice_start; y < slice_end; y++) { \
  803. for (int x = 0; x < width; x++) { \
  804. const float smooth = hypotf(x - width / 2, y - height / 2) / z + p; \
  805. for (int p = 0; p < s->nb_planes; p++) { \
  806. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  807. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  808. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  809. \
  810. dst[x] = mix(xf0[x], xf1[x], smoothstep(0.f, 1.f, smooth)); \
  811. } \
  812. } \
  813. } \
  814. }
  815. CIRCLEOPEN_TRANSITION(8, uint8_t, 1)
  816. CIRCLEOPEN_TRANSITION(16, uint16_t, 2)
  817. #define CIRCLECLOSE_TRANSITION(name, type, div) \
  818. static void circleclose##name##_transition(AVFilterContext *ctx, \
  819. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  820. float progress, \
  821. int slice_start, int slice_end, int jobnr) \
  822. { \
  823. XFadeContext *s = ctx->priv; \
  824. const int width = out->width; \
  825. const int height = out->height; \
  826. const float z = hypotf(width / 2, height / 2); \
  827. const float p = (1.f - progress - 0.5f) * 3.f; \
  828. \
  829. for (int y = slice_start; y < slice_end; y++) { \
  830. for (int x = 0; x < width; x++) { \
  831. const float smooth = hypotf(x - width / 2, y - height / 2) / z + p; \
  832. for (int p = 0; p < s->nb_planes; p++) { \
  833. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  834. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  835. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  836. \
  837. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  838. } \
  839. } \
  840. } \
  841. }
  842. CIRCLECLOSE_TRANSITION(8, uint8_t, 1)
  843. CIRCLECLOSE_TRANSITION(16, uint16_t, 2)
  844. #define VERTOPEN_TRANSITION(name, type, div) \
  845. static void vertopen##name##_transition(AVFilterContext *ctx, \
  846. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  847. float progress, \
  848. int slice_start, int slice_end, int jobnr) \
  849. { \
  850. XFadeContext *s = ctx->priv; \
  851. const int width = out->width; \
  852. const float w2 = out->width / 2; \
  853. \
  854. for (int y = slice_start; y < slice_end; y++) { \
  855. for (int x = 0; x < width; x++) { \
  856. const float smooth = 2.f - fabsf((x - w2) / w2) - progress * 2.f; \
  857. for (int p = 0; p < s->nb_planes; p++) { \
  858. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  859. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  860. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  861. \
  862. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  863. } \
  864. } \
  865. } \
  866. }
  867. VERTOPEN_TRANSITION(8, uint8_t, 1)
  868. VERTOPEN_TRANSITION(16, uint16_t, 2)
  869. #define VERTCLOSE_TRANSITION(name, type, div) \
  870. static void vertclose##name##_transition(AVFilterContext *ctx, \
  871. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  872. float progress, \
  873. int slice_start, int slice_end, int jobnr) \
  874. { \
  875. XFadeContext *s = ctx->priv; \
  876. const int width = out->width; \
  877. const float w2 = out->width / 2; \
  878. \
  879. for (int y = slice_start; y < slice_end; y++) { \
  880. for (int x = 0; x < width; x++) { \
  881. const float smooth = 1.f + fabsf((x - w2) / w2) - progress * 2.f; \
  882. for (int p = 0; p < s->nb_planes; p++) { \
  883. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  884. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  885. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  886. \
  887. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  888. } \
  889. } \
  890. } \
  891. }
  892. VERTCLOSE_TRANSITION(8, uint8_t, 1)
  893. VERTCLOSE_TRANSITION(16, uint16_t, 2)
  894. #define HORZOPEN_TRANSITION(name, type, div) \
  895. static void horzopen##name##_transition(AVFilterContext *ctx, \
  896. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  897. float progress, \
  898. int slice_start, int slice_end, int jobnr) \
  899. { \
  900. XFadeContext *s = ctx->priv; \
  901. const int width = out->width; \
  902. const float h2 = out->height / 2; \
  903. \
  904. for (int y = slice_start; y < slice_end; y++) { \
  905. const float smooth = 2.f - fabsf((y - h2) / h2) - progress * 2.f; \
  906. for (int x = 0; x < width; x++) { \
  907. for (int p = 0; p < s->nb_planes; p++) { \
  908. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  909. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  910. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  911. \
  912. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  913. } \
  914. } \
  915. } \
  916. }
  917. HORZOPEN_TRANSITION(8, uint8_t, 1)
  918. HORZOPEN_TRANSITION(16, uint16_t, 2)
  919. #define HORZCLOSE_TRANSITION(name, type, div) \
  920. static void horzclose##name##_transition(AVFilterContext *ctx, \
  921. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  922. float progress, \
  923. int slice_start, int slice_end, int jobnr) \
  924. { \
  925. XFadeContext *s = ctx->priv; \
  926. const int width = out->width; \
  927. const float h2 = out->height / 2; \
  928. \
  929. for (int y = slice_start; y < slice_end; y++) { \
  930. const float smooth = 1.f + fabsf((y - h2) / h2) - progress * 2.f; \
  931. for (int x = 0; x < width; x++) { \
  932. for (int p = 0; p < s->nb_planes; p++) { \
  933. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  934. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  935. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  936. \
  937. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  938. } \
  939. } \
  940. } \
  941. }
  942. HORZCLOSE_TRANSITION(8, uint8_t, 1)
  943. HORZCLOSE_TRANSITION(16, uint16_t, 2)
  944. static float frand(int x, int y)
  945. {
  946. const float r = sinf(x * 12.9898f + y * 78.233f) * 43758.545f;
  947. return r - floorf(r);
  948. }
  949. #define DISSOLVE_TRANSITION(name, type, div) \
  950. static void dissolve##name##_transition(AVFilterContext *ctx, \
  951. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  952. float progress, \
  953. int slice_start, int slice_end, int jobnr) \
  954. { \
  955. XFadeContext *s = ctx->priv; \
  956. const int width = out->width; \
  957. \
  958. for (int y = slice_start; y < slice_end; y++) { \
  959. for (int x = 0; x < width; x++) { \
  960. const float smooth = frand(x, y) * 2.f + progress * 2.f - 1.5f; \
  961. for (int p = 0; p < s->nb_planes; p++) { \
  962. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  963. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  964. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  965. \
  966. dst[x] = smooth >= 0.5f ? xf0[x] : xf1[x]; \
  967. } \
  968. } \
  969. } \
  970. }
  971. DISSOLVE_TRANSITION(8, uint8_t, 1)
  972. DISSOLVE_TRANSITION(16, uint16_t, 2)
  973. #define PIXELIZE_TRANSITION(name, type, div) \
  974. static void pixelize##name##_transition(AVFilterContext *ctx, \
  975. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  976. float progress, \
  977. int slice_start, int slice_end, int jobnr) \
  978. { \
  979. XFadeContext *s = ctx->priv; \
  980. const int w = out->width; \
  981. const int h = out->height; \
  982. const float d = fminf(progress, 1.f - progress); \
  983. const float dist = ceilf(d * 50.f) / 50.f; \
  984. const float sqx = 2.f * dist * FFMIN(w, h) / 20.f; \
  985. const float sqy = 2.f * dist * FFMIN(w, h) / 20.f; \
  986. \
  987. for (int y = slice_start; y < slice_end; y++) { \
  988. for (int x = 0; x < w; x++) { \
  989. int sx = dist > 0.f ? FFMIN((floorf(x / sqx) + .5f) * sqx, w - 1) : x; \
  990. int sy = dist > 0.f ? FFMIN((floorf(y / sqy) + .5f) * sqy, h - 1) : y; \
  991. for (int p = 0; p < s->nb_planes; p++) { \
  992. const type *xf0 = (const type *)(a->data[p] + sy * a->linesize[p]); \
  993. const type *xf1 = (const type *)(b->data[p] + sy * b->linesize[p]); \
  994. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  995. \
  996. dst[x] = mix(xf0[sx], xf1[sx], progress); \
  997. } \
  998. } \
  999. } \
  1000. }
  1001. PIXELIZE_TRANSITION(8, uint8_t, 1)
  1002. PIXELIZE_TRANSITION(16, uint16_t, 2)
  1003. #define DIAGTL_TRANSITION(name, type, div) \
  1004. static void diagtl##name##_transition(AVFilterContext *ctx, \
  1005. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1006. float progress, \
  1007. int slice_start, int slice_end, int jobnr) \
  1008. { \
  1009. XFadeContext *s = ctx->priv; \
  1010. const int width = out->width; \
  1011. const float w = width; \
  1012. const float h = out->height; \
  1013. \
  1014. for (int y = slice_start; y < slice_end; y++) { \
  1015. for (int x = 0; x < width; x++) { \
  1016. const float smooth = 1.f + x / w * y / h - progress * 2.f; \
  1017. \
  1018. for (int p = 0; p < s->nb_planes; p++) { \
  1019. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1020. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1021. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1022. \
  1023. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  1024. } \
  1025. } \
  1026. } \
  1027. }
  1028. DIAGTL_TRANSITION(8, uint8_t, 1)
  1029. DIAGTL_TRANSITION(16, uint16_t, 2)
  1030. #define DIAGTR_TRANSITION(name, type, div) \
  1031. static void diagtr##name##_transition(AVFilterContext *ctx, \
  1032. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1033. float progress, \
  1034. int slice_start, int slice_end, int jobnr) \
  1035. { \
  1036. XFadeContext *s = ctx->priv; \
  1037. const int width = out->width; \
  1038. const float w = width; \
  1039. const float h = out->height; \
  1040. \
  1041. for (int y = slice_start; y < slice_end; y++) { \
  1042. for (int x = 0; x < width; x++) { \
  1043. const float smooth = 1.f + (w - 1 - x) / w * y / h - progress * 2.f; \
  1044. \
  1045. for (int p = 0; p < s->nb_planes; p++) { \
  1046. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1047. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1048. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1049. \
  1050. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  1051. } \
  1052. } \
  1053. } \
  1054. }
  1055. DIAGTR_TRANSITION(8, uint8_t, 1)
  1056. DIAGTR_TRANSITION(16, uint16_t, 2)
  1057. #define DIAGBL_TRANSITION(name, type, div) \
  1058. static void diagbl##name##_transition(AVFilterContext *ctx, \
  1059. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1060. float progress, \
  1061. int slice_start, int slice_end, int jobnr) \
  1062. { \
  1063. XFadeContext *s = ctx->priv; \
  1064. const int width = out->width; \
  1065. const float w = width; \
  1066. const float h = out->height; \
  1067. \
  1068. for (int y = slice_start; y < slice_end; y++) { \
  1069. for (int x = 0; x < width; x++) { \
  1070. const float smooth = 1.f + x / w * (h - 1 - y) / h - progress * 2.f; \
  1071. \
  1072. for (int p = 0; p < s->nb_planes; p++) { \
  1073. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1074. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1075. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1076. \
  1077. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  1078. } \
  1079. } \
  1080. } \
  1081. }
  1082. DIAGBL_TRANSITION(8, uint8_t, 1)
  1083. DIAGBL_TRANSITION(16, uint16_t, 2)
  1084. #define DIAGBR_TRANSITION(name, type, div) \
  1085. static void diagbr##name##_transition(AVFilterContext *ctx, \
  1086. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1087. float progress, \
  1088. int slice_start, int slice_end, int jobnr) \
  1089. { \
  1090. XFadeContext *s = ctx->priv; \
  1091. const int width = out->width; \
  1092. const float w = width; \
  1093. const float h = out->height; \
  1094. \
  1095. for (int y = slice_start; y < slice_end; y++) { \
  1096. for (int x = 0; x < width; x++) { \
  1097. const float smooth = 1.f + (w - 1 - x) / w * (h - 1 - y) / h - \
  1098. progress * 2.f; \
  1099. \
  1100. for (int p = 0; p < s->nb_planes; p++) { \
  1101. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1102. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1103. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1104. \
  1105. dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
  1106. } \
  1107. } \
  1108. } \
  1109. }
  1110. DIAGBR_TRANSITION(8, uint8_t, 1)
  1111. DIAGBR_TRANSITION(16, uint16_t, 2)
  1112. #define HLSLICE_TRANSITION(name, type, div) \
  1113. static void hlslice##name##_transition(AVFilterContext *ctx, \
  1114. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1115. float progress, \
  1116. int slice_start, int slice_end, int jobnr) \
  1117. { \
  1118. XFadeContext *s = ctx->priv; \
  1119. const int width = out->width; \
  1120. const float w = width; \
  1121. \
  1122. for (int y = slice_start; y < slice_end; y++) { \
  1123. for (int x = 0; x < width; x++) { \
  1124. const float smooth = smoothstep(-0.5f, 0.f, x / w - progress * 1.5f); \
  1125. const float ss = smooth <= fract(10.f * x / w) ? 0.f : 1.f; \
  1126. \
  1127. for (int p = 0; p < s->nb_planes; p++) { \
  1128. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1129. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1130. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1131. \
  1132. dst[x] = mix(xf1[x], xf0[x], ss); \
  1133. } \
  1134. } \
  1135. } \
  1136. }
  1137. HLSLICE_TRANSITION(8, uint8_t, 1)
  1138. HLSLICE_TRANSITION(16, uint16_t, 2)
  1139. #define HRSLICE_TRANSITION(name, type, div) \
  1140. static void hrslice##name##_transition(AVFilterContext *ctx, \
  1141. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1142. float progress, \
  1143. int slice_start, int slice_end, int jobnr) \
  1144. { \
  1145. XFadeContext *s = ctx->priv; \
  1146. const int width = out->width; \
  1147. const float w = width; \
  1148. \
  1149. for (int y = slice_start; y < slice_end; y++) { \
  1150. for (int x = 0; x < width; x++) { \
  1151. const float xx = (w - 1 - x) / w; \
  1152. const float smooth = smoothstep(-0.5f, 0.f, xx - progress * 1.5f); \
  1153. const float ss = smooth <= fract(10.f * xx) ? 0.f : 1.f; \
  1154. \
  1155. for (int p = 0; p < s->nb_planes; p++) { \
  1156. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1157. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1158. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1159. \
  1160. dst[x] = mix(xf1[x], xf0[x], ss); \
  1161. } \
  1162. } \
  1163. } \
  1164. }
  1165. HRSLICE_TRANSITION(8, uint8_t, 1)
  1166. HRSLICE_TRANSITION(16, uint16_t, 2)
  1167. #define VUSLICE_TRANSITION(name, type, div) \
  1168. static void vuslice##name##_transition(AVFilterContext *ctx, \
  1169. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1170. float progress, \
  1171. int slice_start, int slice_end, int jobnr) \
  1172. { \
  1173. XFadeContext *s = ctx->priv; \
  1174. const int width = out->width; \
  1175. const float h = out->height; \
  1176. \
  1177. for (int y = slice_start; y < slice_end; y++) { \
  1178. const float smooth = smoothstep(-0.5f, 0.f, y / h - progress * 1.5f); \
  1179. const float ss = smooth <= fract(10.f * y / h) ? 0.f : 1.f; \
  1180. \
  1181. for (int x = 0; x < width; x++) { \
  1182. for (int p = 0; p < s->nb_planes; p++) { \
  1183. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1184. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1185. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1186. \
  1187. dst[x] = mix(xf1[x], xf0[x], ss); \
  1188. } \
  1189. } \
  1190. } \
  1191. }
  1192. VUSLICE_TRANSITION(8, uint8_t, 1)
  1193. VUSLICE_TRANSITION(16, uint16_t, 2)
  1194. #define VDSLICE_TRANSITION(name, type, div) \
  1195. static void vdslice##name##_transition(AVFilterContext *ctx, \
  1196. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1197. float progress, \
  1198. int slice_start, int slice_end, int jobnr) \
  1199. { \
  1200. XFadeContext *s = ctx->priv; \
  1201. const int width = out->width; \
  1202. const float h = out->height; \
  1203. \
  1204. for (int y = slice_start; y < slice_end; y++) { \
  1205. const float yy = (h - 1 - y) / h; \
  1206. const float smooth = smoothstep(-0.5f, 0.f, yy - progress * 1.5f); \
  1207. const float ss = smooth <= fract(10.f * yy) ? 0.f : 1.f; \
  1208. \
  1209. for (int x = 0; x < width; x++) { \
  1210. for (int p = 0; p < s->nb_planes; p++) { \
  1211. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1212. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1213. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1214. \
  1215. dst[x] = mix(xf1[x], xf0[x], ss); \
  1216. } \
  1217. } \
  1218. } \
  1219. }
  1220. VDSLICE_TRANSITION(8, uint8_t, 1)
  1221. VDSLICE_TRANSITION(16, uint16_t, 2)
  1222. #define HBLUR_TRANSITION(name, type, div) \
  1223. static void hblur##name##_transition(AVFilterContext *ctx, \
  1224. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1225. float progress, \
  1226. int slice_start, int slice_end, int jobnr) \
  1227. { \
  1228. XFadeContext *s = ctx->priv; \
  1229. const int width = out->width; \
  1230. const float prog = progress <= 0.5f ? progress * 2.f : (1.f - progress) * 2.f; \
  1231. const int size = 1 + (width / 2) * prog; \
  1232. \
  1233. for (int y = slice_start; y < slice_end; y++) { \
  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]); \
  1238. float sum0 = 0.f; \
  1239. float sum1 = 0.f; \
  1240. float cnt = size; \
  1241. \
  1242. for (int x = 0; x < size; x++) { \
  1243. sum0 += xf0[x]; \
  1244. sum1 += xf1[x]; \
  1245. } \
  1246. \
  1247. for (int x = 0; x < width; x++) { \
  1248. dst[x] = mix(sum0 / cnt, sum1 / cnt, progress); \
  1249. \
  1250. if (x + size < width) { \
  1251. sum0 += xf0[x + size] - xf0[x]; \
  1252. sum1 += xf1[x + size] - xf1[x]; \
  1253. } else { \
  1254. sum0 -= xf0[x]; \
  1255. sum1 -= xf1[x]; \
  1256. cnt--; \
  1257. } \
  1258. } \
  1259. } \
  1260. } \
  1261. }
  1262. HBLUR_TRANSITION(8, uint8_t, 1)
  1263. HBLUR_TRANSITION(16, uint16_t, 2)
  1264. #define FADEGRAYS_TRANSITION(name, type, div) \
  1265. static void fadegrays##name##_transition(AVFilterContext *ctx, \
  1266. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1267. float progress, \
  1268. int slice_start, int slice_end, int jobnr) \
  1269. { \
  1270. XFadeContext *s = ctx->priv; \
  1271. const int width = out->width; \
  1272. const int is_rgb = s->is_rgb; \
  1273. const int mid = (s->max_value + 1) / 2; \
  1274. const float phase = 0.2f; \
  1275. \
  1276. for (int y = slice_start; y < slice_end; y++) { \
  1277. for (int x = 0; x < width; x++) { \
  1278. int bg[2][4]; \
  1279. if (is_rgb) { \
  1280. for (int p = 0; p < s->nb_planes; p++) { \
  1281. const type *xf0 = (const type *)(a->data[p] + \
  1282. y * a->linesize[p]); \
  1283. const type *xf1 = (const type *)(b->data[p] + \
  1284. y * b->linesize[p]); \
  1285. if (p == 3) { \
  1286. bg[0][3] = xf0[x]; \
  1287. bg[1][3] = xf1[x]; \
  1288. } else { \
  1289. bg[0][0] += xf0[x]; \
  1290. bg[1][0] += xf1[x]; \
  1291. } \
  1292. } \
  1293. bg[0][0] = bg[0][0] / 3; \
  1294. bg[1][0] = bg[1][0] / 3; \
  1295. bg[0][1] = bg[0][2] = bg[0][0]; \
  1296. bg[1][1] = bg[1][2] = bg[1][0]; \
  1297. } else { \
  1298. const type *yf0 = (const type *)(a->data[0] + \
  1299. y * a->linesize[0]); \
  1300. const type *yf1 = (const type *)(b->data[0] + \
  1301. y * a->linesize[0]); \
  1302. bg[0][0] = yf0[x]; \
  1303. bg[1][0] = yf1[x]; \
  1304. if (s->nb_planes == 4) { \
  1305. const type *af0 = (const type *)(a->data[3] + \
  1306. y * a->linesize[3]); \
  1307. const type *af1 = (const type *)(b->data[3] + \
  1308. y * a->linesize[3]); \
  1309. bg[0][3] = af0[x]; \
  1310. bg[1][3] = af1[x]; \
  1311. } \
  1312. bg[0][1] = bg[1][1] = mid; \
  1313. bg[0][2] = bg[1][2] = mid; \
  1314. } \
  1315. \
  1316. for (int p = 0; p < s->nb_planes; p++) { \
  1317. const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
  1318. const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
  1319. type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
  1320. \
  1321. dst[x] = mix(mix(xf0[x], bg[0][p], \
  1322. smoothstep(1.f-phase, 1.f, progress)), \
  1323. mix(bg[1][p], xf1[x], smoothstep(phase, 1.f, progress)), \
  1324. progress); \
  1325. } \
  1326. } \
  1327. } \
  1328. }
  1329. FADEGRAYS_TRANSITION(8, uint8_t, 1)
  1330. FADEGRAYS_TRANSITION(16, uint16_t, 2)
  1331. #define WIPETL_TRANSITION(name, type, div) \
  1332. static void wipetl##name##_transition(AVFilterContext *ctx, \
  1333. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1334. float progress, \
  1335. int slice_start, int slice_end, int jobnr) \
  1336. { \
  1337. XFadeContext *s = ctx->priv; \
  1338. const int height = slice_end - slice_start; \
  1339. const int zw = out->width * progress; \
  1340. const int zh = out->height * progress; \
  1341. \
  1342. for (int p = 0; p < s->nb_planes; p++) { \
  1343. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  1344. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  1345. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  1346. \
  1347. for (int y = 0; y < height; y++) { \
  1348. for (int x = 0; x < out->width; x++) { \
  1349. dst[x] = slice_start + y <= zh && \
  1350. x <= zw ? xf0[x] : xf1[x]; \
  1351. } \
  1352. \
  1353. dst += out->linesize[p] / div; \
  1354. xf0 += a->linesize[p] / div; \
  1355. xf1 += b->linesize[p] / div; \
  1356. } \
  1357. } \
  1358. }
  1359. WIPETL_TRANSITION(8, uint8_t, 1)
  1360. WIPETL_TRANSITION(16, uint16_t, 2)
  1361. #define WIPETR_TRANSITION(name, type, div) \
  1362. static void wipetr##name##_transition(AVFilterContext *ctx, \
  1363. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1364. float progress, \
  1365. int slice_start, int slice_end, int jobnr) \
  1366. { \
  1367. XFadeContext *s = ctx->priv; \
  1368. const int height = slice_end - slice_start; \
  1369. const int zw = out->width * (1.f - progress); \
  1370. const int zh = out->height * progress; \
  1371. \
  1372. for (int p = 0; p < s->nb_planes; p++) { \
  1373. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  1374. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  1375. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  1376. \
  1377. for (int y = 0; y < height; y++) { \
  1378. for (int x = 0; x < out->width; x++) { \
  1379. dst[x] = slice_start + y <= zh && \
  1380. x > zw ? xf0[x] : xf1[x]; \
  1381. } \
  1382. \
  1383. dst += out->linesize[p] / div; \
  1384. xf0 += a->linesize[p] / div; \
  1385. xf1 += b->linesize[p] / div; \
  1386. } \
  1387. } \
  1388. }
  1389. WIPETR_TRANSITION(8, uint8_t, 1)
  1390. WIPETR_TRANSITION(16, uint16_t, 2)
  1391. #define WIPEBL_TRANSITION(name, type, div) \
  1392. static void wipebl##name##_transition(AVFilterContext *ctx, \
  1393. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1394. float progress, \
  1395. int slice_start, int slice_end, int jobnr) \
  1396. { \
  1397. XFadeContext *s = ctx->priv; \
  1398. const int height = slice_end - slice_start; \
  1399. const int zw = out->width * progress; \
  1400. const int zh = out->height * (1.f - progress); \
  1401. \
  1402. for (int p = 0; p < s->nb_planes; p++) { \
  1403. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  1404. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  1405. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  1406. \
  1407. for (int y = 0; y < height; y++) { \
  1408. for (int x = 0; x < out->width; x++) { \
  1409. dst[x] = slice_start + y > zh && \
  1410. x <= zw ? xf0[x] : xf1[x]; \
  1411. } \
  1412. \
  1413. dst += out->linesize[p] / div; \
  1414. xf0 += a->linesize[p] / div; \
  1415. xf1 += b->linesize[p] / div; \
  1416. } \
  1417. } \
  1418. }
  1419. WIPEBL_TRANSITION(8, uint8_t, 1)
  1420. WIPEBL_TRANSITION(16, uint16_t, 2)
  1421. #define WIPEBR_TRANSITION(name, type, div) \
  1422. static void wipebr##name##_transition(AVFilterContext *ctx, \
  1423. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1424. float progress, \
  1425. int slice_start, int slice_end, int jobnr) \
  1426. { \
  1427. XFadeContext *s = ctx->priv; \
  1428. const int height = slice_end - slice_start; \
  1429. const int zh = out->height * (1.f - progress); \
  1430. const int zw = out->width * (1.f - progress); \
  1431. \
  1432. for (int p = 0; p < s->nb_planes; p++) { \
  1433. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  1434. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  1435. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  1436. \
  1437. for (int y = 0; y < height; y++) { \
  1438. for (int x = 0; x < out->width; x++) { \
  1439. dst[x] = slice_start + y > zh && \
  1440. x > zw ? xf0[x] : xf1[x]; \
  1441. } \
  1442. \
  1443. dst += out->linesize[p] / div; \
  1444. xf0 += a->linesize[p] / div; \
  1445. xf1 += b->linesize[p] / div; \
  1446. } \
  1447. } \
  1448. }
  1449. WIPEBR_TRANSITION(8, uint8_t, 1)
  1450. WIPEBR_TRANSITION(16, uint16_t, 2)
  1451. #define SQUEEZEH_TRANSITION(name, type, div) \
  1452. static void squeezeh##name##_transition(AVFilterContext *ctx, \
  1453. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1454. float progress, \
  1455. int slice_start, int slice_end, int jobnr) \
  1456. { \
  1457. XFadeContext *s = ctx->priv; \
  1458. const float h = out->height; \
  1459. const int height = slice_end - slice_start; \
  1460. \
  1461. for (int p = 0; p < s->nb_planes; p++) { \
  1462. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  1463. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  1464. \
  1465. for (int y = 0; y < height; y++) { \
  1466. const float z = .5f + ((slice_start + y) / h - .5f) / progress; \
  1467. \
  1468. if (z < 0.f || z > 1.f) { \
  1469. for (int x = 0; x < out->width; x++) \
  1470. dst[x] = xf1[x]; \
  1471. } else { \
  1472. const int yy = lrintf(z * (h - 1.f)); \
  1473. const type *xf0 = (const type *)(a->data[p] + yy * a->linesize[p]); \
  1474. \
  1475. for (int x = 0; x < out->width; x++) \
  1476. dst[x] = xf0[x]; \
  1477. } \
  1478. \
  1479. dst += out->linesize[p] / div; \
  1480. xf1 += b->linesize[p] / div; \
  1481. } \
  1482. } \
  1483. }
  1484. SQUEEZEH_TRANSITION(8, uint8_t, 1)
  1485. SQUEEZEH_TRANSITION(16, uint16_t, 2)
  1486. #define SQUEEZEV_TRANSITION(name, type, div) \
  1487. static void squeezev##name##_transition(AVFilterContext *ctx, \
  1488. const AVFrame *a, const AVFrame *b, AVFrame *out, \
  1489. float progress, \
  1490. int slice_start, int slice_end, int jobnr) \
  1491. { \
  1492. XFadeContext *s = ctx->priv; \
  1493. const float w = out->width; \
  1494. const int height = slice_end - slice_start; \
  1495. \
  1496. for (int p = 0; p < s->nb_planes; p++) { \
  1497. const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
  1498. const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
  1499. type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
  1500. \
  1501. for (int y = 0; y < height; y++) { \
  1502. for (int x = 0; x < out->width; x++) { \
  1503. const float z = .5f + (x / w - .5f) / progress; \
  1504. \
  1505. if (z < 0.f || z > 1.f) { \
  1506. dst[x] = xf1[x]; \
  1507. } else { \
  1508. const int xx = lrintf(z * (w - 1.f)); \
  1509. \
  1510. dst[x] = xf0[xx]; \
  1511. } \
  1512. } \
  1513. \
  1514. dst += out->linesize[p] / div; \
  1515. xf0 += a->linesize[p] / div; \
  1516. xf1 += b->linesize[p] / div; \
  1517. } \
  1518. } \
  1519. }
  1520. SQUEEZEV_TRANSITION(8, uint8_t, 1)
  1521. SQUEEZEV_TRANSITION(16, uint16_t, 2)
  1522. static inline double getpix(void *priv, double x, double y, int plane, int nb)
  1523. {
  1524. XFadeContext *s = priv;
  1525. AVFrame *in = s->xf[nb];
  1526. const uint8_t *src = in->data[FFMIN(plane, s->nb_planes - 1)];
  1527. int linesize = in->linesize[FFMIN(plane, s->nb_planes - 1)];
  1528. const int w = in->width;
  1529. const int h = in->height;
  1530. int xi, yi;
  1531. xi = av_clipd(x, 0, w - 1);
  1532. yi = av_clipd(y, 0, h - 1);
  1533. if (s->depth > 8) {
  1534. const uint16_t *src16 = (const uint16_t*)src;
  1535. linesize /= 2;
  1536. return src16[xi + yi * linesize];
  1537. } else {
  1538. return src[xi + yi * linesize];
  1539. }
  1540. }
  1541. static double a0(void *priv, double x, double y) { return getpix(priv, x, y, 0, 0); }
  1542. static double a1(void *priv, double x, double y) { return getpix(priv, x, y, 1, 0); }
  1543. static double a2(void *priv, double x, double y) { return getpix(priv, x, y, 2, 0); }
  1544. static double a3(void *priv, double x, double y) { return getpix(priv, x, y, 3, 0); }
  1545. static double b0(void *priv, double x, double y) { return getpix(priv, x, y, 0, 1); }
  1546. static double b1(void *priv, double x, double y) { return getpix(priv, x, y, 1, 1); }
  1547. static double b2(void *priv, double x, double y) { return getpix(priv, x, y, 2, 1); }
  1548. static double b3(void *priv, double x, double y) { return getpix(priv, x, y, 3, 1); }
  1549. static int config_output(AVFilterLink *outlink)
  1550. {
  1551. AVFilterContext *ctx = outlink->src;
  1552. AVFilterLink *inlink0 = ctx->inputs[0];
  1553. AVFilterLink *inlink1 = ctx->inputs[1];
  1554. XFadeContext *s = ctx->priv;
  1555. const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink0->format);
  1556. if (inlink0->format != inlink1->format) {
  1557. av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
  1558. return AVERROR(EINVAL);
  1559. }
  1560. if (inlink0->w != inlink1->w || inlink0->h != inlink1->h) {
  1561. av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
  1562. "(size %dx%d) do not match the corresponding "
  1563. "second input link %s parameters (size %dx%d)\n",
  1564. ctx->input_pads[0].name, inlink0->w, inlink0->h,
  1565. ctx->input_pads[1].name, inlink1->w, inlink1->h);
  1566. return AVERROR(EINVAL);
  1567. }
  1568. if (inlink0->time_base.num != inlink1->time_base.num ||
  1569. inlink0->time_base.den != inlink1->time_base.den) {
  1570. av_log(ctx, AV_LOG_ERROR, "First input link %s timebase "
  1571. "(%d/%d) do not match the corresponding "
  1572. "second input link %s timebase (%d/%d)\n",
  1573. ctx->input_pads[0].name, inlink0->time_base.num, inlink0->time_base.den,
  1574. ctx->input_pads[1].name, inlink1->time_base.num, inlink1->time_base.den);
  1575. return AVERROR(EINVAL);
  1576. }
  1577. if (!inlink0->frame_rate.num || !inlink0->frame_rate.den) {
  1578. av_log(ctx, AV_LOG_ERROR, "The inputs needs to be a constant frame rate; "
  1579. "current rate of %d/%d is invalid\n", inlink0->frame_rate.num, inlink0->frame_rate.den);
  1580. return AVERROR(EINVAL);
  1581. }
  1582. if (inlink0->frame_rate.num != inlink1->frame_rate.num ||
  1583. inlink0->frame_rate.den != inlink1->frame_rate.den) {
  1584. av_log(ctx, AV_LOG_ERROR, "First input link %s frame rate "
  1585. "(%d/%d) do not match the corresponding "
  1586. "second input link %s frame rate (%d/%d)\n",
  1587. ctx->input_pads[0].name, inlink0->frame_rate.num, inlink0->frame_rate.den,
  1588. ctx->input_pads[1].name, inlink1->frame_rate.num, inlink1->frame_rate.den);
  1589. return AVERROR(EINVAL);
  1590. }
  1591. outlink->w = inlink0->w;
  1592. outlink->h = inlink0->h;
  1593. outlink->time_base = inlink0->time_base;
  1594. outlink->sample_aspect_ratio = inlink0->sample_aspect_ratio;
  1595. outlink->frame_rate = inlink0->frame_rate;
  1596. s->depth = pix_desc->comp[0].depth;
  1597. s->is_rgb = !!(pix_desc->flags & AV_PIX_FMT_FLAG_RGB);
  1598. s->nb_planes = av_pix_fmt_count_planes(inlink0->format);
  1599. s->max_value = (1 << s->depth) - 1;
  1600. s->black[0] = 0;
  1601. s->black[1] = s->black[2] = s->is_rgb ? 0 : s->max_value / 2;
  1602. s->black[3] = s->max_value;
  1603. s->white[0] = s->white[3] = s->max_value;
  1604. s->white[1] = s->white[2] = s->is_rgb ? s->max_value : s->max_value / 2;
  1605. s->first_pts = s->last_pts = s->pts = AV_NOPTS_VALUE;
  1606. if (s->duration)
  1607. s->duration_pts = av_rescale_q(s->duration, AV_TIME_BASE_Q, outlink->time_base);
  1608. if (s->offset)
  1609. s->offset_pts = av_rescale_q(s->offset, AV_TIME_BASE_Q, outlink->time_base);
  1610. switch (s->transition) {
  1611. case CUSTOM: s->transitionf = s->depth <= 8 ? custom8_transition : custom16_transition; break;
  1612. case FADE: s->transitionf = s->depth <= 8 ? fade8_transition : fade16_transition; break;
  1613. case WIPELEFT: s->transitionf = s->depth <= 8 ? wipeleft8_transition : wipeleft16_transition; break;
  1614. case WIPERIGHT: s->transitionf = s->depth <= 8 ? wiperight8_transition : wiperight16_transition; break;
  1615. case WIPEUP: s->transitionf = s->depth <= 8 ? wipeup8_transition : wipeup16_transition; break;
  1616. case WIPEDOWN: s->transitionf = s->depth <= 8 ? wipedown8_transition : wipedown16_transition; break;
  1617. case SLIDELEFT: s->transitionf = s->depth <= 8 ? slideleft8_transition : slideleft16_transition; break;
  1618. case SLIDERIGHT: s->transitionf = s->depth <= 8 ? slideright8_transition : slideright16_transition; break;
  1619. case SLIDEUP: s->transitionf = s->depth <= 8 ? slideup8_transition : slideup16_transition; break;
  1620. case SLIDEDOWN: s->transitionf = s->depth <= 8 ? slidedown8_transition : slidedown16_transition; break;
  1621. case CIRCLECROP: s->transitionf = s->depth <= 8 ? circlecrop8_transition : circlecrop16_transition; break;
  1622. case RECTCROP: s->transitionf = s->depth <= 8 ? rectcrop8_transition : rectcrop16_transition; break;
  1623. case DISTANCE: s->transitionf = s->depth <= 8 ? distance8_transition : distance16_transition; break;
  1624. case FADEBLACK: s->transitionf = s->depth <= 8 ? fadeblack8_transition : fadeblack16_transition; break;
  1625. case FADEWHITE: s->transitionf = s->depth <= 8 ? fadewhite8_transition : fadewhite16_transition; break;
  1626. case RADIAL: s->transitionf = s->depth <= 8 ? radial8_transition : radial16_transition; break;
  1627. case SMOOTHLEFT: s->transitionf = s->depth <= 8 ? smoothleft8_transition : smoothleft16_transition; break;
  1628. case SMOOTHRIGHT:s->transitionf = s->depth <= 8 ? smoothright8_transition: smoothright16_transition;break;
  1629. case SMOOTHUP: s->transitionf = s->depth <= 8 ? smoothup8_transition : smoothup16_transition; break;
  1630. case SMOOTHDOWN: s->transitionf = s->depth <= 8 ? smoothdown8_transition : smoothdown16_transition; break;
  1631. case CIRCLEOPEN: s->transitionf = s->depth <= 8 ? circleopen8_transition : circleopen16_transition; break;
  1632. case CIRCLECLOSE:s->transitionf = s->depth <= 8 ? circleclose8_transition: circleclose16_transition;break;
  1633. case VERTOPEN: s->transitionf = s->depth <= 8 ? vertopen8_transition : vertopen16_transition; break;
  1634. case VERTCLOSE: s->transitionf = s->depth <= 8 ? vertclose8_transition : vertclose16_transition; break;
  1635. case HORZOPEN: s->transitionf = s->depth <= 8 ? horzopen8_transition : horzopen16_transition; break;
  1636. case HORZCLOSE: s->transitionf = s->depth <= 8 ? horzclose8_transition : horzclose16_transition; break;
  1637. case DISSOLVE: s->transitionf = s->depth <= 8 ? dissolve8_transition : dissolve16_transition; break;
  1638. case PIXELIZE: s->transitionf = s->depth <= 8 ? pixelize8_transition : pixelize16_transition; break;
  1639. case DIAGTL: s->transitionf = s->depth <= 8 ? diagtl8_transition : diagtl16_transition; break;
  1640. case DIAGTR: s->transitionf = s->depth <= 8 ? diagtr8_transition : diagtr16_transition; break;
  1641. case DIAGBL: s->transitionf = s->depth <= 8 ? diagbl8_transition : diagbl16_transition; break;
  1642. case DIAGBR: s->transitionf = s->depth <= 8 ? diagbr8_transition : diagbr16_transition; break;
  1643. case HLSLICE: s->transitionf = s->depth <= 8 ? hlslice8_transition : hlslice16_transition; break;
  1644. case HRSLICE: s->transitionf = s->depth <= 8 ? hrslice8_transition : hrslice16_transition; break;
  1645. case VUSLICE: s->transitionf = s->depth <= 8 ? vuslice8_transition : vuslice16_transition; break;
  1646. case VDSLICE: s->transitionf = s->depth <= 8 ? vdslice8_transition : vdslice16_transition; break;
  1647. case HBLUR: s->transitionf = s->depth <= 8 ? hblur8_transition : hblur16_transition; break;
  1648. case FADEGRAYS: s->transitionf = s->depth <= 8 ? fadegrays8_transition : fadegrays16_transition; break;
  1649. case WIPETL: s->transitionf = s->depth <= 8 ? wipetl8_transition : wipetl16_transition; break;
  1650. case WIPETR: s->transitionf = s->depth <= 8 ? wipetr8_transition : wipetr16_transition; break;
  1651. case WIPEBL: s->transitionf = s->depth <= 8 ? wipebl8_transition : wipebl16_transition; break;
  1652. case WIPEBR: s->transitionf = s->depth <= 8 ? wipebr8_transition : wipebr16_transition; break;
  1653. case SQUEEZEH: s->transitionf = s->depth <= 8 ? squeezeh8_transition : squeezeh16_transition; break;
  1654. case SQUEEZEV: s->transitionf = s->depth <= 8 ? squeezev8_transition : squeezev16_transition; break;
  1655. }
  1656. if (s->transition == CUSTOM) {
  1657. static const char *const func2_names[] = {
  1658. "a0", "a1", "a2", "a3",
  1659. "b0", "b1", "b2", "b3",
  1660. NULL
  1661. };
  1662. double (*func2[])(void *, double, double) = {
  1663. a0, a1, a2, a3,
  1664. b0, b1, b2, b3,
  1665. NULL };
  1666. int ret;
  1667. if (!s->custom_str)
  1668. return AVERROR(EINVAL);
  1669. ret = av_expr_parse(&s->e, s->custom_str, var_names,
  1670. NULL, NULL, func2_names, func2, 0, ctx);
  1671. if (ret < 0)
  1672. return ret;
  1673. }
  1674. return 0;
  1675. }
  1676. static int xfade_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  1677. {
  1678. XFadeContext *s = ctx->priv;
  1679. AVFilterLink *outlink = ctx->outputs[0];
  1680. ThreadData *td = arg;
  1681. int slice_start = (outlink->h * jobnr ) / nb_jobs;
  1682. int slice_end = (outlink->h * (jobnr+1)) / nb_jobs;
  1683. s->transitionf(ctx, td->xf[0], td->xf[1], td->out, td->progress, slice_start, slice_end, jobnr);
  1684. return 0;
  1685. }
  1686. static int xfade_frame(AVFilterContext *ctx, AVFrame *a, AVFrame *b)
  1687. {
  1688. XFadeContext *s = ctx->priv;
  1689. AVFilterLink *outlink = ctx->outputs[0];
  1690. float progress = av_clipf(1.f - ((float)(s->pts - s->first_pts - s->offset_pts) / s->duration_pts), 0.f, 1.f);
  1691. ThreadData td;
  1692. AVFrame *out;
  1693. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  1694. if (!out)
  1695. return AVERROR(ENOMEM);
  1696. av_frame_copy_props(out, a);
  1697. td.xf[0] = a, td.xf[1] = b, td.out = out, td.progress = progress;
  1698. ctx->internal->execute(ctx, xfade_slice, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
  1699. out->pts = s->pts;
  1700. return ff_filter_frame(outlink, out);
  1701. }
  1702. static int xfade_activate(AVFilterContext *ctx)
  1703. {
  1704. XFadeContext *s = ctx->priv;
  1705. AVFilterLink *outlink = ctx->outputs[0];
  1706. AVFrame *in = NULL;
  1707. int ret = 0, status;
  1708. int64_t pts;
  1709. FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
  1710. if (s->xfade_is_over) {
  1711. ret = ff_inlink_consume_frame(ctx->inputs[1], &in);
  1712. if (ret < 0) {
  1713. return ret;
  1714. } else if (ret > 0) {
  1715. in->pts = (in->pts - s->last_pts) + s->pts;
  1716. return ff_filter_frame(outlink, in);
  1717. } else if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) {
  1718. ff_outlink_set_status(outlink, status, s->pts);
  1719. return 0;
  1720. } else if (!ret) {
  1721. if (ff_outlink_frame_wanted(outlink))
  1722. ff_inlink_request_frame(ctx->inputs[1]);
  1723. return 0;
  1724. }
  1725. }
  1726. if (ff_inlink_queued_frames(ctx->inputs[0]) > 0) {
  1727. s->xf[0] = ff_inlink_peek_frame(ctx->inputs[0], 0);
  1728. if (s->xf[0]) {
  1729. if (s->first_pts == AV_NOPTS_VALUE) {
  1730. s->first_pts = s->xf[0]->pts;
  1731. }
  1732. s->pts = s->xf[0]->pts;
  1733. if (s->first_pts + s->offset_pts > s->xf[0]->pts) {
  1734. s->xf[0] = NULL;
  1735. s->need_second = 0;
  1736. ff_inlink_consume_frame(ctx->inputs[0], &in);
  1737. return ff_filter_frame(outlink, in);
  1738. }
  1739. s->need_second = 1;
  1740. }
  1741. }
  1742. if (s->xf[0] && ff_inlink_queued_frames(ctx->inputs[1]) > 0) {
  1743. ff_inlink_consume_frame(ctx->inputs[0], &s->xf[0]);
  1744. ff_inlink_consume_frame(ctx->inputs[1], &s->xf[1]);
  1745. s->last_pts = s->xf[1]->pts;
  1746. s->pts = s->xf[0]->pts;
  1747. if (s->xf[0]->pts - (s->first_pts + s->offset_pts) > s->duration_pts)
  1748. s->xfade_is_over = 1;
  1749. ret = xfade_frame(ctx, s->xf[0], s->xf[1]);
  1750. av_frame_free(&s->xf[0]);
  1751. av_frame_free(&s->xf[1]);
  1752. return ret;
  1753. }
  1754. if (ff_inlink_queued_frames(ctx->inputs[0]) > 0 &&
  1755. ff_inlink_queued_frames(ctx->inputs[1]) > 0) {
  1756. ff_filter_set_ready(ctx, 100);
  1757. return 0;
  1758. }
  1759. if (ff_outlink_frame_wanted(outlink)) {
  1760. if (!s->eof[0] && ff_outlink_get_status(ctx->inputs[0])) {
  1761. s->eof[0] = 1;
  1762. s->xfade_is_over = 1;
  1763. }
  1764. if (!s->eof[1] && ff_outlink_get_status(ctx->inputs[1])) {
  1765. s->eof[1] = 1;
  1766. }
  1767. if (!s->eof[0] && !s->xf[0] && ff_inlink_queued_frames(ctx->inputs[0]) == 0)
  1768. ff_inlink_request_frame(ctx->inputs[0]);
  1769. if (!s->eof[1] && (s->need_second || s->eof[0]) && ff_inlink_queued_frames(ctx->inputs[1]) == 0)
  1770. ff_inlink_request_frame(ctx->inputs[1]);
  1771. if (s->eof[0] && s->eof[1] && (
  1772. ff_inlink_queued_frames(ctx->inputs[0]) <= 0 &&
  1773. ff_inlink_queued_frames(ctx->inputs[1]) <= 0)) {
  1774. ff_outlink_set_status(outlink, AVERROR_EOF, AV_NOPTS_VALUE);
  1775. } else if (s->xfade_is_over) {
  1776. ff_filter_set_ready(ctx, 100);
  1777. }
  1778. return 0;
  1779. }
  1780. return FFERROR_NOT_READY;
  1781. }
  1782. static const AVFilterPad xfade_inputs[] = {
  1783. {
  1784. .name = "main",
  1785. .type = AVMEDIA_TYPE_VIDEO,
  1786. },
  1787. {
  1788. .name = "xfade",
  1789. .type = AVMEDIA_TYPE_VIDEO,
  1790. },
  1791. { NULL }
  1792. };
  1793. static const AVFilterPad xfade_outputs[] = {
  1794. {
  1795. .name = "default",
  1796. .type = AVMEDIA_TYPE_VIDEO,
  1797. .config_props = config_output,
  1798. },
  1799. { NULL }
  1800. };
  1801. AVFilter ff_vf_xfade = {
  1802. .name = "xfade",
  1803. .description = NULL_IF_CONFIG_SMALL("Cross fade one video with another video."),
  1804. .priv_size = sizeof(XFadeContext),
  1805. .priv_class = &xfade_class,
  1806. .query_formats = query_formats,
  1807. .activate = xfade_activate,
  1808. .uninit = uninit,
  1809. .inputs = xfade_inputs,
  1810. .outputs = xfade_outputs,
  1811. .flags = AVFILTER_FLAG_SLICE_THREADS,
  1812. };