* 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 | 4169 | To enable this filter install libopencv library and headers and |
| 4170 | 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 | |
| 4177 | −filter. If not specified the default values are assumed. | |
| 4179 | +@item filter_params | |
| 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 | 4185 | Refer to the official libopencv documentation for more precise |
| 4180 | 4186 | information: |
| @@ -4188,7 +4194,7 @@ Follows the list of supported libopencv filters. · 7 unmodified lines | ||
| 4188 | 4194 | Dilate an image by using a specific structuring element. |
| 4189 | 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 | 4199 | @var{struct_el} represents a structuring element, and has the syntax: |
| 4194 | 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 | 4222 | ocv=dilate |
| 4217 | 4223 | |
| 4218 | 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 | 4227 | # read the shape from the file diamond.shape, iterate two times |
| 4222 | 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 | 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 | 4236 | @end example |
| 4231 | 4237 | |
| 4232 | 4238 | @subsection erode |
| @@ -4242,7 +4248,7 @@ with the same syntax and semantics as the @ref{dilate} filter. · 9 unmodified lines | ||
| 4242 | 4248 | Smooth the input video. |
| 4243 | 4249 | |
| 4244 | 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 | 4253 | @var{type} is the type of smooth filter to apply, and can be one of |
| 4248 | 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 | 671 | !strcmp(filter->filter->name, "frei0r_src") || |
| 672 | 672 | !strcmp(filter->filter->name, "gradfun" ) || |
| 673 | 673 | !strcmp(filter->filter->name, "hqdn3d" ) || |
| 674 | + !strcmp(filter->filter->name, "ocv" ) || | |
| 674 | 675 | !strcmp(filter->filter->name, "format") || |
| 675 | 676 | !strcmp(filter->filter->name, "noformat") || |
| 676 | 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 | 731 | } else if (!strcmp(filter->filter->name, "format") || |
| 731 | 732 | !strcmp(filter->filter->name, "noformat") || |
| 732 | 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 | 736 | /* a hack for compatibility with the old syntax |
| 735 | 737 | * replace colons with |s */ |
| 736 | 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 | 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 | 749 | nb_leading = 1; |
| 747 | 750 | else if (!strcmp(filter->filter->name, "frei0r_src")) |
| 748 | 751 | nb_leading = 3; |
| @@ -30,6 +30,7 @@ · 29 unmodified lines | ||
| 30 | 30 | #include "libavutil/avstring.h" |
| 31 | 31 | #include "libavutil/common.h" |
| 32 | 32 | #include "libavutil/file.h" |
| 33 | +#include "libavutil/opt.h" | |
| 33 | 34 | #include "avfilter.h" |
| 34 | 35 | #include "formats.h" |
| 35 | 36 | #include "internal.h" |
| @@ -70,7 +71,9 @@ static int query_formats(AVFilterContext *ctx) · 34 unmodified lines | ||
| 70 | 71 | } |
| 71 | 72 | |
| 72 | 73 | typedef struct { |
| 73 | − const char *name; | |
| 74 | + const AVClass *class; | |
| 75 | + char *name; | |
| 76 | + char *params; | |
| 74 | 77 | int (*init)(AVFilterContext *ctx, const char *args); |
| 75 | 78 | void (*uninit)(AVFilterContext *ctx); |
| 76 | 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 | 98 | smooth->param4 = 0.0; |
| 96 | 99 | |
| 97 | 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 | 103 | if (!strcmp(type_str, "blur" )) smooth->type = CV_BLUR; |
| 101 | 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 | 264 | dilate->nb_iterations = 1; |
| 262 | 265 | |
| 263 | 266 | if (args) |
| 264 | − kernel_str = av_get_token(&buf, ":"); | |
| 267 | + kernel_str = av_get_token(&buf, "|"); | |
| 265 | 268 | if ((ret = parse_iplconvkernel(&dilate->kernel, |
| 266 | 269 | *kernel_str ? kernel_str : default_kernel_str, |
| 267 | 270 | ctx)) < 0) |
| 268 | 271 | return ret; |
| 269 | 272 | av_free(kernel_str); |
| 270 | 273 | |
| 271 | − sscanf(buf, ":%d", &dilate->nb_iterations); | |
| 274 | + sscanf(buf, "|%d", &dilate->nb_iterations); | |
| 272 | 275 | av_log(ctx, AV_LOG_VERBOSE, "iterations_nb:%d\n", dilate->nb_iterations); |
| 273 | 276 | if (dilate->nb_iterations <= 0) { |
| 274 | 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 | 320 | static av_cold int init(AVFilterContext *ctx, const char *args) |
| 318 | 321 | { |
| 319 | 322 | OCVContext *ocv = ctx->priv; |
| 320 | − char name[128], priv_args[1024]; | |
| 321 | 323 | int i; |
| 322 | − char c; | |
| 323 | − | |
| 324 | − sscanf(args, "%127[^=:]%c%1023s", name, &c, priv_args); | |
| 325 | 324 | |
| 326 | 325 | for (i = 0; i < FF_ARRAY_ELEMS(ocv_filter_entries); i++) { |
| 327 | 326 | OCVFilterEntry *entry = &ocv_filter_entries[i]; |
| 328 | − if (!strcmp(name, entry->name)) { | |
| 329 | − ocv->name = entry->name; | |
| 327 | + if (!strcmp(ocv->name, entry->name)) { | |
| 330 | 328 | ocv->init = entry->init; |
| 331 | 329 | ocv->uninit = entry->uninit; |
| 332 | 330 | ocv->end_frame_filter = entry->end_frame_filter; |
| 333 | 331 | |
| 334 | 332 | if (!(ocv->priv = av_mallocz(entry->priv_size))) |
| 335 | 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 | 339 | return AVERROR(EINVAL); |
| 342 | 340 | } |
| 343 | 341 | |
| @@ -348,7 +346,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 4 unmodified lines | ||
| 348 | 346 | if (ocv->uninit) |
| 349 | 347 | ocv->uninit(ctx); |
| 350 | 348 | av_free(ocv->priv); |
| 351 | − memset(ocv, 0, sizeof(*ocv)); | |
| 352 | 349 | } |
| 353 | 350 | |
| 354 | 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 | 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 | 391 | static const AVFilterPad avfilter_vf_ocv_inputs[] = { |
| 380 | 392 | { |
| 381 | 393 | .name = "default", |
| @@ -398,6 +410,7 @@ AVFilter avfilter_vf_ocv = { · 16 unmodified lines | ||
| 398 | 410 | .description = NULL_IF_CONFIG_SMALL("Apply transform using libopencv."), |
| 399 | 411 | |
| 400 | 412 | .priv_size = sizeof(OCVContext), |
| 413 | + .priv_class = &ocv_class, | |
| 401 | 414 | |
| 402 | 415 | .query_formats = query_formats, |
| 403 | 416 | .init = init, |