History

avfilter/vf_xfade: add horzopen/close transition

Paul B Mahol committed 6 years ago

Commit 2d58fa61 parent 10f44412 files · +62 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +2 −0
  2. libavfilter/vf_xfade.c +60 −0
doc/filters.texi+2−0
@@ -19944,6 +19944,8 @@ Set one of available transition effects: · 19943 unmodified lines
1994419944 @item circleclose
1994519945 @item vertopen
1994619946 @item vertclose
19947+@item horzopen
19948+@item horzclose
1994719949 @end table
1994819950 Default transition effect is fade.
1994919951
libavfilter/vf_xfade.c+60−0
@@ -53,6 +53,8 @@ enum XFadeTransitions { · 52 unmodified lines
5353 CIRCLECLOSE,
5454 VERTOPEN,
5555 VERTCLOSE,
56+ HORZOPEN,
57+ HORZCLOSE,
5658 NB_TRANSITIONS,
5759 };
5860
@@ -158,6 +160,8 @@ static const AVOption xfade_options[] = { · 99 unmodified lines
158160 { "circleclose","circleclose transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLECLOSE},0, 0, FLAGS, "transition" },
159161 { "vertopen", "vert open transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTOPEN}, 0, 0, FLAGS, "transition" },
160162 { "vertclose", "vert close transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTCLOSE}, 0, 0, FLAGS, "transition" },
163+ { "horzopen", "horz open transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZOPEN}, 0, 0, FLAGS, "transition" },
164+ { "horzclose", "horz close transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZCLOSE}, 0, 0, FLAGS, "transition" },
161165 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
162166 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
163167 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -916,6 +920,60 @@ static void vertclose##name##_transition(AVFilterContext *ctx, · 752 unmodified lines
916920 VERTCLOSE_TRANSITION(8, uint8_t, 1)
917921 VERTCLOSE_TRANSITION(16, uint16_t, 2)
918922
923+#define HORZOPEN_TRANSITION(name, type, div) \
924+static void horzopen##name##_transition(AVFilterContext *ctx, \
925+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
926+ float progress, \
927+ int slice_start, int slice_end, int jobnr) \
928+{ \
929+ XFadeContext *s = ctx->priv; \
930+ const int width = out->width; \
931+ const float h2 = out->height / 2; \
932+ \
933+ for (int y = slice_start; y < slice_end; y++) { \
934+ const float smooth = 2.f - fabsf((y - h2) / h2) - progress * 2.f; \
935+ for (int x = 0; x < width; x++) { \
936+ for (int p = 0; p < s->nb_planes; p++) { \
937+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
938+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
939+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
940+ \
941+ dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
942+ } \
943+ } \
944+ } \
945+}
946+
947+HORZOPEN_TRANSITION(8, uint8_t, 1)
948+HORZOPEN_TRANSITION(16, uint16_t, 2)
949+
950+#define HORZCLOSE_TRANSITION(name, type, div) \
951+static void horzclose##name##_transition(AVFilterContext *ctx, \
952+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
953+ float progress, \
954+ int slice_start, int slice_end, int jobnr) \
955+{ \
956+ XFadeContext *s = ctx->priv; \
957+ const int width = out->width; \
958+ const float h2 = out->height / 2; \
959+ \
960+ for (int y = slice_start; y < slice_end; y++) { \
961+ const float smooth = 1.f + fabsf((y - h2) / h2) - progress * 2.f; \
962+ for (int x = 0; x < width; x++) { \
963+ for (int p = 0; p < s->nb_planes; p++) { \
964+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
965+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
966+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
967+ \
968+ dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
969+ } \
970+ } \
971+ } \
972+}
973+
974+HORZCLOSE_TRANSITION(8, uint8_t, 1)
975+HORZCLOSE_TRANSITION(16, uint16_t, 2)
976+
919977 static inline double getpix(void *priv, double x, double y, int plane, int nb)
920978 {
921979 XFadeContext *s = priv;
@@ -1030,6 +1088,8 @@ static int config_output(AVFilterLink *outlink) · 108 unmodified lines
10301088 case CIRCLECLOSE:s->transitionf = s->depth <= 8 ? circleclose8_transition: circleclose16_transition;break;
10311089 case VERTOPEN: s->transitionf = s->depth <= 8 ? vertopen8_transition : vertopen16_transition; break;
10321090 case VERTCLOSE: s->transitionf = s->depth <= 8 ? vertclose8_transition : vertclose16_transition; break;
1091+ case HORZOPEN: s->transitionf = s->depth <= 8 ? horzopen8_transition : horzopen16_transition; break;
1092+ case HORZCLOSE: s->transitionf = s->depth <= 8 ? horzclose8_transition : horzclose16_transition; break;
10331093 }
10341094
10351095 if (s->transition == CUSTOM) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t