History

aviflter/vf_xfade: add pixelize transition

Paul B Mahol committed 6 years ago

Commit 37201531 parent e3e55982 files · +37 −1Browse files

Unified · Split

2 files
  1. doc/filters.texi +1 −0
  2. libavfilter/vf_xfade.c +36 −1
doc/filters.texi+1−0
@@ -19985,6 +19985,7 @@ Set one of available transition effects: · 19984 unmodified lines
19985@item horzopen19985@item horzopen
19986@item horzclose19986@item horzclose
19987@item dissolve19987@item dissolve
19988@item pixelize
19988@end table19989@end table
19989Default transition effect is fade.19990Default transition effect is fade.
19990 19991
libavfilter/vf_xfade.c+36−1
@@ -56,6 +56,7 @@ enum XFadeTransitions { · 55 unmodified lines
56 HORZOPEN,56 HORZOPEN,
57 HORZCLOSE,57 HORZCLOSE,
58 DISSOLVE,58 DISSOLVE,
59 PIXELIZE,
59 NB_TRANSITIONS,60 NB_TRANSITIONS,
60};61};
61 62
@@ -164,6 +165,7 @@ static const AVOption xfade_options[] = { · 102 unmodified lines
164 { "horzopen", "horz open transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZOPEN}, 0, 0, FLAGS, "transition" },165 { "horzopen", "horz open transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZOPEN}, 0, 0, FLAGS, "transition" },
165 { "horzclose", "horz close transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZCLOSE}, 0, 0, FLAGS, "transition" },166 { "horzclose", "horz close transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZCLOSE}, 0, 0, FLAGS, "transition" },
166 { "dissolve", "dissolve transition", 0, AV_OPT_TYPE_CONST, {.i64=DISSOLVE}, 0, 0, FLAGS, "transition" },167 { "dissolve", "dissolve transition", 0, AV_OPT_TYPE_CONST, {.i64=DISSOLVE}, 0, 0, FLAGS, "transition" },
168 { "pixelize", "pixelize transition", 0, AV_OPT_TYPE_CONST, {.i64=PIXELIZE}, 0, 0, FLAGS, "transition" },
167 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },169 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
168 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },170 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
169 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },171 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -1009,6 +1011,38 @@ static void dissolve##name##_transition(AVFilterContext *ctx, · 839 unmodified lines
1009DISSOLVE_TRANSITION(8, uint8_t, 1)1011DISSOLVE_TRANSITION(8, uint8_t, 1)
1010DISSOLVE_TRANSITION(16, uint16_t, 2)1012DISSOLVE_TRANSITION(16, uint16_t, 2)
1011 1013
1014#define PIXELIZE_TRANSITION(name, type, div) \
1015static void pixelize##name##_transition(AVFilterContext *ctx, \
1016 const AVFrame *a, const AVFrame *b, AVFrame *out, \
1017 float progress, \
1018 int slice_start, int slice_end, int jobnr) \
1019{ \
1020 XFadeContext *s = ctx->priv; \
1021 const int w = out->width; \
1022 const int h = out->height; \
1023 const float d = fminf(progress, 1.f - progress); \
1024 const float dist = ceilf(d * 50.f) / 50.f; \
1025 const float sqx = 2.f * dist * FFMIN(w, h) / 20.f; \
1026 const float sqy = 2.f * dist * FFMIN(w, h) / 20.f; \
1027 \
1028 for (int y = slice_start; y < slice_end; y++) { \
1029 for (int x = 0; x < w; x++) { \
1030 int sx = dist > 0.f ? FFMIN((floorf(x / sqx) + .5f) * sqx, w - 1) : x; \
1031 int sy = dist > 0.f ? FFMIN((floorf(y / sqy) + .5f) * sqy, h - 1) : y; \
1032 for (int p = 0; p < s->nb_planes; p++) { \
1033 const type *xf0 = (const type *)(a->data[p] + sy * a->linesize[p]); \
1034 const type *xf1 = (const type *)(b->data[p] + sy * b->linesize[p]); \
1035 type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
1036 \
1037 dst[x] = mix(xf0[sx], xf1[sx], progress); \
1038 } \
1039 } \
1040 } \
1041}
1042
1043PIXELIZE_TRANSITION(8, uint8_t, 1)
1044PIXELIZE_TRANSITION(16, uint16_t, 2)
1045
1012static inline double getpix(void *priv, double x, double y, int plane, int nb)1046static inline double getpix(void *priv, double x, double y, int plane, int nb)
1013{1047{
1014 XFadeContext *s = priv;1048 XFadeContext *s = priv;
@@ -1125,7 +1159,8 @@ static int config_output(AVFilterLink *outlink) · 110 unmodified lines
1125 case VERTCLOSE: s->transitionf = s->depth <= 8 ? vertclose8_transition : vertclose16_transition; break;1159 case VERTCLOSE: s->transitionf = s->depth <= 8 ? vertclose8_transition : vertclose16_transition; break;
1126 case HORZOPEN: s->transitionf = s->depth <= 8 ? horzopen8_transition : horzopen16_transition; break;1160 case HORZOPEN: s->transitionf = s->depth <= 8 ? horzopen8_transition : horzopen16_transition; break;
1127 case HORZCLOSE: s->transitionf = s->depth <= 8 ? horzclose8_transition : horzclose16_transition; break;1161 case HORZCLOSE: s->transitionf = s->depth <= 8 ? horzclose8_transition : horzclose16_transition; break;
1128 case DISSOLVE: s->transitionf = s->depth <= 8 ? dissolve8_transition : dissolve16_transition; break;1162 case DISSOLVE: s->transitionf = s->depth <= 8 ? dissolve8_transition : dissolve16_transition; break;
1163 case PIXELIZE: s->transitionf = s->depth <= 8 ? pixelize8_transition : pixelize16_transition; break;
1129 }1164 }
1130 1165
1131 if (s->transition == CUSTOM) {1166 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