* commit '5aa1a668cfae7f617e1a06efad20f87283badd8a': vf_frei0r: switch to an AVOptions-based system. Conflicts: doc/filters.texi libavfilter/vf_frei0r.c
Unified · Split
| @@ -3251,21 +3251,22 @@ Apply a frei0r effect to the input video. · 3250 unmodified lines | |||
| 3251 | To enable compilation of this filter you need to install the frei0r | 3251 | To enable compilation of this filter you need to install the frei0r |
| 3252 | header and configure FFmpeg with @code{--enable-frei0r}. | 3252 | header and configure FFmpeg with @code{--enable-frei0r}. |
| 3253 | 3253 | ||
| 3254 | The filter supports the syntax: | 3254 | This filter accepts the following options: |
| 3255 | @example | 3255 | |
| 3256 | @var{filter_name}[@{:|=@}@var{param1}:@var{param2}:...:@var{paramN}] | 3256 | @table @option |
| 3257 | @end example | ||
| 3258 | 3257 | ||
| 3259 | @var{filter_name} is the name of the frei0r effect to load. If the | 3258 | @item filter_name |
| 3260 | environment variable @env{FREI0R_PATH} is defined, the frei0r effect | 3259 | The name to the frei0r effect to load. If the environment variable |
| 3261 | is searched in each one of the directories specified by the colon (or | 3260 | @env{FREI0R_PATH} is defined, the frei0r effect is searched in each one of the |
| 3262 | semicolon on Windows platforms) separated list in @env{FREIOR_PATH}, | 3261 | directories specified by the colon separated list in @env{FREIOR_PATH}, |
| 3263 | otherwise in the standard frei0r paths, which are in this order: | 3262 | otherwise in the standard frei0r paths, which are in this order: |
| 3264 | @file{HOME/.frei0r-1/lib/}, @file{/usr/local/lib/frei0r-1/}, | 3263 | @file{HOME/.frei0r-1/lib/}, @file{/usr/local/lib/frei0r-1/}, |
| 3265 | @file{/usr/lib/frei0r-1/}. | 3264 | @file{/usr/lib/frei0r-1/}. |
| 3266 | 3265 | ||
| 3267 | @var{param1}, @var{param2}, ... , @var{paramN} specify the parameters | 3266 | @item filter_params |
| 3268 | for the frei0r effect. | 3267 | A '|'-separated list of parameters to pass to the frei0r effect. |
| 3268 | |||
| 3269 | @end table | ||
| 3269 | 3270 | ||
| 3270 | A frei0r effect parameter can be a boolean (whose values are specified | 3271 | A frei0r effect parameter can be a boolean (whose values are specified |
| 3271 | with "y" and "n"), a double, a color (specified by the syntax | 3272 | with "y" and "n"), a double, a color (specified by the syntax |
| @@ -3283,7 +3284,7 @@ effect parameter is not specified the default value is set. · 11 unmodified lines | |||
| 3283 | @item | 3284 | @item |
| 3284 | Apply the distort0r effect, set the first two double parameters: | 3285 | Apply the distort0r effect, set the first two double parameters: |
| 3285 | @example | 3286 | @example |
| 3286 | frei0r=distort0r:0.5:0.01 | 3287 | frei0r=filter_name=distort0r:filter_params=0.5|0.01 |
| 3287 | @end example | 3288 | @end example |
| 3288 | 3289 | ||
| 3289 | @item | 3290 | @item |
| @@ -3298,7 +3299,7 @@ frei0r=colordistance:0x112233 · 8 unmodified lines | |||
| 3298 | Apply the perspective effect, specify the top left and top right image | 3299 | Apply the perspective effect, specify the top left and top right image |
| 3299 | positions: | 3300 | positions: |
| 3300 | @example | 3301 | @example |
| 3301 | frei0r=perspective:0.2/0.2:0.8/0.2 | 3302 | frei0r=perspective:0.2/0.2|0.8/0.2 |
| 3302 | @end example | 3303 | @end example |
| 3303 | @end itemize | 3304 | @end itemize |
| 3304 | 3305 | ||
| @@ -6074,23 +6075,32 @@ Provide a frei0r source. · 2769 unmodified lines | |||
| 6074 | To enable compilation of this filter you need to install the frei0r | 6075 | To enable compilation of this filter you need to install the frei0r |
| 6075 | header and configure FFmpeg with @code{--enable-frei0r}. | 6076 | header and configure FFmpeg with @code{--enable-frei0r}. |
| 6076 | 6077 | ||
| 6077 | The source supports the syntax: | 6078 | This source accepts the following options: |
| 6078 | @example | ||
| 6079 | @var{size}:@var{rate}:@var{src_name}[@{=|:@}@var{param1}:@var{param2}:...:@var{paramN}] | ||
| 6080 | @end example | ||
| 6081 | 6079 | ||
| 6082 | @var{size} is the size of the video to generate, may be a string of the | 6080 | @table @option |
| 6083 | form @var{width}x@var{height} or a frame size abbreviation. | 6081 | |
| 6084 | @var{rate} is the rate of the video to generate, may be a string of | 6082 | @item size |
| 6085 | the form @var{num}/@var{den} or a frame rate abbreviation. | 6083 | The size of the video to generate, may be a string of the form |
| 6086 | @var{src_name} is the name to the frei0r source to load. For more | 6084 | @var{width}x@var{height} or a frame size abbreviation. |
| 6087 | information regarding frei0r and how to set the parameters read the | 6085 | |
| 6088 | section @ref{frei0r} in the description of the video filters. | 6086 | @item framerate |
| 6087 | Framerate of the generated video, may be a string of the form | ||
| 6088 | @var{num}/@var{den} or a frame rate abbreviation. | ||
| 6089 | |||
| 6090 | @item filter_name | ||
| 6091 | The name to the frei0r source to load. For more information regarding frei0r and | ||
| 6092 | how to set the parameters read the section @ref{frei0r} in the description of | ||
| 6093 | the video filters. | ||
| 6094 | |||
| 6095 | @item filter_params | ||
| 6096 | A '|'-separated list of parameters to pass to the frei0r source. | ||
| 6097 | |||
| 6098 | @end table | ||
| 6089 | 6099 | ||
| 6090 | For example, to generate a frei0r partik0l source with size 200x200 | 6100 | For example, to generate a frei0r partik0l source with size 200x200 |
| 6091 | and frame rate 10 which is overlayed on the overlay filter main input: | 6101 | and frame rate 10 which is overlayed on the overlay filter main input: |
| 6092 | @example | 6102 | @example |
| 6093 | frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay | 6103 | frei0r_src=size=200x200:framerate=10:filter_name=partik0l:filter_params=1234 [overlay]; [in][overlay] overlay |
| 6094 | @end example | 6104 | @end example |
| 6095 | 6105 | ||
| 6096 | @section life | 6106 | @section life |
| @@ -667,6 +667,8 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 666 unmodified lines | |||
| 667 | !strcmp(filter->filter->name, "fade" ) || | 667 | !strcmp(filter->filter->name, "fade" ) || |
| 668 | !strcmp(filter->filter->name, "fieldorder") || | 668 | !strcmp(filter->filter->name, "fieldorder") || |
| 669 | !strcmp(filter->filter->name, "fps" ) || | 669 | !strcmp(filter->filter->name, "fps" ) || |
| 670 | !strcmp(filter->filter->name, "frei0r" ) || | ||
| 671 | !strcmp(filter->filter->name, "frei0r_src") || | ||
| 670 | !strcmp(filter->filter->name, "format") || | 672 | !strcmp(filter->filter->name, "format") || |
| 671 | !strcmp(filter->filter->name, "noformat") || | 673 | !strcmp(filter->filter->name, "noformat") || |
| 672 | !strcmp(filter->filter->name, "resample") | 674 | !strcmp(filter->filter->name, "resample") |
| @@ -691,19 +693,36 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 18 unmodified lines | |||
| 691 | if (ret < 0) | 693 | if (ret < 0) |
| 692 | goto fail; | 694 | goto fail; |
| 693 | #if FF_API_OLD_FILTER_OPTS | 695 | #if FF_API_OLD_FILTER_OPTS |
| 694 | } else if (!strcmp(filter->filter->name, "format") || | 696 | } else if (!strcmp(filter->filter->name, "format") || |
| 695 | !strcmp(filter->filter->name, "noformat")) { | 697 | !strcmp(filter->filter->name, "noformat") || |
| 698 | !strcmp(filter->filter->name, "frei0r") || | ||
| 699 | !strcmp(filter->filter->name, "frei0r_src")) { | ||
| 696 | /* a hack for compatibility with the old syntax | 700 | /* a hack for compatibility with the old syntax |
| 697 | * replace colons with |s */ | 701 | * replace colons with |s */ |
| 698 | char *copy = av_strdup(args); | 702 | char *copy = av_strdup(args); |
| 699 | char *p = copy; | 703 | char *p = copy; |
| 704 | int nb_leading = 0; // number of leading colons to skip | ||
| 700 | 705 | ||
| 701 | if (!copy) { | 706 | if (!copy) { |
| 702 | ret = AVERROR(ENOMEM); | 707 | ret = AVERROR(ENOMEM); |
| 703 | goto fail; | 708 | goto fail; |
| 704 | } | 709 | } |
| 705 | 710 | ||
| 706 | if (strchr(copy, ':')) { | 711 | if (!strcmp(filter->filter->name, "frei0r")) |
| 712 | nb_leading = 1; | ||
| 713 | else if (!strcmp(filter->filter->name, "frei0r_src")) | ||
| 714 | nb_leading = 3; | ||
| 715 | |||
| 716 | while (nb_leading--) { | ||
| 717 | p = strchr(p, ':'); | ||
| 718 | if (!p) { | ||
| 719 | p = copy + strlen(copy); | ||
| 720 | break; | ||
| 721 | } | ||
| 722 | p++; | ||
| 723 | } | ||
| 724 | |||
| 725 | if (strchr(p, ':')) { | ||
| 707 | av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use " | 726 | av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use " |
| 708 | "'|' to separate the list items.\n"); | 727 | "'|' to separate the list items.\n"); |
| 709 | } | 728 | } |
| @@ -35,6 +35,7 @@ · 34 unmodified lines | |||
| 35 | #include "libavutil/internal.h" | 35 | #include "libavutil/internal.h" |
| 36 | #include "libavutil/mathematics.h" | 36 | #include "libavutil/mathematics.h" |
| 37 | #include "libavutil/mem.h" | 37 | #include "libavutil/mem.h" |
| 38 | #include "libavutil/opt.h" | ||
| 38 | #include "libavutil/parseutils.h" | 39 | #include "libavutil/parseutils.h" |
| 39 | #include "avfilter.h" | 40 | #include "avfilter.h" |
| 40 | #include "formats.h" | 41 | #include "formats.h" |
| @@ -53,6 +54,7 @@ typedef void (*f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param · 12 unmodified lines | |||
| 53 | typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index); | 54 | typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index); |
| 54 | 55 | ||
| 55 | typedef struct Frei0rContext { | 56 | typedef struct Frei0rContext { |
| 57 | const AVClass *class; | ||
| 56 | f0r_update_f update; | 58 | f0r_update_f update; |
| 57 | void *dl_handle; /* dynamic library handle */ | 59 | void *dl_handle; /* dynamic library handle */ |
| 58 | f0r_instance_t instance; | 60 | f0r_instance_t instance; |
| @@ -64,7 +66,11 @@ typedef struct Frei0rContext { · 5 unmodified lines | |||
| 64 | f0r_construct_f construct; | 66 | f0r_construct_f construct; |
| 65 | f0r_destruct_f destruct; | 67 | f0r_destruct_f destruct; |
| 66 | f0r_deinit_f deinit; | 68 | f0r_deinit_f deinit; |
| 67 | char params[256]; | 69 | |
| 70 | char *dl_name; | ||
| 71 | char *params; | ||
| 72 | char *size; | ||
| 73 | char *framerate; | ||
| 68 | 74 | ||
| 69 | /* only used by the source */ | 75 | /* only used by the source */ |
| 70 | int w, h; | 76 | int w, h; |
| @@ -143,7 +149,7 @@ static int set_params(AVFilterContext *ctx, const char *params) · 72 unmodified lines | |||
| 143 | frei0r->get_param_info(&info, i); | 149 | frei0r->get_param_info(&info, i); |
| 144 | 150 | ||
| 145 | if (*params) { | 151 | if (*params) { |
| 146 | if (!(param = av_get_token(¶ms, ":"))) | 152 | if (!(param = av_get_token(¶ms, "|"))) |
| 147 | return AVERROR(ENOMEM); | 153 | return AVERROR(ENOMEM); |
| 148 | params++; /* skip ':' */ | 154 | params++; /* skip ':' */ |
| 149 | ret = set_param(ctx, info, i, param); | 155 | ret = set_param(ctx, info, i, param); |
| @@ -225,6 +231,11 @@ static av_cold int frei0r_init(AVFilterContext *ctx, · 75 unmodified lines | |||
| 225 | char *path; | 231 | char *path; |
| 226 | int ret = 0; | 232 | int ret = 0; |
| 227 | 233 | ||
| 234 | if (!dl_name) { | ||
| 235 | av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n"); | ||
| 236 | return AVERROR(EINVAL); | ||
| 237 | } | ||
| 238 | |||
| 228 | /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */ | 239 | /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */ |
| 229 | if ((path = av_strdup(getenv("FREI0R_PATH")))) { | 240 | if ((path = av_strdup(getenv("FREI0R_PATH")))) { |
| 230 | #ifdef _WIN32 | 241 | #ifdef _WIN32 |
| @@ -320,13 +331,8 @@ static av_cold int frei0r_init(AVFilterContext *ctx, · 89 unmodified lines | |||
| 320 | static av_cold int filter_init(AVFilterContext *ctx, const char *args) | 331 | static av_cold int filter_init(AVFilterContext *ctx, const char *args) |
| 321 | { | 332 | { |
| 322 | Frei0rContext *frei0r = ctx->priv; | 333 | Frei0rContext *frei0r = ctx->priv; |
| 323 | char dl_name[1024], c; | ||
| 324 | *frei0r->params = 0; | ||
| 325 | 334 | ||
| 326 | if (args) | 335 | return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_FILTER); |
| 327 | sscanf(args, "%1023[^:=]%c%255c", dl_name, &c, frei0r->params); | ||
| 328 | |||
| 329 | return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_FILTER); | ||
| 330 | } | 336 | } |
| 331 | 337 | ||
| 332 | static av_cold void uninit(AVFilterContext *ctx) | 338 | static av_cold void uninit(AVFilterContext *ctx) |
| @@ -339,8 +345,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 6 unmodified lines | |||
| 339 | frei0r->deinit(); | 345 | frei0r->deinit(); |
| 340 | if (frei0r->dl_handle) | 346 | if (frei0r->dl_handle) |
| 341 | dlclose(frei0r->dl_handle); | 347 | dlclose(frei0r->dl_handle); |
| 342 | |||
| 343 | memset(frei0r, 0, sizeof(*frei0r)); | ||
| 344 | } | 348 | } |
| 345 | 349 | ||
| 346 | static int config_input_props(AVFilterLink *inlink) | 350 | static int config_input_props(AVFilterLink *inlink) |
| @@ -401,6 +405,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 54 unmodified lines | |||
| 401 | return ff_filter_frame(outlink, out); | 405 | return ff_filter_frame(outlink, out); |
| 402 | } | 406 | } |
| 403 | 407 | ||
| 408 | #define OFFSET(x) offsetof(Frei0rContext, x) | ||
| 409 | #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | ||
| 410 | static const AVOption filter_options[] = { | ||
| 411 | { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS }, | ||
| 412 | { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS }, | ||
| 413 | { NULL }, | ||
| 414 | }; | ||
| 415 | |||
| 416 | static const AVClass filter_class = { | ||
| 417 | .class_name = "frei0r", | ||
| 418 | .item_name = av_default_item_name, | ||
| 419 | .option = filter_options, | ||
| 420 | .version = LIBAVUTIL_VERSION_INT, | ||
| 421 | }; | ||
| 422 | |||
| 404 | static const AVFilterPad avfilter_vf_frei0r_inputs[] = { | 423 | static const AVFilterPad avfilter_vf_frei0r_inputs[] = { |
| 405 | { | 424 | { |
| 406 | .name = "default", | 425 | .name = "default", |
| @@ -428,6 +447,7 @@ AVFilter avfilter_vf_frei0r = { · 21 unmodified lines | |||
| 428 | .uninit = uninit, | 447 | .uninit = uninit, |
| 429 | 448 | ||
| 430 | .priv_size = sizeof(Frei0rContext), | 449 | .priv_size = sizeof(Frei0rContext), |
| 450 | .priv_class = &filter_class, | ||
| 431 | 451 | ||
| 432 | .inputs = avfilter_vf_frei0r_inputs, | 452 | .inputs = avfilter_vf_frei0r_inputs, |
| 433 | 453 | ||
| @@ -437,30 +457,21 @@ AVFilter avfilter_vf_frei0r = { · 3 unmodified lines | |||
| 437 | static av_cold int source_init(AVFilterContext *ctx, const char *args) | 457 | static av_cold int source_init(AVFilterContext *ctx, const char *args) |
| 438 | { | 458 | { |
| 439 | Frei0rContext *frei0r = ctx->priv; | 459 | Frei0rContext *frei0r = ctx->priv; |
| 440 | char dl_name[1024], c; | ||
| 441 | char frame_size[128] = ""; | ||
| 442 | char frame_rate[128] = ""; | ||
| 443 | AVRational frame_rate_q; | 460 | AVRational frame_rate_q; |
| 444 | 461 | ||
| 445 | memset(frei0r->params, 0, sizeof(frei0r->params)); | 462 | if (av_parse_video_size(&frei0r->w, &frei0r->h, frei0r->size) < 0) { |
| 446 | 463 | av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", frei0r->size); | |
| 447 | if (args) | ||
| 448 | sscanf(args, "%127[^:]:%127[^:]:%1023[^:=]%c%255c", | ||
| 449 | frame_size, frame_rate, dl_name, &c, frei0r->params); | ||
| 450 | |||
| 451 | if (av_parse_video_size(&frei0r->w, &frei0r->h, frame_size) < 0) { | ||
| 452 | av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", frame_size); | ||
| 453 | return AVERROR(EINVAL); | 464 | return AVERROR(EINVAL); |
| 454 | } | 465 | } |
| 455 | 466 | ||
| 456 | if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0) { | 467 | if (av_parse_video_rate(&frame_rate_q, frei0r->framerate) < 0) { |
| 457 | av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", frame_rate); | 468 | av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", frei0r->framerate); |
| 458 | return AVERROR(EINVAL); | 469 | return AVERROR(EINVAL); |
| 459 | } | 470 | } |
| 460 | frei0r->time_base.num = frame_rate_q.den; | 471 | frei0r->time_base.num = frame_rate_q.den; |
| 461 | frei0r->time_base.den = frame_rate_q.num; | 472 | frei0r->time_base.den = frame_rate_q.num; |
| 462 | 473 | ||
| 463 | return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_SOURCE); | 474 | return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_SOURCE); |
| 464 | } | 475 | } |
| 465 | 476 | ||
| 466 | static int source_config_props(AVFilterLink *outlink) | 477 | static int source_config_props(AVFilterLink *outlink) |
| @@ -500,6 +511,21 @@ static int source_request_frame(AVFilterLink *outlink) · 33 unmodified lines | |||
| 500 | return ff_filter_frame(outlink, frame); | 511 | return ff_filter_frame(outlink, frame); |
| 501 | } | 512 | } |
| 502 | 513 | ||
| 514 | static const AVOption src_options[] = { | ||
| 515 | { "size", "Dimensions of the generated video.", OFFSET(size), AV_OPT_TYPE_STRING, { .str = "" }, .flags = FLAGS }, | ||
| 516 | { "framerate", NULL, OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = FLAGS }, | ||
| 517 | { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS }, | ||
| 518 | { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS }, | ||
| 519 | { NULL }, | ||
| 520 | }; | ||
| 521 | |||
| 522 | static const AVClass src_class = { | ||
| 523 | .class_name = "frei0r_src", | ||
| 524 | .item_name = av_default_item_name, | ||
| 525 | .option = src_options, | ||
| 526 | .version = LIBAVUTIL_VERSION_INT, | ||
| 527 | }; | ||
| 528 | |||
| 503 | static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[] = { | 529 | static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[] = { |
| 504 | { | 530 | { |
| 505 | .name = "default", | 531 | .name = "default", |
| @@ -515,6 +541,7 @@ AVFilter avfilter_vsrc_frei0r_src = { · 9 unmodified lines | |||
| 515 | .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."), | 541 | .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."), |
| 516 | 542 | ||
| 517 | .priv_size = sizeof(Frei0rContext), | 543 | .priv_size = sizeof(Frei0rContext), |
| 544 | .priv_class = &src_class, | ||
| 518 | .init = source_init, | 545 | .init = source_init, |
| 519 | .uninit = uninit, | 546 | .uninit = uninit, |
| 520 | 547 | ||