Commit 682ddb89 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge branch 'scale-filter-factor' of https://github.com/lkiesow/FFmpeg

* 'scale-filter-factor' of https://github.com/lkiesow/FFmpeg:
  Documentation for scale filter factor
  Documentation for scale filter factor
  Fixed factor for scale filter
  Factors for scale filter
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 018e2b57 c49b0360
...@@ -6911,6 +6911,11 @@ maintains the aspect ratio of the input image, calculated from the ...@@ -6911,6 +6911,11 @@ maintains the aspect ratio of the input image, calculated from the
other specified dimension. If both of them are -1, the input size is other specified dimension. If both of them are -1, the input size is
used used
If one of the values is -n with n > 1, the scale filter will also use a value
that maintains the aspect ratio of the input image, calculated from the other
specified dimension. After that it will, however, make sure that the calculated
dimension is divisible by n and adjust the value if necessary.
See below for the list of accepted constants for use in the dimension See below for the list of accepted constants for use in the dimension
expression. expression.
......
...@@ -81,6 +81,7 @@ typedef struct { ...@@ -81,6 +81,7 @@ typedef struct {
* New dimensions. Special values are: * New dimensions. Special values are:
* 0 = original width/height * 0 = original width/height
* -1 = keep original aspect * -1 = keep original aspect
* -N = try to keep aspect but make sure it is divisible by N
*/ */
int w, h; int w, h;
char *size_str; char *size_str;
...@@ -236,6 +237,7 @@ static int config_props(AVFilterLink *outlink) ...@@ -236,6 +237,7 @@ static int config_props(AVFilterLink *outlink)
double var_values[VARS_NB], res; double var_values[VARS_NB], res;
char *expr; char *expr;
int ret; int ret;
int factor_w, factor_h;
var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
...@@ -270,11 +272,22 @@ static int config_props(AVFilterLink *outlink) ...@@ -270,11 +272,22 @@ static int config_props(AVFilterLink *outlink)
w = scale->w; w = scale->w;
h = scale->h; h = scale->h;
/* sanity check params */ /* Check if it is requested that the result has to be divisible by a some
if (w < -1 || h < -1) { * factor (w or h = -n with n being the factor). After we got the factor,
av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n"); * we set w/h back to -1 so that the automatic scaling is done. */
return AVERROR(EINVAL); factor_w = 1;
factor_h = 1;
if (w < -1) {
factor_w = -w;
w = -1;
scale->w = -1;
} }
if (h < -1) {
factor_h = -h;
h = -1;
scale->h = -1;
}
if (w == -1 && h == -1) if (w == -1 && h == -1)
scale->w = scale->h = 0; scale->w = scale->h = 0;
...@@ -287,6 +300,14 @@ static int config_props(AVFilterLink *outlink) ...@@ -287,6 +300,14 @@ static int config_props(AVFilterLink *outlink)
if (h == -1) if (h == -1)
h = av_rescale(w, inlink->h, inlink->w); h = av_rescale(w, inlink->h, inlink->w);
/* Make sure that the result is divisible by the factor we determined
* earlier. If no factor was set, it is nothing will happen as the default
* factor is 1 */
w = (w / factor_w) * factor_w;
h = (h / factor_h) * factor_h;
/* Note that force_original_aspect_ratio may overwrite the previous set
* dimensions so that it is not divisible by the set factors anymore. */
if (scale->force_original_aspect_ratio) { if (scale->force_original_aspect_ratio) {
int tmp_w = av_rescale(h, inlink->w, inlink->h); int tmp_w = av_rescale(h, inlink->w, inlink->h);
int tmp_h = av_rescale(w, inlink->h, inlink->w); int tmp_h = av_rescale(w, inlink->h, inlink->w);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment