History

avfilter/vf_xfade: add cover transitions

Paul B Mahol committed 3 years ago

Commit 8fe25b11 parent 593e8c22 files · +84 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −0
  2. libavfilter/vf_xfade.c +80 −0
doc/filters.texi+4−0
@@ -25259,6 +25259,10 @@ Set one of available transition effects: · 25258 unmodified lines
2525925259 @item hrwind
2526025260 @item vuwind
2526125261 @item vdwind
25262+@item coverleft
25263+@item coverright
25264+@item coverup
25265+@item coverdown
2526225266 @end table
2526325267 Default transition effect is fade.
2526425268
libavfilter/vf_xfade.c+80−0
@@ -80,6 +80,10 @@ enum XFadeTransitions { · 79 unmodified lines
8080 HRWIND,
8181 VUWIND,
8282 VDWIND,
83+ COVERLEFT,
84+ COVERRIGHT,
85+ COVERUP,
86+ COVERDOWN,
8387 NB_TRANSITIONS,
8488 };
8589
@@ -214,6 +218,10 @@ static const AVOption xfade_options[] = { · 128 unmodified lines
214218 { "hrwind", "hr wind transition", 0, AV_OPT_TYPE_CONST, {.i64=HRWIND}, 0, 0, FLAGS, "transition" },
215219 { "vuwind", "vu wind transition", 0, AV_OPT_TYPE_CONST, {.i64=VUWIND}, 0, 0, FLAGS, "transition" },
216220 { "vdwind", "vd wind transition", 0, AV_OPT_TYPE_CONST, {.i64=VDWIND}, 0, 0, FLAGS, "transition" },
221+ { "coverleft", "cover left transition", 0, AV_OPT_TYPE_CONST, {.i64=COVERLEFT}, 0, 0, FLAGS, "transition" },
222+ { "coverright", "cover right transition", 0, AV_OPT_TYPE_CONST, {.i64=COVERRIGHT}, 0, 0, FLAGS, "transition" },
223+ { "coverup", "cover up transition", 0, AV_OPT_TYPE_CONST, {.i64=COVERUP}, 0, 0, FLAGS, "transition" },
224+ { "coverdown", "cover down transition", 0, AV_OPT_TYPE_CONST, {.i64=COVERDOWN}, 0, 0, FLAGS, "transition" },
217225 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
218226 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
219227 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -1851,6 +1859,74 @@ VWIND_TRANSITION(16, u, uint16_t, 2, 1.f - ) · 1631 unmodified lines
18511859 VWIND_TRANSITION(8, d, uint8_t, 1, )
18521860 VWIND_TRANSITION(16, d, uint16_t, 2, )
18531861
1862+#define COVERH_TRANSITION(dir, name, type, div, expr) \
1863+static void cover##dir##name##_transition(AVFilterContext *ctx, \
1864+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
1865+ float progress, \
1866+ int slice_start, int slice_end, int jobnr) \
1867+{ \
1868+ XFadeContext *s = ctx->priv; \
1869+ const int height = slice_end - slice_start; \
1870+ const int width = out->width; \
1871+ const int z = (expr progress) * width; \
1872+ \
1873+ for (int p = 0; p < s->nb_planes; p++) { \
1874+ const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
1875+ const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
1876+ type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
1877+ \
1878+ for (int y = 0; y < height; y++) { \
1879+ for (int x = 0; x < width; x++) { \
1880+ const int zx = z + x; \
1881+ const int zz = zx % width + width * (zx < 0); \
1882+ dst[x] = (zx >= 0) && (zx < width) ? xf1[zz] : xf0[x]; \
1883+ } \
1884+ \
1885+ dst += out->linesize[p] / div; \
1886+ xf0 += a->linesize[p] / div; \
1887+ xf1 += b->linesize[p] / div; \
1888+ } \
1889+ } \
1890+}
1891+
1892+COVERH_TRANSITION(left, 8, uint8_t, 1, -)
1893+COVERH_TRANSITION(left, 16, uint16_t, 2, -)
1894+COVERH_TRANSITION(right, 8, uint8_t, 1, )
1895+COVERH_TRANSITION(right, 16, uint16_t, 2, )
1896+
1897+#define COVERV_TRANSITION(dir, name, type, div, expr) \
1898+static void cover##dir##name##_transition(AVFilterContext *ctx, \
1899+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
1900+ float progress, \
1901+ int slice_start, int slice_end, int jobnr) \
1902+{ \
1903+ XFadeContext *s = ctx->priv; \
1904+ const int height = out->height; \
1905+ const int width = out->width; \
1906+ const int z = (expr progress) * height; \
1907+ \
1908+ for (int p = 0; p < s->nb_planes; p++) { \
1909+ type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
1910+ \
1911+ for (int y = slice_start; y < slice_end; y++) { \
1912+ const int zy = z + y; \
1913+ const int zz = zy % height + height * (zy < 0); \
1914+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
1915+ const type *xf1 = (const type *)(b->data[p] + zz * b->linesize[p]); \
1916+ \
1917+ for (int x = 0; x < width; x++) \
1918+ dst[x] = (zy >= 0) && (zy < height) ? xf1[x] : xf0[x]; \
1919+ \
1920+ dst += out->linesize[p] / div; \
1921+ } \
1922+ } \
1923+}
1924+
1925+COVERV_TRANSITION(up, 8, uint8_t, 1, -)
1926+COVERV_TRANSITION(up, 16, uint16_t, 2, -)
1927+COVERV_TRANSITION(down, 8, uint8_t, 1, )
1928+COVERV_TRANSITION(down, 16, uint16_t, 2, )
1929+
18541930 static inline double getpix(void *priv, double x, double y, int plane, int nb)
18551931 {
18561932 XFadeContext *s = priv;
@@ -2001,6 +2077,10 @@ static int config_output(AVFilterLink *outlink) · 144 unmodified lines
20012077 case HRWIND: s->transitionf = s->depth <= 8 ? hrwind8_transition : hrwind16_transition; break;
20022078 case VUWIND: s->transitionf = s->depth <= 8 ? vuwind8_transition : vuwind16_transition; break;
20032079 case VDWIND: s->transitionf = s->depth <= 8 ? vdwind8_transition : vdwind16_transition; break;
2080+ case COVERLEFT: s->transitionf = s->depth <= 8 ? coverleft8_transition : coverleft16_transition; break;
2081+ case COVERRIGHT: s->transitionf = s->depth <= 8 ? coverright8_transition : coverright16_transition; break;
2082+ case COVERUP: s->transitionf = s->depth <= 8 ? coverup8_transition : coverup16_transition; break;
2083+ case COVERDOWN: s->transitionf = s->depth <= 8 ? coverdown8_transition : coverdown16_transition; break;
20042084 default: return AVERROR_BUG;
20052085 }
20062086

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