History

lavfi/aspect: switch to an AVOptions-based system.

This is heavily based on 2831b307 by Anton Khirnov <anton@khirnov.net>

Clément Bœsch committed 13 years ago

Commit 71ef1ec1 parent 647fe2e4 files · +42 −52Browse files

Unified · Split

4 files
  1. doc/filters.texi +20 −20
  2. libavfilter/avfilter.c +0 −2
  3. libavfilter/vf_aspect.c +20 −28
  4. tests/lavfi-regression.sh +2 −2
doc/filters.texi+20−20
@@ -5030,18 +5030,10 @@ Keep in mind that the sample aspect ratio set by the @code{setsar} · 5029 unmodified lines
50305030 filter may be changed by later filters in the filterchain, e.g. if
50315031 another "setsar" or a "setdar" filter is applied.
50325032
5033−The @code{setdar} and @code{setsar} filters accept a string in the
5034−form @var{num}:@var{den} expressing an aspect ratio, or the following
5035−named options, expressed as a sequence of @var{key}=@var{value} pairs,
5036−separated by ":".
5033+The filters accept the following options:
50375034
50385035 @table @option
5039−@item max
5040−Set the maximum integer value to use for expressing numerator and
5041−denominator when reducing the expressed aspect ratio to a rational.
5042−Default value is @code{100}.
5043−
5044−@item r, ratio, dar, sar:
5036+@item r, ratio, dar (@code{setdar} only), sar (@code{setsar} only)
50455037 Set the aspect ratio used by the filter.
50465038
50475039 The parameter can be a floating point number string, an expression, or
@@ -5050,33 +5042,41 @@ a string of the form @var{num}:@var{den}, where @var{num} and · 2 unmodified lines
50505042 the parameter is not specified, it is assumed the value "0".
50515043 In case the form "@var{num}:@var{den}" the @code{:} character should
50525044 be escaped.
5045+
5046+@item max
5047+Set the maximum integer value to use for expressing numerator and
5048+denominator when reducing the expressed aspect ratio to a rational.
5049+Default value is @code{100}.
5050+
50535051 @end table
50545052
5055−If the keys are omitted in the named options list, the specifed values
5056−are assumed to be @var{ratio} and @var{max} in that order.
5053+@subsection Examples
50575054
5058−For example to change the display aspect ratio to 16:9, specify:
5055+@itemize
5056+
5057+@item
5058+To change the display aspect ratio to 16:9, specify one of the following:
50595059 @example
5060−setdar='16:9'
5061−# the above is equivalent to
5062−setdar=1.77777
5060+setdar=dar=1.77777
50635061 setdar=dar=16/9
50645062 setdar=dar=1.77777
50655063 @end example
50665064
5065+@item
50675066 To change the sample aspect ratio to 10:11, specify:
50685067 @example
5069−setsar='10:11'
5070−# the above is equivalent to
5071−setsar='sar=10/11'
5068+setsar=sar=10/11
50725069 @end example
50735070
5071+@item
50745072 To set a display aspect ratio of 16:9, and specify a maximum integer value of
50755073 1000 in the aspect ratio reduction, use the command:
50765074 @example
5077−setdar=ratio='16:9':max=1000
5075+setdar=ratio=16/9:max=1000
50785076 @end example
50795077
5078+@end itemize
5079+
50805080 @anchor{setfield}
50815081 @section setfield
50825082
libavfilter/avfilter.c+0−2
@@ -681,8 +681,6 @@ static const char *const filters_left_to_update[] = { · 680 unmodified lines
681681 "mp",
682682 "pan",
683683 "scale",
684− "setdar",
685− "setsar",
686684 };
687685
688686 static int filter_use_deprecated_init(const char *name)
libavfilter/vf_aspect.c+20−28
@@ -38,7 +38,6 @@ · 37 unmodified lines
3838 typedef struct {
3939 const AVClass *class;
4040 AVRational aspect;
41− char *ratio_str;
4241 int max;
4342 #if FF_API_OLD_FILTER_OPTS
4443 float aspect_num, aspect_den;
@@ -49,26 +48,11 @@ typedef struct { · 4 unmodified lines
4948 static av_cold int init(AVFilterContext *ctx, const char *args)
5049 {
5150 AspectContext *s = ctx->priv;
52− static const char *shorthand[] = { "ratio", "max", NULL };
53− char c;
54− int ret;
55− AVRational q;
5651
57− if (args && sscanf(args, "%d:%d%c", &q.num, &q.den, &c) == 2) {
58− s->ratio_str = av_strdup(args);
52+ if (s->aspect_num > 0 && s->aspect_den > 0) {
5953 av_log(ctx, AV_LOG_WARNING,
6054 "num:den syntax is deprecated, please use num/den or named options instead\n");
61− } else if ((ret = av_opt_set_from_string(s, args, shorthand, "=", ":")) < 0) {
62− return ret;
63− }
64−
65− if (s->ratio_str) {
66− ret = av_parse_ratio(&s->aspect, s->ratio_str, s->max, 0, ctx);
67− if (ret < 0 || s->aspect.num < 0 || s->aspect.den <= 0) {
68− av_log(ctx, AV_LOG_ERROR,
69− "Invalid string '%s' for aspect ratio\n", args);
70− return AVERROR(EINVAL);
71− }
55+ s->aspect = av_d2q(s->aspect_num / s->aspect_den, INT_MAX);
7256 }
7357
7458 return 0;
@@ -111,11 +95,15 @@ static int setdar_config_props(AVFilterLink *inlink) · 36 unmodified lines
11195 }
11296
11397 static const AVOption setdar_options[] = {
114− {"max", "set max value for nominator or denominator in the ratio", OFFSET(max), AV_OPT_TYPE_INT, {.i64=100}, 1, INT_MAX, FLAGS },
115− {"ratio", "display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
116− {"r", "display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
117− {"dar", "display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
118− {NULL}
98+#if FF_API_OLD_FILTER_OPTS
99+ { "dar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
100+ { "dar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
101+#endif
102+ { "dar", "set display aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX, FLAGS },
103+ { "ratio", "set display aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX, FLAGS },
104+ { "r", "set display aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX, FLAGS },
105+ { "max", "set max value for nominator or denominator in the ratio", OFFSET(max), AV_OPT_TYPE_INT, {.i64=100}, 1, INT_MAX, FLAGS },
106+ { NULL }
119107 };
120108
121109 AVFILTER_DEFINE_CLASS(setdar);
@@ -170,11 +158,15 @@ static int setsar_config_props(AVFilterLink *inlink) · 48 unmodified lines
170158 }
171159
172160 static const AVOption setsar_options[] = {
173− {"max", "set max value for nominator or denominator in the ratio", OFFSET(max), AV_OPT_TYPE_INT, {.i64=100}, 1, INT_MAX, FLAGS },
174− {"ratio", "sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
175− {"r", "sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
176− {"sar", "sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
177− {NULL}
161+#if FF_API_OLD_FILTER_OPTS
162+ { "sar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
163+ { "sar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
164+#endif
165+ { "sar", "set sample (pixel) aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX, FLAGS },
166+ { "ratio", "set sample (pixel) aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX, FLAGS },
167+ { "r", "set sample (pixel) aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX, FLAGS },
168+ { "max", "set max value for nominator or denominator in the ratio", OFFSET(max), AV_OPT_TYPE_INT, {.i64=100}, 1, INT_MAX, FLAGS },
169+ { NULL }
178170 };
179171
180172 AVFILTER_DEFINE_CLASS(setsar);
tests/lavfi-regression.sh+2−2
@@ -60,8 +60,8 @@ do_lavfi "pp6" "pp=be/fd" · 59 unmodified lines
6060 do_lavfi "scale200" "scale=200:200"
6161 do_lavfi "scale500" "scale=500:500"
6262 do_lavfi "select" "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))"
63−do_lavfi "setdar" "setdar=16/9"
64−do_lavfi "setsar" "setsar=16/11"
63+do_lavfi "setdar" "setdar=dar=16/9"
64+do_lavfi "setsar" "setsar=sar=16/11"
6565 do_lavfi "thumbnail" "thumbnail=10"
6666 do_lavfi "tile" "tile=3x3:nb_frames=5:padding=7:margin=2"
6767 do_lavfi "transpose" "transpose"

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