-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvf_xfade.patch
76 lines (66 loc) · 3.46 KB
/
vf_xfade.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--- libavfilter/vf_xfade.c 2025-02-21 00:54:54.000000000 +0000
+++ vf_xfade.c 2025-02-21 00:54:54.000000000 +0000
@@ -126,6 +126,11 @@
void (*transitionf)(AVFilterContext *ctx, const AVFrame *a, const AVFrame *b, AVFrame *out, float progress,
int slice_start, int slice_end, int jobnr);
+ char *easing_str; // easing name with optional args
+ char *transition_str; // transition name with optional args
+ int reverse; // reverse option bit flags (enum ReverseOpts)
+ struct XFadeEasingContext *k; // xfade-easing data
+
AVExpr *e;
} XFadeContext;
@@ -157,18 +162,22 @@
AV_PIX_FMT_NONE
};
+static void xe_data_free(struct XFadeEasingContext *k);
static av_cold void uninit(AVFilterContext *ctx)
{
XFadeContext *s = ctx->priv;
av_expr_free(s->e);
+ xe_data_free(s->k);
}
#define OFFSET(x) offsetof(XFadeContext, x)
#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
static const AVOption xfade_options[] = {
- { "transition", "set cross fade transition", OFFSET(transition), AV_OPT_TYPE_INT, {.i64=FADE}, -1, NB_TRANSITIONS-1, FLAGS, .unit = "transition" },
+ { "easing", "set cross fade easing", OFFSET(easing_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
+ { "reverse", "reverse easing/transition", OFFSET(reverse), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, FLAGS },
+ { "transition", "set cross fade transition", OFFSET(transition_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS, .unit = "transition" },
{ "custom", "custom transition", 0, AV_OPT_TYPE_CONST, {.i64=CUSTOM}, 0, 0, FLAGS, .unit = "transition" },
{ "fade", "fade transition", 0, AV_OPT_TYPE_CONST, {.i64=FADE}, 0, 0, FLAGS, .unit = "transition" },
{ "wipeleft", "wipe left transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPELEFT}, 0, 0, FLAGS, .unit = "transition" },
@@ -2001,10 +2010,12 @@
REVEALV_TRANSITION(down, 8, uint8_t, 1, )
REVEALV_TRANSITION(down, 16, uint16_t, 2, )
+#include "xfade-easing.h" // easing & extended transitions
+
static inline double getpix(void *priv, double x, double y, int plane, int nb)
{
XFadeContext *s = priv;
- AVFrame *in = s->xf[nb];
+ AVFrame *in = s->xf[nb ^ (s->reverse & REVERSE_TRANSITION)];
const uint8_t *src = in->data[FFMIN(plane, s->nb_planes - 1)];
int linesize = in->linesize[FFMIN(plane, s->nb_planes - 1)];
const int w = in->width;
@@ -2102,6 +2113,9 @@
if (s->duration)
s->duration_pts = av_rescale_q(s->duration, AV_TIME_BASE_Q, outlink->time_base);
+ int ret = config_xfade_easing(ctx);
+ if (ret <= 0) return ret; // error or extended transition
+
switch (s->transition) {
case CUSTOM: s->transitionf = s->depth <= 8 ? custom8_transition : custom16_transition; break;
case FADE: s->transitionf = s->depth <= 8 ? fade8_transition : fade16_transition; break;
@@ -2195,8 +2209,12 @@
ThreadData *td = arg;
int slice_start = (outlink->h * jobnr ) / nb_jobs;
int slice_end = (outlink->h * (jobnr+1)) / nb_jobs;
+ int i = s->reverse & REVERSE_TRANSITION; // input 0 or 1
+ float p = td->progress;
- s->transitionf(ctx, td->xf[0], td->xf[1], td->out, td->progress, slice_start, slice_end, jobnr);
+ p = (s->reverse & REVERSE_EASING) ? 1 - ease(s, 1 - p) : ease(s, p); // eased progress
+ if (i) p = 1 - p;
+ s->transitionf(ctx, td->xf[i], td->xf[i ^ 1], td->out, p, slice_start, slice_end, jobnr);
return 0;
}