diff mbox

[FFmpeg-devel] doc/filters: Correct scale doc regarding w/h <= 0

Message ID 20170606072706.85743-1-kmark937@gmail.com
State Superseded
Headers show

Commit Message

Kevin Mark June 6, 2017, 7:27 a.m. UTC
According to libavfilter/scale.c, if the width and height are both
less than or equal to 0 then the input size is used for both
dimensions. It does not need to be -1. -1:-1 is the same as 0:0 which
is the same as -10:-42, etc.

if (w < 0 && h < 0)
    eval_w = eval_h = 0;

Signed-off-by: Kevin Mark <kmark937@gmail.com>
---
 doc/filters.texi | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Moritz Barsnick June 6, 2017, 11:59 a.m. UTC | #1
On Tue, Jun 06, 2017 at 03:27:06 -0400, Kevin Mark wrote:
> According to libavfilter/scale.c, if the width and height are both
> less than or equal to 0 then the input size is used for both
> dimensions. It does not need to be -1. -1:-1 is the same as 0:0 which
> is the same as -10:-42, etc.

This makes it obvious that the paragraph following the one you fixed is
a bit misleading (to me):

    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.

This is true only if *exactly* one of the two values is "-n with n > 1".
(It also doesn't apply to "-1:-2". Good luck finding words to describe
this behavior. ;-))

Just nitpicking,
Moritz
Kevin Mark June 6, 2017, 8:40 p.m. UTC | #2
Hey Moritz,

Thanks for the feedback.

On Tue, Jun 6, 2017 at 7:59 AM, Moritz Barsnick <barsnick@gmx.net> wrote:
> This makes it obvious that the paragraph following the one you fixed is
> a bit misleading (to me):
>
>     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.
>
> This is true only if *exactly* one of the two values is "-n with n > 1".
> (It also doesn't apply to "-1:-2". Good luck finding words to describe
> this behavior. ;-))

Haha, you're right. The best approach seems to be involve removing the
paragraph about the -1 stuff (since it's technically -n) and expand
the -n paragraph to include -1. So something like:

If the width value is 0, the input width is used for the output. If the
height value is 0, the input height is used for the output.

If one and only one of the values is -n with n >= 1, the scale filter
will 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.

If both values are -n with n >= 1, the behavior will be identical to
both values being set to 0 as previously detailed.

-

I noticed the z-scale documentation is very similar. I might need to
look at that too.

Thanks,
Kevin
Kevin Mark June 12, 2017, 5:56 a.m. UTC | #3
I screwed up my git-send-email. Please ignore this patch as I already
submitted what should be an identical one on June 7th. My apologies.

On Mon, Jun 12, 2017 at 1:51 AM, Kevin Mark <kmark937@gmail.com> wrote:
> The input width and height is known at parse time so there's no
> reason ow/oh should not be usable when using 0 as the width or
> height expression.
>
> Previously in "scale=0:ow" ow would be set to "0" which works,
> conveniently, as "scale=0:0" is perfectly valid input but this breaks
> down when you do something like "scale=0:ow/4" which one could
> reasonably expect to work as well, but does not as ow is 0 not the
> real value.
>
> This change handles the 0 case for w/h immediately so the ow/oh
> variables work as expected. Consequently, the rest of the code does
> not need to handle 0 input. w/h will always be > 0 or < 0.
>
> Signed-off-by: Kevin Mark <kmark937@gmail.com>
> ---
>  libavfilter/scale.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/libavfilter/scale.c b/libavfilter/scale.c
> index 03745ddcb8..a6c32e3978 100644
> --- a/libavfilter/scale.c
> +++ b/libavfilter/scale.c
> @@ -158,19 +158,19 @@ int ff_scale_eval_dimensions(void *log_ctx,
>      av_expr_parse_and_eval(&res, (expr = w_expr),
>                             names, var_values,
>                             NULL, NULL, NULL, NULL, NULL, 0, log_ctx);
> -    eval_w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
> +    eval_w = var_values[VAR_OUT_W] = var_values[VAR_OW] = (int) res == 0 ? inlink->w : res;
>
>      if ((ret = av_expr_parse_and_eval(&res, (expr = h_expr),
>                                        names, var_values,
>                                        NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0)
>          goto fail;
> -    eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
> +    eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = (int) res == 0 ? inlink->h : res;
>      /* evaluate again the width, as it may depend on the output height */
>      if ((ret = av_expr_parse_and_eval(&res, (expr = w_expr),
>                                        names, var_values,
>                                        NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0)
>          goto fail;
> -    eval_w = res;
> +    eval_w = (int) res == 0 ? inlink->w : res;
>
>      w = eval_w;
>      h = eval_h;
> @@ -186,13 +186,10 @@ int ff_scale_eval_dimensions(void *log_ctx,
>          factor_h = -h;
>      }
>
> -    if (w < 0 && h < 0)
> -        eval_w = eval_h = 0;
> -
> -    if (!(w = eval_w))
> +    if (w < 0 && h < 0) {
>          w = inlink->w;
> -    if (!(h = eval_h))
>          h = inlink->h;
> +    }
>
>      /* 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
> --
> 2.13.1
>
diff mbox

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index 65eef89d07..b9d6eafc74 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -12125,12 +12125,13 @@  the complete list of scaler options.
 Set the output video dimension expression. Default value is the input
 dimension.
 
-If the value is 0, the input width is used for the output.
+If the width value is 0, the input width is used for the output. If the
+height value is 0, the input height is used for the output.
 
 If one of the values is -1, the scale filter will use a value that
 maintains the aspect ratio of the input image, calculated from the
-other specified dimension. If both of them are -1, the input size is
-used
+other specified dimension. If both of them are negative, the behavior
+will be identical to both values being set to 0 as explained above.
 
 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