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
25259@item hrwind25259@item hrwind
25260@item vuwind25260@item vuwind
25261@item vdwind25261@item vdwind
25262@item coverleft
25263@item coverright
25264@item coverup
25265@item coverdown
25262@end table25266@end table
25263Default transition effect is fade.25267Default transition effect is fade.
25264 25268
libavfilter/vf_xfade.c+80−0
@@ -80,6 +80,10 @@ enum XFadeTransitions { · 79 unmodified lines
80 HRWIND,80 HRWIND,
81 VUWIND,81 VUWIND,
82 VDWIND,82 VDWIND,
83 COVERLEFT,
84 COVERRIGHT,
85 COVERUP,
86 COVERDOWN,
83 NB_TRANSITIONS,87 NB_TRANSITIONS,
84};88};
85 89
@@ -214,6 +218,10 @@ static const AVOption xfade_options[] = { · 128 unmodified lines
214 { "hrwind", "hr wind transition", 0, AV_OPT_TYPE_CONST, {.i64=HRWIND}, 0, 0, FLAGS, "transition" },218 { "hrwind", "hr wind transition", 0, AV_OPT_TYPE_CONST, {.i64=HRWIND}, 0, 0, FLAGS, "transition" },
215 { "vuwind", "vu wind transition", 0, AV_OPT_TYPE_CONST, {.i64=VUWIND}, 0, 0, FLAGS, "transition" },219 { "vuwind", "vu wind transition", 0, AV_OPT_TYPE_CONST, {.i64=VUWIND}, 0, 0, FLAGS, "transition" },
216 { "vdwind", "vd wind transition", 0, AV_OPT_TYPE_CONST, {.i64=VDWIND}, 0, 0, FLAGS, "transition" },220 { "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" },
217 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },225 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
218 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },226 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
219 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },227 { "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
1851VWIND_TRANSITION(8, d, uint8_t, 1, )1859VWIND_TRANSITION(8, d, uint8_t, 1, )
1852VWIND_TRANSITION(16, d, uint16_t, 2, )1860VWIND_TRANSITION(16, d, uint16_t, 2, )
1853 1861
1862#define COVERH_TRANSITION(dir, name, type, div, expr) \
1863static 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
1892COVERH_TRANSITION(left, 8, uint8_t, 1, -)
1893COVERH_TRANSITION(left, 16, uint16_t, 2, -)
1894COVERH_TRANSITION(right, 8, uint8_t, 1, )
1895COVERH_TRANSITION(right, 16, uint16_t, 2, )
1896
1897#define COVERV_TRANSITION(dir, name, type, div, expr) \
1898static 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
1925COVERV_TRANSITION(up, 8, uint8_t, 1, -)
1926COVERV_TRANSITION(up, 16, uint16_t, 2, -)
1927COVERV_TRANSITION(down, 8, uint8_t, 1, )
1928COVERV_TRANSITION(down, 16, uint16_t, 2, )
1929
1854static inline double getpix(void *priv, double x, double y, int plane, int nb)1930static inline double getpix(void *priv, double x, double y, int plane, int nb)
1855{1931{
1856 XFadeContext *s = priv;1932 XFadeContext *s = priv;
@@ -2001,6 +2077,10 @@ static int config_output(AVFilterLink *outlink) · 144 unmodified lines
2001 case HRWIND: s->transitionf = s->depth <= 8 ? hrwind8_transition : hrwind16_transition; break;2077 case HRWIND: s->transitionf = s->depth <= 8 ? hrwind8_transition : hrwind16_transition; break;
2002 case VUWIND: s->transitionf = s->depth <= 8 ? vuwind8_transition : vuwind16_transition; break;2078 case VUWIND: s->transitionf = s->depth <= 8 ? vuwind8_transition : vuwind16_transition; break;
2003 case VDWIND: s->transitionf = s->depth <= 8 ? vdwind8_transition : vdwind16_transition; break;2079 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;
2004 default: return AVERROR_BUG;2084 default: return AVERROR_BUG;
2005 }2085 }
2006 2086

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