This is heavily based on 2831b307 by Anton Khirnov <anton@khirnov.net>
Unified · Split
| @@ -5030,18 +5030,10 @@ Keep in mind that the sample aspect ratio set by the @code{setsar} · 5029 unmodified lines | |||
| 5030 | filter may be changed by later filters in the filterchain, e.g. if | 5030 | filter may be changed by later filters in the filterchain, e.g. if |
| 5031 | another "setsar" or a "setdar" filter is applied. | 5031 | another "setsar" or a "setdar" filter is applied. |
| 5032 | 5032 | ||
| 5033 | The @code{setdar} and @code{setsar} filters accept a string in the | 5033 | The filters accept the following options: |
| 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 ":". | ||
| 5037 | 5034 | ||
| 5038 | @table @option | 5035 | @table @option |
| 5039 | @item max | 5036 | @item r, ratio, dar (@code{setdar} only), sar (@code{setsar} only) |
| 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: | ||
| 5045 | Set the aspect ratio used by the filter. | 5037 | Set the aspect ratio used by the filter. |
| 5046 | 5038 | ||
| 5047 | The parameter can be a floating point number string, an expression, or | 5039 | 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 | |||
| 5050 | the parameter is not specified, it is assumed the value "0". | 5042 | the parameter is not specified, it is assumed the value "0". |
| 5051 | In case the form "@var{num}:@var{den}" the @code{:} character should | 5043 | In case the form "@var{num}:@var{den}" the @code{:} character should |
| 5052 | be escaped. | 5044 | 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 | |||
| 5053 | @end table | 5051 | @end table |
| 5054 | 5052 | ||
| 5055 | If the keys are omitted in the named options list, the specifed values | 5053 | @subsection Examples |
| 5056 | are assumed to be @var{ratio} and @var{max} in that order. | ||
| 5057 | 5054 | ||
| 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: | ||
| 5059 | @example | 5059 | @example |
| 5060 | setdar='16:9' | 5060 | setdar=dar=1.77777 |
| 5061 | # the above is equivalent to | ||
| 5062 | setdar=1.77777 | ||
| 5063 | setdar=dar=16/9 | 5061 | setdar=dar=16/9 |
| 5064 | setdar=dar=1.77777 | 5062 | setdar=dar=1.77777 |
| 5065 | @end example | 5063 | @end example |
| 5066 | 5064 | ||
| 5065 | @item | ||
| 5067 | To change the sample aspect ratio to 10:11, specify: | 5066 | To change the sample aspect ratio to 10:11, specify: |
| 5068 | @example | 5067 | @example |
| 5069 | setsar='10:11' | 5068 | setsar=sar=10/11 |
| 5070 | # the above is equivalent to | ||
| 5071 | setsar='sar=10/11' | ||
| 5072 | @end example | 5069 | @end example |
| 5073 | 5070 | ||
| 5071 | @item | ||
| 5074 | To set a display aspect ratio of 16:9, and specify a maximum integer value of | 5072 | To set a display aspect ratio of 16:9, and specify a maximum integer value of |
| 5075 | 1000 in the aspect ratio reduction, use the command: | 5073 | 1000 in the aspect ratio reduction, use the command: |
| 5076 | @example | 5074 | @example |
| 5077 | setdar=ratio='16:9':max=1000 | 5075 | setdar=ratio=16/9:max=1000 |
| 5078 | @end example | 5076 | @end example |
| 5079 | 5077 | ||
| 5078 | @end itemize | ||
| 5079 | |||
| 5080 | @anchor{setfield} | 5080 | @anchor{setfield} |
| 5081 | @section setfield | 5081 | @section setfield |
| 5082 | 5082 | ||
| @@ -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 | ||
| 688 | static int filter_use_deprecated_init(const char *name) | 686 | static int filter_use_deprecated_init(const char *name) |
| @@ -38,7 +38,6 @@ · 37 unmodified lines | |||
| 38 | typedef struct { | 38 | typedef 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_OPTS | 42 | #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 | |||
| 49 | static av_cold int init(AVFilterContext *ctx, const char *args) | 48 | static 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 | ||
| 113 | static const AVOption setdar_options[] = { | 97 | 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 }, | 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 | ||
| 121 | AVFILTER_DEFINE_CLASS(setdar); | 109 | AVFILTER_DEFINE_CLASS(setdar); |
| @@ -170,11 +158,15 @@ static int setsar_config_props(AVFilterLink *inlink) · 48 unmodified lines | |||
| 170 | } | 158 | } |
| 171 | 159 | ||
| 172 | static const AVOption setsar_options[] = { | 160 | 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 }, | 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 | ||
| 180 | AVFILTER_DEFINE_CLASS(setsar); | 172 | AVFILTER_DEFINE_CLASS(setsar); |
| @@ -60,8 +60,8 @@ do_lavfi "pp6" "pp=be/fd" · 59 unmodified lines | |||
| 60 | do_lavfi "scale200" "scale=200:200" | 60 | do_lavfi "scale200" "scale=200:200" |
| 61 | do_lavfi "scale500" "scale=500:500" | 61 | do_lavfi "scale500" "scale=500:500" |
| 62 | do_lavfi "select" "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))" | 62 | do_lavfi "select" "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))" |
| 63 | do_lavfi "setdar" "setdar=16/9" | 63 | do_lavfi "setdar" "setdar=dar=16/9" |
| 64 | do_lavfi "setsar" "setsar=16/11" | 64 | do_lavfi "setsar" "setsar=sar=16/11" |
| 65 | do_lavfi "thumbnail" "thumbnail=10" | 65 | do_lavfi "thumbnail" "thumbnail=10" |
| 66 | do_lavfi "tile" "tile=3x3:nb_frames=5:padding=7:margin=2" | 66 | do_lavfi "tile" "tile=3x3:nb_frames=5:padding=7:margin=2" |
| 67 | do_lavfi "transpose" "transpose" | 67 | do_lavfi "transpose" "transpose" |