* commit 'ee0e8d4b15a87932ab6066cd6eae3cab08726319': vf_libopencv: switch to an AVOptions-based system.
Unified · Split
| @@ -4169,12 +4169,18 @@ Apply video transform using libopencv. · 4168 unmodified lines | |||
| 4169 | To enable this filter install libopencv library and headers and | 4169 | To enable this filter install libopencv library and headers and |
| 4170 | configure FFmpeg with @code{--enable-libopencv}. | 4170 | configure FFmpeg with @code{--enable-libopencv}. |
| 4171 | 4171 | ||
| 4172 | The filter takes the parameters: @var{filter_name}@{:=@}@var{filter_params}. | 4172 | This filter accepts the following parameters: |
| 4173 | |||
| 4174 | @table @option | ||
| 4173 | 4175 | ||
| 4174 | @var{filter_name} is the name of the libopencv filter to apply. | 4176 | @item filter_name |
| 4177 | The name of the libopencv filter to apply. | ||
| 4175 | 4178 | ||
| 4176 | @var{filter_params} specifies the parameters to pass to the libopencv | 4179 | @item filter_params |
| 4177 | filter. If not specified the default values are assumed. | 4180 | The parameters to pass to the libopencv filter. If not specified the default |
| 4181 | values are assumed. | ||
| 4182 | |||
| 4183 | @end table | ||
| 4178 | 4184 | ||
| 4179 | Refer to the official libopencv documentation for more precise | 4185 | Refer to the official libopencv documentation for more precise |
| 4180 | information: | 4186 | information: |
| @@ -4188,7 +4194,7 @@ Follows the list of supported libopencv filters. · 7 unmodified lines | |||
| 4188 | Dilate an image by using a specific structuring element. | 4194 | Dilate an image by using a specific structuring element. |
| 4189 | This filter corresponds to the libopencv function @code{cvDilate}. | 4195 | This filter corresponds to the libopencv function @code{cvDilate}. |
| 4190 | 4196 | ||
| 4191 | It accepts the parameters: @var{struct_el}:@var{nb_iterations}. | 4197 | It accepts the parameters: @var{struct_el}|@var{nb_iterations}. |
| 4192 | 4198 | ||
| 4193 | @var{struct_el} represents a structuring element, and has the syntax: | 4199 | @var{struct_el} represents a structuring element, and has the syntax: |
| 4194 | @var{cols}x@var{rows}+@var{anchor_x}x@var{anchor_y}/@var{shape} | 4200 | @var{cols}x@var{rows}+@var{anchor_x}x@var{anchor_y}/@var{shape} |
| @@ -4216,7 +4222,7 @@ Follow some example: · 21 unmodified lines | |||
| 4216 | ocv=dilate | 4222 | ocv=dilate |
| 4217 | 4223 | ||
| 4218 | # dilate using a structuring element with a 5x5 cross, iterate two times | 4224 | # dilate using a structuring element with a 5x5 cross, iterate two times |
| 4219 | ocv=dilate=5x5+2x2/cross:2 | 4225 | ocv=filter_name=dilate:filter_params=5x5+2x2/cross|2 |
| 4220 | 4226 | ||
| 4221 | # read the shape from the file diamond.shape, iterate two times | 4227 | # read the shape from the file diamond.shape, iterate two times |
| 4222 | # the file diamond.shape may contain a pattern of characters like this: | 4228 | # the file diamond.shape may contain a pattern of characters like this: |
| @@ -4226,7 +4232,7 @@ ocv=dilate=5x5+2x2/cross:2 · 3 unmodified lines | |||
| 4226 | # *** | 4232 | # *** |
| 4227 | # * | 4233 | # * |
| 4228 | # the specified cols and rows are ignored (but not the anchor point coordinates) | 4234 | # the specified cols and rows are ignored (but not the anchor point coordinates) |
| 4229 | ocv=0x0+2x2/custom=diamond.shape:2 | 4235 | ocv=dilate:0x0+2x2/custom=diamond.shape|2 |
| 4230 | @end example | 4236 | @end example |
| 4231 | 4237 | ||
| 4232 | @subsection erode | 4238 | @subsection erode |
| @@ -4242,7 +4248,7 @@ with the same syntax and semantics as the @ref{dilate} filter. · 9 unmodified lines | |||
| 4242 | Smooth the input video. | 4248 | Smooth the input video. |
| 4243 | 4249 | ||
| 4244 | The filter takes the following parameters: | 4250 | The filter takes the following parameters: |
| 4245 | @var{type}:@var{param1}:@var{param2}:@var{param3}:@var{param4}. | 4251 | @var{type}|@var{param1}|@var{param2}|@var{param3}|@var{param4}. |
| 4246 | 4252 | ||
| 4247 | @var{type} is the type of smooth filter to apply, and can be one of | 4253 | @var{type} is the type of smooth filter to apply, and can be one of |
| 4248 | the following values: "blur", "blur_no_scale", "median", "gaussian", | 4254 | the following values: "blur", "blur_no_scale", "median", "gaussian", |
| @@ -671,6 +671,7 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 670 unmodified lines | |||
| 671 | !strcmp(filter->filter->name, "frei0r_src") || | 671 | !strcmp(filter->filter->name, "frei0r_src") || |
| 672 | !strcmp(filter->filter->name, "gradfun" ) || | 672 | !strcmp(filter->filter->name, "gradfun" ) || |
| 673 | !strcmp(filter->filter->name, "hqdn3d" ) || | 673 | !strcmp(filter->filter->name, "hqdn3d" ) || |
| 674 | !strcmp(filter->filter->name, "ocv" ) || | ||
| 674 | !strcmp(filter->filter->name, "format") || | 675 | !strcmp(filter->filter->name, "format") || |
| 675 | !strcmp(filter->filter->name, "noformat") || | 676 | !strcmp(filter->filter->name, "noformat") || |
| 676 | !strcmp(filter->filter->name, "resample") || | 677 | !strcmp(filter->filter->name, "resample") || |
| @@ -730,7 +731,8 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 53 unmodified lines | |||
| 730 | } else if (!strcmp(filter->filter->name, "format") || | 731 | } else if (!strcmp(filter->filter->name, "format") || |
| 731 | !strcmp(filter->filter->name, "noformat") || | 732 | !strcmp(filter->filter->name, "noformat") || |
| 732 | !strcmp(filter->filter->name, "frei0r") || | 733 | !strcmp(filter->filter->name, "frei0r") || |
| 733 | !strcmp(filter->filter->name, "frei0r_src")) { | 734 | !strcmp(filter->filter->name, "frei0r_src") || |
| 735 | !strcmp(filter->filter->name, "ocv")) { | ||
| 734 | /* a hack for compatibility with the old syntax | 736 | /* a hack for compatibility with the old syntax |
| 735 | * replace colons with |s */ | 737 | * replace colons with |s */ |
| 736 | char *copy = av_strdup(args); | 738 | char *copy = av_strdup(args); |
| @@ -742,7 +744,8 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 5 unmodified lines | |||
| 742 | goto fail; | 744 | goto fail; |
| 743 | } | 745 | } |
| 744 | 746 | ||
| 745 | if (!strcmp(filter->filter->name, "frei0r")) | 747 | if (!strcmp(filter->filter->name, "frei0r") || |
| 748 | !strcmp(filter->filter->name, "ocv")) | ||
| 746 | nb_leading = 1; | 749 | nb_leading = 1; |
| 747 | else if (!strcmp(filter->filter->name, "frei0r_src")) | 750 | else if (!strcmp(filter->filter->name, "frei0r_src")) |
| 748 | nb_leading = 3; | 751 | nb_leading = 3; |
| @@ -30,6 +30,7 @@ · 29 unmodified lines | |||
| 30 | #include "libavutil/avstring.h" | 30 | #include "libavutil/avstring.h" |
| 31 | #include "libavutil/common.h" | 31 | #include "libavutil/common.h" |
| 32 | #include "libavutil/file.h" | 32 | #include "libavutil/file.h" |
| 33 | #include "libavutil/opt.h" | ||
| 33 | #include "avfilter.h" | 34 | #include "avfilter.h" |
| 34 | #include "formats.h" | 35 | #include "formats.h" |
| 35 | #include "internal.h" | 36 | #include "internal.h" |
| @@ -70,7 +71,9 @@ static int query_formats(AVFilterContext *ctx) · 34 unmodified lines | |||
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | typedef struct { | 73 | typedef struct { |
| 73 | const char *name; | 74 | const AVClass *class; |
| 75 | char *name; | ||
| 76 | char *params; | ||
| 74 | int (*init)(AVFilterContext *ctx, const char *args); | 77 | int (*init)(AVFilterContext *ctx, const char *args); |
| 75 | void (*uninit)(AVFilterContext *ctx); | 78 | void (*uninit)(AVFilterContext *ctx); |
| 76 | void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg); | 79 | void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg); |
| @@ -95,7 +98,7 @@ static av_cold int smooth_init(AVFilterContext *ctx, const char *args) · 18 unmodified lines | |||
| 95 | smooth->param4 = 0.0; | 98 | smooth->param4 = 0.0; |
| 96 | 99 | ||
| 97 | if (args) | 100 | if (args) |
| 98 | sscanf(args, "%127[^:]:%d:%d:%lf:%lf", type_str, &smooth->param1, &smooth->param2, &smooth->param3, &smooth->param4); | 101 | sscanf(args, "%127[^|]|%d|%d|%lf|%lf", type_str, &smooth->param1, &smooth->param2, &smooth->param3, &smooth->param4); |
| 99 | 102 | ||
| 100 | if (!strcmp(type_str, "blur" )) smooth->type = CV_BLUR; | 103 | if (!strcmp(type_str, "blur" )) smooth->type = CV_BLUR; |
| 101 | else if (!strcmp(type_str, "blur_no_scale")) smooth->type = CV_BLUR_NO_SCALE; | 104 | else if (!strcmp(type_str, "blur_no_scale")) smooth->type = CV_BLUR_NO_SCALE; |
| @@ -261,14 +264,14 @@ static av_cold int dilate_init(AVFilterContext *ctx, const char *args) · 159 unmodified lines | |||
| 261 | dilate->nb_iterations = 1; | 264 | dilate->nb_iterations = 1; |
| 262 | 265 | ||
| 263 | if (args) | 266 | if (args) |
| 264 | kernel_str = av_get_token(&buf, ":"); | 267 | kernel_str = av_get_token(&buf, "|"); |
| 265 | if ((ret = parse_iplconvkernel(&dilate->kernel, | 268 | if ((ret = parse_iplconvkernel(&dilate->kernel, |
| 266 | *kernel_str ? kernel_str : default_kernel_str, | 269 | *kernel_str ? kernel_str : default_kernel_str, |
| 267 | ctx)) < 0) | 270 | ctx)) < 0) |
| 268 | return ret; | 271 | return ret; |
| 269 | av_free(kernel_str); | 272 | av_free(kernel_str); |
| 270 | 273 | ||
| 271 | sscanf(buf, ":%d", &dilate->nb_iterations); | 274 | sscanf(buf, "|%d", &dilate->nb_iterations); |
| 272 | av_log(ctx, AV_LOG_VERBOSE, "iterations_nb:%d\n", dilate->nb_iterations); | 275 | av_log(ctx, AV_LOG_VERBOSE, "iterations_nb:%d\n", dilate->nb_iterations); |
| 273 | if (dilate->nb_iterations <= 0) { | 276 | if (dilate->nb_iterations <= 0) { |
| 274 | av_log(ctx, AV_LOG_ERROR, "Invalid non-positive value '%d' for nb_iterations\n", | 277 | av_log(ctx, AV_LOG_ERROR, "Invalid non-positive value '%d' for nb_iterations\n", |
| @@ -317,27 +320,22 @@ static OCVFilterEntry ocv_filter_entries[] = { · 42 unmodified lines | |||
| 317 | static av_cold int init(AVFilterContext *ctx, const char *args) | 320 | static av_cold int init(AVFilterContext *ctx, const char *args) |
| 318 | { | 321 | { |
| 319 | OCVContext *ocv = ctx->priv; | 322 | OCVContext *ocv = ctx->priv; |
| 320 | char name[128], priv_args[1024]; | ||
| 321 | int i; | 323 | int i; |
| 322 | char c; | ||
| 323 | |||
| 324 | sscanf(args, "%127[^=:]%c%1023s", name, &c, priv_args); | ||
| 325 | 324 | ||
| 326 | for (i = 0; i < FF_ARRAY_ELEMS(ocv_filter_entries); i++) { | 325 | for (i = 0; i < FF_ARRAY_ELEMS(ocv_filter_entries); i++) { |
| 327 | OCVFilterEntry *entry = &ocv_filter_entries[i]; | 326 | OCVFilterEntry *entry = &ocv_filter_entries[i]; |
| 328 | if (!strcmp(name, entry->name)) { | 327 | if (!strcmp(ocv->name, entry->name)) { |
| 329 | ocv->name = entry->name; | ||
| 330 | ocv->init = entry->init; | 328 | ocv->init = entry->init; |
| 331 | ocv->uninit = entry->uninit; | 329 | ocv->uninit = entry->uninit; |
| 332 | ocv->end_frame_filter = entry->end_frame_filter; | 330 | ocv->end_frame_filter = entry->end_frame_filter; |
| 333 | 331 | ||
| 334 | if (!(ocv->priv = av_mallocz(entry->priv_size))) | 332 | if (!(ocv->priv = av_mallocz(entry->priv_size))) |
| 335 | return AVERROR(ENOMEM); | 333 | return AVERROR(ENOMEM); |
| 336 | return ocv->init(ctx, priv_args); | 334 | return ocv->init(ctx, ocv->params); |
| 337 | } | 335 | } |
| 338 | } | 336 | } |
| 339 | 337 | ||
| 340 | av_log(ctx, AV_LOG_ERROR, "No libopencv filter named '%s'\n", name); | 338 | av_log(ctx, AV_LOG_ERROR, "No libopencv filter named '%s'\n", ocv->name); |
| 341 | return AVERROR(EINVAL); | 339 | return AVERROR(EINVAL); |
| 342 | } | 340 | } |
| 343 | 341 | ||
| @@ -348,7 +346,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 4 unmodified lines | |||
| 348 | if (ocv->uninit) | 346 | if (ocv->uninit) |
| 349 | ocv->uninit(ctx); | 347 | ocv->uninit(ctx); |
| 350 | av_free(ocv->priv); | 348 | av_free(ocv->priv); |
| 351 | memset(ocv, 0, sizeof(*ocv)); | ||
| 352 | } | 349 | } |
| 353 | 350 | ||
| 354 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) | 351 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
| @@ -376,6 +373,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 21 unmodified lines | |||
| 376 | return ff_filter_frame(outlink, out); | 373 | return ff_filter_frame(outlink, out); |
| 377 | } | 374 | } |
| 378 | 375 | ||
| 376 | #define OFFSET(x) offsetof(OCVContext, x) | ||
| 377 | #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | ||
| 378 | static const AVOption options[] = { | ||
| 379 | { "filter_name", NULL, OFFSET(name), AV_OPT_TYPE_STRING, .flags = FLAGS }, | ||
| 380 | { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS }, | ||
| 381 | { NULL }, | ||
| 382 | }; | ||
| 383 | |||
| 384 | static const AVClass ocv_class = { | ||
| 385 | .class_name = "ocv", | ||
| 386 | .item_name = av_default_item_name, | ||
| 387 | .option = options, | ||
| 388 | .version = LIBAVUTIL_VERSION_INT, | ||
| 389 | }; | ||
| 390 | |||
| 379 | static const AVFilterPad avfilter_vf_ocv_inputs[] = { | 391 | static const AVFilterPad avfilter_vf_ocv_inputs[] = { |
| 380 | { | 392 | { |
| 381 | .name = "default", | 393 | .name = "default", |
| @@ -398,6 +410,7 @@ AVFilter avfilter_vf_ocv = { · 16 unmodified lines | |||
| 398 | .description = NULL_IF_CONFIG_SMALL("Apply transform using libopencv."), | 410 | .description = NULL_IF_CONFIG_SMALL("Apply transform using libopencv."), |
| 399 | 411 | ||
| 400 | .priv_size = sizeof(OCVContext), | 412 | .priv_size = sizeof(OCVContext), |
| 413 | .priv_class = &ocv_class, | ||
| 401 | 414 | ||
| 402 | .query_formats = query_formats, | 415 | .query_formats = query_formats, |
| 403 | .init = init, | 416 | .init = init, |