History

Merge commit '5aa1a668cfae7f617e1a06efad20f87283badd8a'

* commit '5aa1a668cfae7f617e1a06efad20f87283badd8a': vf_frei0r: switch to an AVOptions-based system. Conflicts: doc/filters.texi libavfilter/vf_frei0r.c

Michael Niedermayer committed 13 years ago

Commit da3f8992 parents 9280fc7 5aa1a663 files · +107 −51Browse files

Unified · Split

3 files
  1. doc/filters.texi +34 −24
  2. libavfilter/avfilter.c +22 −3
  3. libavfilter/vf_frei0r.c +51 −24
doc/filters.texi+34−24
@@ -3251,21 +3251,22 @@ Apply a frei0r effect to the input video. · 3250 unmodified lines
32513251 To enable compilation of this filter you need to install the frei0r
32523252 header and configure FFmpeg with @code{--enable-frei0r}.
32533253
3254−The filter supports the syntax:
3255−@example
3256−@var{filter_name}[@{:|=@}@var{param1}:@var{param2}:...:@var{paramN}]
3257−@end example
3254+This filter accepts the following options:
3255+
3256+@table @option
32583257
3259−@var{filter_name} is the name of the frei0r effect to load. If the
3260−environment variable @env{FREI0R_PATH} is defined, the frei0r effect
3261−is searched in each one of the directories specified by the colon (or
3262−semicolon on Windows platforms) separated list in @env{FREIOR_PATH},
3258+@item filter_name
3259+The name to the frei0r effect to load. If the environment variable
3260+@env{FREI0R_PATH} is defined, the frei0r effect is searched in each one of the
3261+directories specified by the colon separated list in @env{FREIOR_PATH},
32633262 otherwise in the standard frei0r paths, which are in this order:
32643263 @file{HOME/.frei0r-1/lib/}, @file{/usr/local/lib/frei0r-1/},
32653264 @file{/usr/lib/frei0r-1/}.
32663265
3267−@var{param1}, @var{param2}, ... , @var{paramN} specify the parameters
3268−for the frei0r effect.
3266+@item filter_params
3267+A '|'-separated list of parameters to pass to the frei0r effect.
3268+
3269+@end table
32693270
32703271 A frei0r effect parameter can be a boolean (whose values are specified
32713272 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
32833284 @item
32843285 Apply the distort0r effect, set the first two double parameters:
32853286 @example
3286−frei0r=distort0r:0.5:0.01
3287+frei0r=filter_name=distort0r:filter_params=0.5|0.01
32873288 @end example
32883289
32893290 @item
@@ -3298,7 +3299,7 @@ frei0r=colordistance:0x112233 · 8 unmodified lines
32983299 Apply the perspective effect, specify the top left and top right image
32993300 positions:
33003301 @example
3301−frei0r=perspective:0.2/0.2:0.8/0.2
3302+frei0r=perspective:0.2/0.2|0.8/0.2
33023303 @end example
33033304 @end itemize
33043305
@@ -6074,23 +6075,32 @@ Provide a frei0r source. · 2769 unmodified lines
60746075 To enable compilation of this filter you need to install the frei0r
60756076 header and configure FFmpeg with @code{--enable-frei0r}.
60766077
6077−The source supports the syntax:
6078−@example
6079−@var{size}:@var{rate}:@var{src_name}[@{=|:@}@var{param1}:@var{param2}:...:@var{paramN}]
6080−@end example
6078+This source accepts the following options:
60816079
6082−@var{size} is the size of the video to generate, may be a string of the
6083−form @var{width}x@var{height} or a frame size abbreviation.
6084−@var{rate} is the rate of the video to generate, may be a string of
6085−the form @var{num}/@var{den} or a frame rate abbreviation.
6086−@var{src_name} is the name to the frei0r source to load. For more
6087−information regarding frei0r and how to set the parameters read the
6088−section @ref{frei0r} in the description of the video filters.
6080+@table @option
6081+
6082+@item size
6083+The size of the video to generate, may be a string of the form
6084+@var{width}x@var{height} or a frame size abbreviation.
6085+
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
60896099
60906100 For example, to generate a frei0r partik0l source with size 200x200
60916101 and frame rate 10 which is overlayed on the overlay filter main input:
60926102 @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
60946104 @end example
60956105
60966106 @section life
libavfilter/avfilter.c+22−3
@@ -667,6 +667,8 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 666 unmodified lines
667667 !strcmp(filter->filter->name, "fade" ) ||
668668 !strcmp(filter->filter->name, "fieldorder") ||
669669 !strcmp(filter->filter->name, "fps" ) ||
670+ !strcmp(filter->filter->name, "frei0r" ) ||
671+ !strcmp(filter->filter->name, "frei0r_src") ||
670672 !strcmp(filter->filter->name, "format") ||
671673 !strcmp(filter->filter->name, "noformat") ||
672674 !strcmp(filter->filter->name, "resample")
@@ -691,19 +693,36 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 18 unmodified lines
691693 if (ret < 0)
692694 goto fail;
693695 #if FF_API_OLD_FILTER_OPTS
694− } else if (!strcmp(filter->filter->name, "format") ||
695− !strcmp(filter->filter->name, "noformat")) {
696+ } else if (!strcmp(filter->filter->name, "format") ||
697+ !strcmp(filter->filter->name, "noformat") ||
698+ !strcmp(filter->filter->name, "frei0r") ||
699+ !strcmp(filter->filter->name, "frei0r_src")) {
696700 /* a hack for compatibility with the old syntax
697701 * replace colons with |s */
698702 char *copy = av_strdup(args);
699703 char *p = copy;
704+ int nb_leading = 0; // number of leading colons to skip
700705
701706 if (!copy) {
702707 ret = AVERROR(ENOMEM);
703708 goto fail;
704709 }
705710
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, ':')) {
707726 av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "
708727 "'|' to separate the list items.\n");
709728 }
libavfilter/vf_frei0r.c+51−24
@@ -35,6 +35,7 @@ · 34 unmodified lines
3535 #include "libavutil/internal.h"
3636 #include "libavutil/mathematics.h"
3737 #include "libavutil/mem.h"
38+#include "libavutil/opt.h"
3839 #include "libavutil/parseutils.h"
3940 #include "avfilter.h"
4041 #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
5354 typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
5455
5556 typedef struct Frei0rContext {
57+ const AVClass *class;
5658 f0r_update_f update;
5759 void *dl_handle; /* dynamic library handle */
5860 f0r_instance_t instance;
@@ -64,7 +66,11 @@ typedef struct Frei0rContext { · 5 unmodified lines
6466 f0r_construct_f construct;
6567 f0r_destruct_f destruct;
6668 f0r_deinit_f deinit;
67− char params[256];
69+
70+ char *dl_name;
71+ char *params;
72+ char *size;
73+ char *framerate;
6874
6975 /* only used by the source */
7076 int w, h;
@@ -143,7 +149,7 @@ static int set_params(AVFilterContext *ctx, const char *params) · 72 unmodified lines
143149 frei0r->get_param_info(&info, i);
144150
145151 if (*params) {
146− if (!(param = av_get_token(&params, ":")))
152+ if (!(param = av_get_token(&params, "|")))
147153 return AVERROR(ENOMEM);
148154 params++; /* skip ':' */
149155 ret = set_param(ctx, info, i, param);
@@ -225,6 +231,11 @@ static av_cold int frei0r_init(AVFilterContext *ctx, · 75 unmodified lines
225231 char *path;
226232 int ret = 0;
227233
234+ if (!dl_name) {
235+ av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n");
236+ return AVERROR(EINVAL);
237+ }
238+
228239 /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */
229240 if ((path = av_strdup(getenv("FREI0R_PATH")))) {
230241 #ifdef _WIN32
@@ -320,13 +331,8 @@ static av_cold int frei0r_init(AVFilterContext *ctx, · 89 unmodified lines
320331 static av_cold int filter_init(AVFilterContext *ctx, const char *args)
321332 {
322333 Frei0rContext *frei0r = ctx->priv;
323− char dl_name[1024], c;
324− *frei0r->params = 0;
325334
326− if (args)
327− sscanf(args, "%1023[^:=]%c%255c", dl_name, &c, frei0r->params);
328−
329− return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_FILTER);
335+ return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_FILTER);
330336 }
331337
332338 static av_cold void uninit(AVFilterContext *ctx)
@@ -339,8 +345,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 6 unmodified lines
339345 frei0r->deinit();
340346 if (frei0r->dl_handle)
341347 dlclose(frei0r->dl_handle);
342−
343− memset(frei0r, 0, sizeof(*frei0r));
344348 }
345349
346350 static int config_input_props(AVFilterLink *inlink)
@@ -401,6 +405,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 54 unmodified lines
401405 return ff_filter_frame(outlink, out);
402406 }
403407
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+
404423 static const AVFilterPad avfilter_vf_frei0r_inputs[] = {
405424 {
406425 .name = "default",
@@ -428,6 +447,7 @@ AVFilter avfilter_vf_frei0r = { · 21 unmodified lines
428447 .uninit = uninit,
429448
430449 .priv_size = sizeof(Frei0rContext),
450+ .priv_class = &filter_class,
431451
432452 .inputs = avfilter_vf_frei0r_inputs,
433453
@@ -437,30 +457,21 @@ AVFilter avfilter_vf_frei0r = { · 3 unmodified lines
437457 static av_cold int source_init(AVFilterContext *ctx, const char *args)
438458 {
439459 Frei0rContext *frei0r = ctx->priv;
440− char dl_name[1024], c;
441− char frame_size[128] = "";
442− char frame_rate[128] = "";
443460 AVRational frame_rate_q;
444461
445− memset(frei0r->params, 0, sizeof(frei0r->params));
446−
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);
462+ if (av_parse_video_size(&frei0r->w, &frei0r->h, frei0r->size) < 0) {
463+ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", frei0r->size);
453464 return AVERROR(EINVAL);
454465 }
455466
456− if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0) {
457− av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", frame_rate);
467+ if (av_parse_video_rate(&frame_rate_q, frei0r->framerate) < 0) {
468+ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", frei0r->framerate);
458469 return AVERROR(EINVAL);
459470 }
460471 frei0r->time_base.num = frame_rate_q.den;
461472 frei0r->time_base.den = frame_rate_q.num;
462473
463− return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_SOURCE);
474+ return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_SOURCE);
464475 }
465476
466477 static int source_config_props(AVFilterLink *outlink)
@@ -500,6 +511,21 @@ static int source_request_frame(AVFilterLink *outlink) · 33 unmodified lines
500511 return ff_filter_frame(outlink, frame);
501512 }
502513
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+
503529 static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[] = {
504530 {
505531 .name = "default",
@@ -515,6 +541,7 @@ AVFilter avfilter_vsrc_frei0r_src = { · 9 unmodified lines
515541 .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
516542
517543 .priv_size = sizeof(Frei0rContext),
544+ .priv_class = &src_class,
518545 .init = source_init,
519546 .uninit = uninit,
520547

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t