... | ... |
@@ -1834,18 +1834,20 @@ the video frame. Also the display aspect ratio set by this filter may |
1834 | 1834 |
be changed by later filters in the filterchain, e.g. in case of |
1835 | 1835 |
scaling or if another "setdar" or a "setsar" filter is applied. |
1836 | 1836 |
|
1837 |
-The filter accepts a parameter string which represents the wanted |
|
1838 |
-display aspect ratio. |
|
1839 |
-The parameter can be a floating point number string, or an expression |
|
1840 |
-of the form @var{num}:@var{den}, where @var{num} and @var{den} are the |
|
1841 |
-numerator and denominator of the aspect ratio. |
|
1842 |
-If the parameter is not specified, it is assumed the value "0:1". |
|
1837 |
+This filter accepts the following options: |
|
1838 |
+ |
|
1839 |
+@table @option |
|
1840 |
+ |
|
1841 |
+@item dar |
|
1842 |
+Output display aspect ratio, as a rational or a decimal number. |
|
1843 |
+ |
|
1844 |
+@end table |
|
1843 | 1845 |
|
1844 | 1846 |
For example to change the display aspect ratio to 16:9, specify: |
1845 | 1847 |
@example |
1846 |
-setdar=16:9 |
|
1848 |
+setdar=dar=16/9 |
|
1847 | 1849 |
# the above is equivalent to |
1848 |
-setdar=1.77777 |
|
1850 |
+setdar=dar=1.77777 |
|
1849 | 1851 |
@end example |
1850 | 1852 |
|
1851 | 1853 |
See also the @ref{setsar} filter documentation. |
... | ... |
@@ -1929,16 +1931,18 @@ Keep in mind that the sample aspect ratio set by this filter may be |
1929 | 1929 |
changed by later filters in the filterchain, e.g. if another "setsar" |
1930 | 1930 |
or a "setdar" filter is applied. |
1931 | 1931 |
|
1932 |
-The filter accepts a parameter string which represents the wanted |
|
1933 |
-sample aspect ratio. |
|
1934 |
-The parameter can be a floating point number string, or an expression |
|
1935 |
-of the form @var{num}:@var{den}, where @var{num} and @var{den} are the |
|
1936 |
-numerator and denominator of the aspect ratio. |
|
1937 |
-If the parameter is not specified, it is assumed the value "0:1". |
|
1932 |
+This filter accepts the following options: |
|
1933 |
+ |
|
1934 |
+@table @option |
|
1935 |
+ |
|
1936 |
+@item sar |
|
1937 |
+Output sample aspect ratio, as a rational or decimal number. |
|
1938 |
+ |
|
1939 |
+@end table |
|
1938 | 1940 |
|
1939 | 1941 |
For example to change the sample aspect ratio to 10:11, specify: |
1940 | 1942 |
@example |
1941 |
-setsar=10:11 |
|
1943 |
+setsar=sar=10/11 |
|
1942 | 1944 |
@end example |
1943 | 1945 |
|
1944 | 1946 |
@section settb |
... | ... |
@@ -23,47 +23,38 @@ |
23 | 23 |
* aspect ratio modification video filters |
24 | 24 |
*/ |
25 | 25 |
|
26 |
+#include <float.h> |
|
27 |
+ |
|
26 | 28 |
#include "libavutil/common.h" |
27 | 29 |
#include "libavutil/mathematics.h" |
30 |
+#include "libavutil/opt.h" |
|
31 |
+ |
|
28 | 32 |
#include "avfilter.h" |
29 | 33 |
#include "internal.h" |
30 | 34 |
#include "video.h" |
31 | 35 |
|
32 | 36 |
typedef struct { |
37 |
+ const AVClass *class; |
|
33 | 38 |
AVRational aspect; |
39 |
+#if FF_API_OLD_FILTER_OPTS |
|
40 |
+ float aspect_num, aspect_den; |
|
41 |
+#endif |
|
34 | 42 |
} AspectContext; |
35 | 43 |
|
44 |
+#if FF_API_OLD_FILTER_OPTS |
|
36 | 45 |
static av_cold int init(AVFilterContext *ctx, const char *args) |
37 | 46 |
{ |
38 |
- AspectContext *aspect = ctx->priv; |
|
39 |
- double ratio; |
|
40 |
- int64_t gcd; |
|
41 |
- char c = 0; |
|
42 |
- |
|
43 |
- if (args) { |
|
44 |
- if (sscanf(args, "%d:%d%c", &aspect->aspect.num, &aspect->aspect.den, &c) != 2) |
|
45 |
- if (sscanf(args, "%lf%c", &ratio, &c) == 1) |
|
46 |
- aspect->aspect = av_d2q(ratio, 100); |
|
47 |
- |
|
48 |
- if (c || aspect->aspect.num <= 0 || aspect->aspect.den <= 0) { |
|
49 |
- av_log(ctx, AV_LOG_ERROR, |
|
50 |
- "Invalid string '%s' for aspect ratio.\n", args); |
|
51 |
- return AVERROR(EINVAL); |
|
52 |
- } |
|
53 |
- |
|
54 |
- gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den)); |
|
55 |
- if (gcd) { |
|
56 |
- aspect->aspect.num /= gcd; |
|
57 |
- aspect->aspect.den /= gcd; |
|
58 |
- } |
|
59 |
- } |
|
47 |
+ AspectContext *s = ctx->priv; |
|
60 | 48 |
|
61 |
- if (aspect->aspect.den == 0) |
|
62 |
- aspect->aspect = (AVRational) {0, 1}; |
|
49 |
+ if (s->aspect_num > 0 && s->aspect_den > 0) { |
|
50 |
+ av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use " |
|
51 |
+ "dar=<number> or dar=num/den.\n"); |
|
52 |
+ s->aspect = av_d2q(s->aspect_num / s->aspect_den, INT_MAX); |
|
53 |
+ } |
|
63 | 54 |
|
64 |
- av_log(ctx, AV_LOG_VERBOSE, "a:%d/%d\n", aspect->aspect.num, aspect->aspect.den); |
|
65 | 55 |
return 0; |
66 | 56 |
} |
57 |
+#endif |
|
67 | 58 |
|
68 | 59 |
static int filter_frame(AVFilterLink *link, AVFrame *frame) |
69 | 60 |
{ |
... | ... |
@@ -73,6 +64,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) |
73 | 73 |
return ff_filter_frame(link->dst->outputs[0], frame); |
74 | 74 |
} |
75 | 75 |
|
76 |
+#define OFFSET(x) offsetof(AspectContext, x) |
|
77 |
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM |
|
78 |
+ |
|
76 | 79 |
#if CONFIG_SETDAR_FILTER |
77 | 80 |
/* for setdar filter, convert from frame aspect ratio to pixel aspect ratio */ |
78 | 81 |
static int setdar_config_props(AVFilterLink *inlink) |
... | ... |
@@ -80,18 +74,39 @@ static int setdar_config_props(AVFilterLink *inlink) |
80 | 80 |
AspectContext *aspect = inlink->dst->priv; |
81 | 81 |
AVRational dar = aspect->aspect; |
82 | 82 |
|
83 |
- av_reduce(&aspect->aspect.num, &aspect->aspect.den, |
|
84 |
- aspect->aspect.num * inlink->h, |
|
85 |
- aspect->aspect.den * inlink->w, 100); |
|
83 |
+ if (aspect->aspect.num && aspect->aspect.den) { |
|
84 |
+ av_reduce(&aspect->aspect.num, &aspect->aspect.den, |
|
85 |
+ aspect->aspect.num * inlink->h, |
|
86 |
+ aspect->aspect.den * inlink->w, 100); |
|
87 |
+ inlink->sample_aspect_ratio = aspect->aspect; |
|
88 |
+ } else { |
|
89 |
+ inlink->sample_aspect_ratio = (AVRational){ 1, 1 }; |
|
90 |
+ dar = (AVRational){ inlink->w, inlink->h }; |
|
91 |
+ } |
|
86 | 92 |
|
87 | 93 |
av_log(inlink->dst, AV_LOG_VERBOSE, "w:%d h:%d -> dar:%d/%d sar:%d/%d\n", |
88 |
- inlink->w, inlink->h, dar.num, dar.den, aspect->aspect.num, aspect->aspect.den); |
|
89 |
- |
|
90 |
- inlink->sample_aspect_ratio = aspect->aspect; |
|
94 |
+ inlink->w, inlink->h, dar.num, dar.den, |
|
95 |
+ inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den); |
|
91 | 96 |
|
92 | 97 |
return 0; |
93 | 98 |
} |
94 | 99 |
|
100 |
+static const AVOption setdar_options[] = { |
|
101 |
+#if FF_API_OLD_FILTER_OPTS |
|
102 |
+ { "dar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS }, |
|
103 |
+ { "dar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS }, |
|
104 |
+#endif |
|
105 |
+ { "dar", "display aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, FLAGS }, |
|
106 |
+ { NULL }, |
|
107 |
+}; |
|
108 |
+ |
|
109 |
+static const AVClass setdar_class = { |
|
110 |
+ .class_name = "setdar", |
|
111 |
+ .item_name = av_default_item_name, |
|
112 |
+ .option = setdar_options, |
|
113 |
+ .version = LIBAVUTIL_VERSION_INT, |
|
114 |
+}; |
|
115 |
+ |
|
95 | 116 |
static const AVFilterPad avfilter_vf_setdar_inputs[] = { |
96 | 117 |
{ |
97 | 118 |
.name = "default", |
... | ... |
@@ -115,9 +130,12 @@ AVFilter avfilter_vf_setdar = { |
115 | 115 |
.name = "setdar", |
116 | 116 |
.description = NULL_IF_CONFIG_SMALL("Set the frame display aspect ratio."), |
117 | 117 |
|
118 |
+#if FF_API_OLD_FILTER_OPTS |
|
118 | 119 |
.init = init, |
120 |
+#endif |
|
119 | 121 |
|
120 | 122 |
.priv_size = sizeof(AspectContext), |
123 |
+ .priv_class = &setdar_class, |
|
121 | 124 |
|
122 | 125 |
.inputs = avfilter_vf_setdar_inputs, |
123 | 126 |
|
... | ... |
@@ -136,6 +154,22 @@ static int setsar_config_props(AVFilterLink *inlink) |
136 | 136 |
return 0; |
137 | 137 |
} |
138 | 138 |
|
139 |
+static const AVOption setsar_options[] = { |
|
140 |
+#if FF_API_OLD_FILTER_OPTS |
|
141 |
+ { "sar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS }, |
|
142 |
+ { "sar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS }, |
|
143 |
+#endif |
|
144 |
+ { "sar", "sample (pixel) aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, INT_MAX, FLAGS }, |
|
145 |
+ { NULL }, |
|
146 |
+}; |
|
147 |
+ |
|
148 |
+static const AVClass setsar_class = { |
|
149 |
+ .class_name = "setsar", |
|
150 |
+ .item_name = av_default_item_name, |
|
151 |
+ .option = setsar_options, |
|
152 |
+ .version = LIBAVUTIL_VERSION_INT, |
|
153 |
+}; |
|
154 |
+ |
|
139 | 155 |
static const AVFilterPad avfilter_vf_setsar_inputs[] = { |
140 | 156 |
{ |
141 | 157 |
.name = "default", |
... | ... |
@@ -159,9 +193,12 @@ AVFilter avfilter_vf_setsar = { |
159 | 159 |
.name = "setsar", |
160 | 160 |
.description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."), |
161 | 161 |
|
162 |
+#if FF_API_OLD_FILTER_OPTS |
|
162 | 163 |
.init = init, |
164 |
+#endif |
|
163 | 165 |
|
164 | 166 |
.priv_size = sizeof(AspectContext), |
167 |
+ .priv_class = &setsar_class, |
|
165 | 168 |
|
166 | 169 |
.inputs = avfilter_vf_setsar_inputs, |
167 | 170 |
|