| @@ -53,6 +53,8 @@ enum XFadeTransitions { · 52 unmodified lines |
| 53 | CIRCLECLOSE, | 53 | CIRCLECLOSE, |
| 54 | VERTOPEN, | 54 | VERTOPEN, |
| 55 | VERTCLOSE, | 55 | VERTCLOSE, |
| | 56 | HORZOPEN, |
| | 57 | HORZCLOSE, |
| 56 | NB_TRANSITIONS, | 58 | NB_TRANSITIONS, |
| 57 | }; | 59 | }; |
| 58 | | 60 | |
| @@ -158,6 +160,8 @@ static const AVOption xfade_options[] = { · 99 unmodified lines |
| 158 | { "circleclose","circleclose transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLECLOSE},0, 0, FLAGS, "transition" }, | 160 | { "circleclose","circleclose transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLECLOSE},0, 0, FLAGS, "transition" }, |
| 159 | { "vertopen", "vert open transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTOPEN}, 0, 0, FLAGS, "transition" }, | 161 | { "vertopen", "vert open transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTOPEN}, 0, 0, FLAGS, "transition" }, |
| 160 | { "vertclose", "vert close transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTCLOSE}, 0, 0, FLAGS, "transition" }, | 162 | { "vertclose", "vert close transition", 0, AV_OPT_TYPE_CONST, {.i64=VERTCLOSE}, 0, 0, FLAGS, "transition" }, |
| | 163 | { "horzopen", "horz open transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZOPEN}, 0, 0, FLAGS, "transition" }, |
| | 164 | { "horzclose", "horz close transition", 0, AV_OPT_TYPE_CONST, {.i64=HORZCLOSE}, 0, 0, FLAGS, "transition" }, |
| 161 | { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS }, | 165 | { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS }, |
| 162 | { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS }, | 166 | { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS }, |
| 163 | { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, | 167 | { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, |
| @@ -916,6 +920,60 @@ static void vertclose##name##_transition(AVFilterContext *ctx, · 752 unmodified lines |
| 916 | VERTCLOSE_TRANSITION(8, uint8_t, 1) | 920 | VERTCLOSE_TRANSITION(8, uint8_t, 1) |
| 917 | VERTCLOSE_TRANSITION(16, uint16_t, 2) | 921 | VERTCLOSE_TRANSITION(16, uint16_t, 2) |
| 918 | | 922 | |
| | 923 | #define HORZOPEN_TRANSITION(name, type, div) \ |
| | 924 | static void horzopen##name##_transition(AVFilterContext *ctx, \ |
| | 925 | const AVFrame *a, const AVFrame *b, AVFrame *out, \ |
| | 926 | float progress, \ |
| | 927 | int slice_start, int slice_end, int jobnr) \ |
| | 928 | { \ |
| | 929 | XFadeContext *s = ctx->priv; \ |
| | 930 | const int width = out->width; \ |
| | 931 | const float h2 = out->height / 2; \ |
| | 932 | \ |
| | 933 | for (int y = slice_start; y < slice_end; y++) { \ |
| | 934 | const float smooth = 2.f - fabsf((y - h2) / h2) - progress * 2.f; \ |
| | 935 | for (int x = 0; x < width; x++) { \ |
| | 936 | for (int p = 0; p < s->nb_planes; p++) { \ |
| | 937 | const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \ |
| | 938 | const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \ |
| | 939 | type *dst = (type *)(out->data[p] + y * out->linesize[p]); \ |
| | 940 | \ |
| | 941 | dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \ |
| | 942 | } \ |
| | 943 | } \ |
| | 944 | } \ |
| | 945 | } |
| | 946 | |
| | 947 | HORZOPEN_TRANSITION(8, uint8_t, 1) |
| | 948 | HORZOPEN_TRANSITION(16, uint16_t, 2) |
| | 949 | |
| | 950 | #define HORZCLOSE_TRANSITION(name, type, div) \ |
| | 951 | static void horzclose##name##_transition(AVFilterContext *ctx, \ |
| | 952 | const AVFrame *a, const AVFrame *b, AVFrame *out, \ |
| | 953 | float progress, \ |
| | 954 | int slice_start, int slice_end, int jobnr) \ |
| | 955 | { \ |
| | 956 | XFadeContext *s = ctx->priv; \ |
| | 957 | const int width = out->width; \ |
| | 958 | const float h2 = out->height / 2; \ |
| | 959 | \ |
| | 960 | for (int y = slice_start; y < slice_end; y++) { \ |
| | 961 | const float smooth = 1.f + fabsf((y - h2) / h2) - progress * 2.f; \ |
| | 962 | for (int x = 0; x < width; x++) { \ |
| | 963 | for (int p = 0; p < s->nb_planes; p++) { \ |
| | 964 | const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \ |
| | 965 | const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \ |
| | 966 | type *dst = (type *)(out->data[p] + y * out->linesize[p]); \ |
| | 967 | \ |
| | 968 | dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \ |
| | 969 | } \ |
| | 970 | } \ |
| | 971 | } \ |
| | 972 | } |
| | 973 | |
| | 974 | HORZCLOSE_TRANSITION(8, uint8_t, 1) |
| | 975 | HORZCLOSE_TRANSITION(16, uint16_t, 2) |
| | 976 | |
| 919 | static inline double getpix(void *priv, double x, double y, int plane, int nb) | 977 | static inline double getpix(void *priv, double x, double y, int plane, int nb) |
| 920 | { | 978 | { |
| 921 | XFadeContext *s = priv; | 979 | XFadeContext *s = priv; |
| @@ -1030,6 +1088,8 @@ static int config_output(AVFilterLink *outlink) · 108 unmodified lines |
| 1030 | case CIRCLECLOSE:s->transitionf = s->depth <= 8 ? circleclose8_transition: circleclose16_transition;break; | 1088 | case CIRCLECLOSE:s->transitionf = s->depth <= 8 ? circleclose8_transition: circleclose16_transition;break; |
| 1031 | case VERTOPEN: s->transitionf = s->depth <= 8 ? vertopen8_transition : vertopen16_transition; break; | 1089 | case VERTOPEN: s->transitionf = s->depth <= 8 ? vertopen8_transition : vertopen16_transition; break; |
| 1032 | case VERTCLOSE: s->transitionf = s->depth <= 8 ? vertclose8_transition : vertclose16_transition; break; | 1090 | case VERTCLOSE: s->transitionf = s->depth <= 8 ? vertclose8_transition : vertclose16_transition; break; |
| | 1091 | case HORZOPEN: s->transitionf = s->depth <= 8 ? horzopen8_transition : horzopen16_transition; break; |
| | 1092 | case HORZCLOSE: s->transitionf = s->depth <= 8 ? horzclose8_transition : horzclose16_transition; break; |
| 1033 | } | 1093 | } |
| 1034 | | 1094 | |
| 1035 | if (s->transition == CUSTOM) { | 1095 | if (s->transition == CUSTOM) { |