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
5030filter may be changed by later filters in the filterchain, e.g. if5030filter may be changed by later filters in the filterchain, e.g. if
5031another "setsar" or a "setdar" filter is applied.5031another "setsar" or a "setdar" filter is applied.
5032 5032
5033The @code{setdar} and @code{setsar} filters accept a string in the5033The filters accept the following options:
5034form @var{num}:@var{den} expressing an aspect ratio, or the following
5035named options, expressed as a sequence of @var{key}=@var{value} pairs,
5036separated by ":".
5037 5034
5038@table @option5035@table @option
5039@item max5036@item r, ratio, dar (@code{setdar} only), sar (@code{setsar} only)
5040Set the maximum integer value to use for expressing numerator and
5041denominator when reducing the expressed aspect ratio to a rational.
5042Default value is @code{100}.
5043
5044@item r, ratio, dar, sar:
5045Set the aspect ratio used by the filter.5037Set the aspect ratio used by the filter.
5046 5038
5047The parameter can be a floating point number string, an expression, or5039The 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
5050the parameter is not specified, it is assumed the value "0".5042the parameter is not specified, it is assumed the value "0".
5051In case the form "@var{num}:@var{den}" the @code{:} character should5043In case the form "@var{num}:@var{den}" the @code{:} character should
5052be escaped.5044be escaped.
5045
5046@item max
5047Set the maximum integer value to use for expressing numerator and
5048denominator when reducing the expressed aspect ratio to a rational.
5049Default value is @code{100}.
5050
5053@end table5051@end table
5054 5052
5055If the keys are omitted in the named options list, the specifed values5053@subsection Examples
5056are assumed to be @var{ratio} and @var{max} in that order.
5057 5054
5058For example to change the display aspect ratio to 16:9, specify:5055@itemize
5056
5057@item
5058To change the display aspect ratio to 16:9, specify one of the following:
5059@example5059@example
5060setdar='16:9'5060setdar=dar=1.77777
5061# the above is equivalent to
5062setdar=1.77777
5063setdar=dar=16/95061setdar=dar=16/9
5064setdar=dar=1.777775062setdar=dar=1.77777
5065@end example5063@end example
5066 5064
5065@item
5067To change the sample aspect ratio to 10:11, specify:5066To change the sample aspect ratio to 10:11, specify:
5068@example5067@example
5069setsar='10:11'5068setsar=sar=10/11
5070# the above is equivalent to
5071setsar='sar=10/11'
5072@end example5069@end example
5073 5070
5071@item
5074To set a display aspect ratio of 16:9, and specify a maximum integer value of5072To set a display aspect ratio of 16:9, and specify a maximum integer value of
50751000 in the aspect ratio reduction, use the command:50731000 in the aspect ratio reduction, use the command:
5076@example5074@example
5077setdar=ratio='16:9':max=10005075setdar=ratio=16/9:max=1000
5078@end example5076@end example
5079 5077
5078@end itemize
5079
5080@anchor{setfield}5080@anchor{setfield}
5081@section setfield5081@section setfield
5082 5082
libavfilter/avfilter.c+0−2
@@ -681,8 +681,6 @@ static const char *const filters_left_to_update[] = { · 680 unmodified lines
681 "mp",681 "mp",
682 "pan",682 "pan",
683 "scale",683 "scale",
684 "setdar",
685 "setsar",
686};684};
687 685
688static int filter_use_deprecated_init(const char *name)686static int filter_use_deprecated_init(const char *name)
libavfilter/vf_aspect.c+20−28
@@ -38,7 +38,6 @@ · 37 unmodified lines
38typedef struct {38typedef struct {
39 const AVClass *class;39 const AVClass *class;
40 AVRational aspect;40 AVRational aspect;
41 char *ratio_str;
42 int max;41 int max;
43#if FF_API_OLD_FILTER_OPTS42#if FF_API_OLD_FILTER_OPTS
44 float aspect_num, aspect_den;43 float aspect_num, aspect_den;
@@ -49,26 +48,11 @@ typedef struct { · 4 unmodified lines
49static av_cold int init(AVFilterContext *ctx, const char *args)48static av_cold int init(AVFilterContext *ctx, const char *args)
50{49{
51 AspectContext *s = ctx->priv;50 AspectContext *s = ctx->priv;
52 static const char *shorthand[] = { "ratio", "max", NULL };
53 char c;
54 int ret;
55 AVRational q;
56 51
57 if (args && sscanf(args, "%d:%d%c", &q.num, &q.den, &c) == 2) {52 if (s->aspect_num > 0 && s->aspect_den > 0) {
58 s->ratio_str = av_strdup(args);
59 av_log(ctx, AV_LOG_WARNING,53 av_log(ctx, AV_LOG_WARNING,
60 "num:den syntax is deprecated, please use num/den or named options instead\n");54 "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) {55 s->aspect = av_d2q(s->aspect_num / s->aspect_den, INT_MAX);
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 }
72 }56 }
73 57
74 return 0;58 return 0;
@@ -111,11 +95,15 @@ static int setdar_config_props(AVFilterLink *inlink) · 36 unmodified lines
111}95}
112 96
113static const AVOption setdar_options[] = {97static 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 },98#if FF_API_OLD_FILTER_OPTS
115 {"ratio", "display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },99 { "dar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
116 {"r", "display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },100 { "dar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
117 {"dar", "display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },101#endif
118 {NULL}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 }
119};107};
120 108
121AVFILTER_DEFINE_CLASS(setdar);109AVFILTER_DEFINE_CLASS(setdar);
@@ -170,11 +158,15 @@ static int setsar_config_props(AVFilterLink *inlink) · 48 unmodified lines
170}158}
171 159
172static const AVOption setsar_options[] = {160static 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 },161#if FF_API_OLD_FILTER_OPTS
174 {"ratio", "sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },162 { "sar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
175 {"r", "sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },163 { "sar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
176 {"sar", "sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },164#endif
177 {NULL}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 }
178};170};
179 171
180AVFILTER_DEFINE_CLASS(setsar);172AVFILTER_DEFINE_CLASS(setsar);
tests/lavfi-regression.sh+2−2
@@ -60,8 +60,8 @@ do_lavfi "pp6" "pp=be/fd" · 59 unmodified lines
60do_lavfi "scale200" "scale=200:200"60do_lavfi "scale200" "scale=200:200"
61do_lavfi "scale500" "scale=500:500"61do_lavfi "scale500" "scale=500:500"
62do_lavfi "select" "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))"62do_lavfi "select" "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))"
63do_lavfi "setdar" "setdar=16/9"63do_lavfi "setdar" "setdar=dar=16/9"
64do_lavfi "setsar" "setsar=16/11"64do_lavfi "setsar" "setsar=sar=16/11"
65do_lavfi "thumbnail" "thumbnail=10"65do_lavfi "thumbnail" "thumbnail=10"
66do_lavfi "tile" "tile=3x3:nb_frames=5:padding=7:margin=2"66do_lavfi "tile" "tile=3x3:nb_frames=5:padding=7:margin=2"
67do_lavfi "transpose" "transpose"67do_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