History

avfilter/vf_xfade: add squeeze transitions

Paul B Mahol committed 5 years ago

Commit c417f1a1 parent 7ac1dc22 files · +83 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +2 −0
  2. libavfilter/vf_xfade.c +81 −0
doc/filters.texi+2−0
@@ -20716,6 +20716,8 @@ Set one of available transition effects: · 20715 unmodified lines
2071620716 @item wipetr
2071720717 @item wipebl
2071820718 @item wipebr
20719+@item squeezeh
20720+@item squeezev
2071920721 @end table
2072020722 Default transition effect is fade.
2072120723
libavfilter/vf_xfade.c+81−0
@@ -71,6 +71,8 @@ enum XFadeTransitions { · 70 unmodified lines
7171 WIPETR,
7272 WIPEBL,
7373 WIPEBR,
74+ SQUEEZEH,
75+ SQUEEZEV,
7476 NB_TRANSITIONS,
7577 };
7678
@@ -195,6 +197,8 @@ static const AVOption xfade_options[] = { · 118 unmodified lines
195197 { "wipetr", "wipe tr transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPETR}, 0, 0, FLAGS, "transition" },
196198 { "wipebl", "wipe bl transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPEBL}, 0, 0, FLAGS, "transition" },
197199 { "wipebr", "wipe br transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPEBR}, 0, 0, FLAGS, "transition" },
200+ { "squeezeh", "squeeze h transition", 0, AV_OPT_TYPE_CONST, {.i64=SQUEEZEH}, 0, 0, FLAGS, "transition" },
201+ { "squeezev", "squeeze v transition", 0, AV_OPT_TYPE_CONST, {.i64=SQUEEZEV}, 0, 0, FLAGS, "transition" },
198202 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
199203 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
200204 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -1553,6 +1557,81 @@ static void wipebr##name##_transition(AVFilterContext *ctx, · 1352 unmodified lines
15531557 WIPEBR_TRANSITION(8, uint8_t, 1)
15541558 WIPEBR_TRANSITION(16, uint16_t, 2)
15551559
1560+#define SQUEEZEH_TRANSITION(name, type, div) \
1561+static void squeezeh##name##_transition(AVFilterContext *ctx, \
1562+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
1563+ float progress, \
1564+ int slice_start, int slice_end, int jobnr) \
1565+{ \
1566+ XFadeContext *s = ctx->priv; \
1567+ const float h = out->height; \
1568+ const int height = slice_end - slice_start; \
1569+ \
1570+ for (int p = 0; p < s->nb_planes; p++) { \
1571+ const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
1572+ type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
1573+ \
1574+ for (int y = 0; y < height; y++) { \
1575+ const float z = .5f + ((slice_start + y) / h - .5f) / progress; \
1576+ \
1577+ if (z < 0.f || z > 1.f) { \
1578+ for (int x = 0; x < out->width; x++) \
1579+ dst[x] = xf1[x]; \
1580+ } else { \
1581+ const int yy = lrintf(z * (h - 1.f)); \
1582+ const type *xf0 = (const type *)(a->data[p] + yy * a->linesize[p]); \
1583+ \
1584+ for (int x = 0; x < out->width; x++) \
1585+ dst[x] = xf0[x]; \
1586+ } \
1587+ \
1588+ dst += out->linesize[p] / div; \
1589+ xf1 += b->linesize[p] / div; \
1590+ } \
1591+ } \
1592+}
1593+
1594+SQUEEZEH_TRANSITION(8, uint8_t, 1)
1595+SQUEEZEH_TRANSITION(16, uint16_t, 2)
1596+
1597+#define SQUEEZEV_TRANSITION(name, type, div) \
1598+static void squeezev##name##_transition(AVFilterContext *ctx, \
1599+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
1600+ float progress, \
1601+ int slice_start, int slice_end, int jobnr) \
1602+{ \
1603+ XFadeContext *s = ctx->priv; \
1604+ const float w = out->width; \
1605+ const int height = slice_end - slice_start; \
1606+ \
1607+ for (int p = 0; p < s->nb_planes; p++) { \
1608+ const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
1609+ const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
1610+ type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
1611+ \
1612+ for (int y = 0; y < height; y++) { \
1613+ for (int x = 0; x < out->width; x++) { \
1614+ const float z = .5f + (x / w - .5f) / progress; \
1615+ \
1616+ if (z < 0.f || z > 1.f) { \
1617+ dst[x] = xf1[x]; \
1618+ } else { \
1619+ const int xx = lrintf(z * (w - 1.f)); \
1620+ \
1621+ dst[x] = xf0[xx]; \
1622+ } \
1623+ } \
1624+ \
1625+ dst += out->linesize[p] / div; \
1626+ xf0 += a->linesize[p] / div; \
1627+ xf1 += b->linesize[p] / div; \
1628+ } \
1629+ } \
1630+}
1631+
1632+SQUEEZEV_TRANSITION(8, uint8_t, 1)
1633+SQUEEZEV_TRANSITION(16, uint16_t, 2)
1634+
15561635 static inline double getpix(void *priv, double x, double y, int plane, int nb)
15571636 {
15581637 XFadeContext *s = priv;
@@ -1700,6 +1779,8 @@ static int config_output(AVFilterLink *outlink) · 141 unmodified lines
17001779 case WIPETR: s->transitionf = s->depth <= 8 ? wipetr8_transition : wipetr16_transition; break;
17011780 case WIPEBL: s->transitionf = s->depth <= 8 ? wipebl8_transition : wipebl16_transition; break;
17021781 case WIPEBR: s->transitionf = s->depth <= 8 ? wipebr8_transition : wipebr16_transition; break;
1782+ case SQUEEZEH: s->transitionf = s->depth <= 8 ? squeezeh8_transition : squeezeh16_transition; break;
1783+ case SQUEEZEV: s->transitionf = s->depth <= 8 ? squeezev8_transition : squeezev16_transition; break;
17031784 }
17041785
17051786 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