| @@ -67,11 +67,44 @@ static int query_formats(AVFilterContext *ctx) · 66 unmodified lines |
| 67 | return ff_set_common_formats(ctx, formats); | 67 | return ff_set_common_formats(ctx, formats); |
| 68 | } | 68 | } |
| 69 | | 69 | |
| 70 | static av_cold int init(AVFilterContext *ctx) | 70 | static int parse_weights(AVFilterContext *ctx) |
| 71 | { | 71 | { |
| 72 | MixContext *s = ctx->priv; | 72 | MixContext *s = ctx->priv; |
| 73 | char *p, *arg, *saveptr = NULL; | 73 | char *p, *arg, *saveptr = NULL; |
| 74 | int i, ret, last = 0; | 74 | int i, last = 0; |
| | 75 | |
| | 76 | s->wfactor = 0.f; |
| | 77 | p = s->weights_str; |
| | 78 | for (i = 0; i < s->nb_inputs; i++) { |
| | 79 | if (!(arg = av_strtok(p, " |", &saveptr))) |
| | 80 | break; |
| | 81 | |
| | 82 | p = NULL; |
| | 83 | if (av_sscanf(arg, "%f", &s->weights[i]) != 1) { |
| | 84 | av_log(ctx, AV_LOG_ERROR, "Invalid syntax for weights[%d].\n", i); |
| | 85 | return AVERROR(EINVAL); |
| | 86 | } |
| | 87 | s->wfactor += s->weights[i]; |
| | 88 | last = i; |
| | 89 | } |
| | 90 | |
| | 91 | for (; i < s->nb_inputs; i++) { |
| | 92 | s->weights[i] = s->weights[last]; |
| | 93 | s->wfactor += s->weights[i]; |
| | 94 | } |
| | 95 | if (s->scale == 0) { |
| | 96 | s->wfactor = 1 / s->wfactor; |
| | 97 | } else { |
| | 98 | s->wfactor = s->scale; |
| | 99 | } |
| | 100 | |
| | 101 | return 0; |
| | 102 | } |
| | 103 | |
| | 104 | static av_cold int init(AVFilterContext *ctx) |
| | 105 | { |
| | 106 | MixContext *s = ctx->priv; |
| | 107 | int ret; |
| 75 | | 108 | |
| 76 | s->tmix = !strcmp(ctx->filter->name, "tmix"); | 109 | s->tmix = !strcmp(ctx->filter->name, "tmix"); |
| 77 | | 110 | |
| @@ -84,7 +117,7 @@ static av_cold int init(AVFilterContext *ctx) · 6 unmodified lines |
| 84 | return AVERROR(ENOMEM); | 117 | return AVERROR(ENOMEM); |
| 85 | | 118 | |
| 86 | if (!s->tmix) { | 119 | if (!s->tmix) { |
| 87 | for (i = 0; i < s->nb_inputs; i++) { | 120 | for (int i = 0; i < s->nb_inputs; i++) { |
| 88 | AVFilterPad pad = { 0 }; | 121 | AVFilterPad pad = { 0 }; |
| 89 | | 122 | |
| 90 | pad.type = AVMEDIA_TYPE_VIDEO; | 123 | pad.type = AVMEDIA_TYPE_VIDEO; |
| @@ -99,30 +132,7 @@ static av_cold int init(AVFilterContext *ctx) · 8 unmodified lines |
| 99 | } | 132 | } |
| 100 | } | 133 | } |
| 101 | | 134 | |
| 102 | p = s->weights_str; | 135 | return parse_weights(ctx); |
| 103 | for (i = 0; i < s->nb_inputs; i++) { | | |
| 104 | if (!(arg = av_strtok(p, " ", &saveptr))) | | |
| 105 | break; | | |
| 106 | | | |
| 107 | p = NULL; | | |
| 108 | if (av_sscanf(arg, "%f", &s->weights[i]) != 1) { | | |
| 109 | av_log(ctx, AV_LOG_ERROR, "Invalid syntax for weights[%d].\n", i); | | |
| 110 | return AVERROR(EINVAL); | | |
| 111 | } | | |
| 112 | s->wfactor += s->weights[i]; | | |
| 113 | last = i; | | |
| 114 | } | | |
| 115 | for (; i < s->nb_inputs; i++) { | | |
| 116 | s->weights[i] = s->weights[last]; | | |
| 117 | s->wfactor += s->weights[i]; | | |
| 118 | } | | |
| 119 | if (s->scale == 0) { | | |
| 120 | s->wfactor = 1 / s->wfactor; | | |
| 121 | } else { | | |
| 122 | s->wfactor = s->scale; | | |
| 123 | } | | |
| 124 | | | |
| 125 | return 0; | | |
| 126 | } | 136 | } |
| 127 | | 137 | |
| 128 | typedef struct ThreadData { | 138 | typedef struct ThreadData { |
| @@ -303,6 +313,18 @@ static av_cold void uninit(AVFilterContext *ctx) · 174 unmodified lines |
| 303 | av_freep(&s->frames); | 313 | av_freep(&s->frames); |
| 304 | } | 314 | } |
| 305 | | 315 | |
| | 316 | static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, |
| | 317 | char *res, int res_len, int flags) |
| | 318 | { |
| | 319 | int ret; |
| | 320 | |
| | 321 | ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags); |
| | 322 | if (ret < 0) |
| | 323 | return ret; |
| | 324 | |
| | 325 | return parse_weights(ctx); |
| | 326 | } |
| | 327 | |
| 306 | static int activate(AVFilterContext *ctx) | 328 | static int activate(AVFilterContext *ctx) |
| 307 | { | 329 | { |
| 308 | MixContext *s = ctx->priv; | 330 | MixContext *s = ctx->priv; |
| @@ -311,11 +333,12 @@ static int activate(AVFilterContext *ctx) · 2 unmodified lines |
| 311 | | 333 | |
| 312 | #define OFFSET(x) offsetof(MixContext, x) | 334 | #define OFFSET(x) offsetof(MixContext, x) |
| 313 | #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | 335 | #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
| | 336 | #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM |
| 314 | | 337 | |
| 315 | static const AVOption mix_options[] = { | 338 | static const AVOption mix_options[] = { |
| 316 | { "inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=2}, 2, INT16_MAX, .flags = FLAGS }, | 339 | { "inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=2}, 2, INT16_MAX, .flags = FLAGS }, |
| 317 | { "weights", "set weight for each input", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, .flags = FLAGS }, | 340 | { "weights", "set weight for each input", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, .flags = TFLAGS }, |
| 318 | { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = FLAGS }, | 341 | { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = TFLAGS }, |
| 319 | { "duration", "how to determine end of stream", OFFSET(duration), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, .flags = FLAGS, "duration" }, | 342 | { "duration", "how to determine end of stream", OFFSET(duration), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, .flags = FLAGS, "duration" }, |
| 320 | { "longest", "Duration of longest input", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "duration" }, | 343 | { "longest", "Duration of longest input", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "duration" }, |
| 321 | { "shortest", "Duration of shortest input", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "duration" }, | 344 | { "shortest", "Duration of shortest input", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "duration" }, |
| @@ -347,6 +370,7 @@ AVFilter ff_vf_mix = { · 25 unmodified lines |
| 347 | .activate = activate, | 370 | .activate = activate, |
| 348 | .flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS | | 371 | .flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS | |
| 349 | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, | 372 | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, |
| | 373 | .process_command = process_command, |
| 350 | }; | 374 | }; |
| 351 | | 375 | |
| 352 | #endif /* CONFIG_MIX_FILTER */ | 376 | #endif /* CONFIG_MIX_FILTER */ |
| @@ -395,8 +419,8 @@ static int tmix_filter_frame(AVFilterLink *inlink, AVFrame *in) · 42 unmodified lines |
| 395 | | 419 | |
| 396 | static const AVOption tmix_options[] = { | 420 | static const AVOption tmix_options[] = { |
| 397 | { "frames", "set number of successive frames to mix", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=3}, 1, 128, .flags = FLAGS }, | 421 | { "frames", "set number of successive frames to mix", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=3}, 1, 128, .flags = FLAGS }, |
| 398 | { "weights", "set weight for each frame", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1 1"}, 0, 0, .flags = FLAGS }, | 422 | { "weights", "set weight for each frame", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1 1"}, 0, 0, .flags = TFLAGS }, |
| 399 | { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = FLAGS }, | 423 | { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = TFLAGS }, |
| 400 | { NULL }, | 424 | { NULL }, |
| 401 | }; | 425 | }; |
| 402 | | 426 | |
| @@ -422,6 +446,7 @@ AVFilter ff_vf_tmix = { · 19 unmodified lines |
| 422 | .init = init, | 446 | .init = init, |
| 423 | .uninit = uninit, | 447 | .uninit = uninit, |
| 424 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS, | 448 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS, |
| | 449 | .process_command = process_command, |
| 425 | }; | 450 | }; |
| 426 | | 451 | |
| 427 | #endif /* CONFIG_TMIX_FILTER */ | 452 | #endif /* CONFIG_TMIX_FILTER */ |