History

avfilter/vf_xfade: add smooth transitions

Paul B Mahol committed 6 years ago

Commit 53b41281 parent 113bae52 files · +126 −0Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_xfade.c+122−0
@@ -46,6 +46,10 @@ enum XFadeTransitions { · 45 unmodified lines
4646 FADEBLACK,
4747 FADEWHITE,
4848 RADIAL,
49+ SMOOTHLEFT,
50+ SMOOTHRIGHT,
51+ SMOOTHUP,
52+ SMOOTHDOWN,
4953 NB_TRANSITIONS,
5054 };
5155
@@ -143,6 +147,10 @@ static const AVOption xfade_options[] = { · 91 unmodified lines
143147 { "fadeblack", "fadeblack transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEBLACK}, 0, 0, FLAGS, "transition" },
144148 { "fadewhite", "fadewhite transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEWHITE}, 0, 0, FLAGS, "transition" },
145149 { "radial", "radial transition", 0, AV_OPT_TYPE_CONST, {.i64=RADIAL}, 0, 0, FLAGS, "transition" },
150+ { "smoothleft", "smoothleft transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHLEFT}, 0, 0, FLAGS, "transition" },
151+ { "smoothright","smoothright transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHRIGHT},0, 0, FLAGS, "transition" },
152+ { "smoothup", "smoothup transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHUP}, 0, 0, FLAGS, "transition" },
153+ { "smoothdown", "smoothdown transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHDOWN}, 0, 0, FLAGS, "transition" },
146154 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
147155 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
148156 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -679,6 +687,116 @@ static void radial##name##_transition(AVFilterContext *ctx, · 530 unmodified lines
679687 RADIAL_TRANSITION(8, uint8_t, 1)
680688 RADIAL_TRANSITION(16, uint16_t, 2)
681689
690+#define SMOOTHLEFT_TRANSITION(name, type, div) \
691+static void smoothleft##name##_transition(AVFilterContext *ctx, \
692+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
693+ float progress, \
694+ int slice_start, int slice_end, int jobnr) \
695+{ \
696+ XFadeContext *s = ctx->priv; \
697+ const int width = out->width; \
698+ const float w = width; \
699+ \
700+ for (int y = slice_start; y < slice_end; y++) { \
701+ for (int x = 0; x < width; x++) { \
702+ const float smooth = 1.f + x / w - progress * 2.f; \
703+ \
704+ for (int p = 0; p < s->nb_planes; p++) { \
705+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
706+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
707+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
708+ \
709+ dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
710+ } \
711+ } \
712+ } \
713+}
714+
715+SMOOTHLEFT_TRANSITION(8, uint8_t, 1)
716+SMOOTHLEFT_TRANSITION(16, uint16_t, 2)
717+
718+#define SMOOTHRIGHT_TRANSITION(name, type, div) \
719+static void smoothright##name##_transition(AVFilterContext *ctx, \
720+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
721+ float progress, \
722+ int slice_start, int slice_end, int jobnr) \
723+{ \
724+ XFadeContext *s = ctx->priv; \
725+ const int width = out->width; \
726+ const float w = width; \
727+ \
728+ for (int y = slice_start; y < slice_end; y++) { \
729+ for (int x = 0; x < width; x++) { \
730+ const float smooth = 1.f + (w - 1 - x) / w - progress * 2.f; \
731+ \
732+ for (int p = 0; p < s->nb_planes; p++) { \
733+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
734+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
735+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
736+ \
737+ dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
738+ } \
739+ } \
740+ } \
741+}
742+
743+SMOOTHRIGHT_TRANSITION(8, uint8_t, 1)
744+SMOOTHRIGHT_TRANSITION(16, uint16_t, 2)
745+
746+#define SMOOTHUP_TRANSITION(name, type, div) \
747+static void smoothup##name##_transition(AVFilterContext *ctx, \
748+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
749+ float progress, \
750+ int slice_start, int slice_end, int jobnr) \
751+{ \
752+ XFadeContext *s = ctx->priv; \
753+ const int width = out->width; \
754+ const float h = out->height; \
755+ \
756+ for (int y = slice_start; y < slice_end; y++) { \
757+ const float smooth = 1.f + y / h - progress * 2.f; \
758+ for (int x = 0; x < width; x++) { \
759+ for (int p = 0; p < s->nb_planes; p++) { \
760+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
761+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
762+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
763+ \
764+ dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
765+ } \
766+ } \
767+ } \
768+}
769+
770+SMOOTHUP_TRANSITION(8, uint8_t, 1)
771+SMOOTHUP_TRANSITION(16, uint16_t, 2)
772+
773+#define SMOOTHDOWN_TRANSITION(name, type, div) \
774+static void smoothdown##name##_transition(AVFilterContext *ctx, \
775+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
776+ float progress, \
777+ int slice_start, int slice_end, int jobnr) \
778+{ \
779+ XFadeContext *s = ctx->priv; \
780+ const int width = out->width; \
781+ const float h = out->height; \
782+ \
783+ for (int y = slice_start; y < slice_end; y++) { \
784+ const float smooth = 1.f + (h - 1 - y) / h - progress * 2.f; \
785+ for (int x = 0; x < width; x++) { \
786+ for (int p = 0; p < s->nb_planes; p++) { \
787+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
788+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
789+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
790+ \
791+ dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
792+ } \
793+ } \
794+ } \
795+}
796+
797+SMOOTHDOWN_TRANSITION(8, uint8_t, 1)
798+SMOOTHDOWN_TRANSITION(16, uint16_t, 2)
799+
682800 static inline double getpix(void *priv, double x, double y, int plane, int nb)
683801 {
684802 XFadeContext *s = priv;
@@ -785,6 +903,10 @@ static int config_output(AVFilterLink *outlink) · 100 unmodified lines
785903 case FADEBLACK: s->transitionf = s->depth <= 8 ? fadeblack8_transition : fadeblack16_transition; break;
786904 case FADEWHITE: s->transitionf = s->depth <= 8 ? fadewhite8_transition : fadewhite16_transition; break;
787905 case RADIAL: s->transitionf = s->depth <= 8 ? radial8_transition : radial16_transition; break;
906+ case SMOOTHLEFT: s->transitionf = s->depth <= 8 ? smoothleft8_transition : smoothleft16_transition; break;
907+ case SMOOTHRIGHT:s->transitionf = s->depth <= 8 ? smoothright8_transition: smoothright16_transition;break;
908+ case SMOOTHUP: s->transitionf = s->depth <= 8 ? smoothup8_transition : smoothup16_transition; break;
909+ case SMOOTHDOWN: s->transitionf = s->depth <= 8 ? smoothdown8_transition : smoothdown16_transition; break;
788910 }
789911
790912 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