Commit 9bfc89ffd4 for ffmpeg

commit 9bfc89ffd4b8dd7edbe11954e99c67cfeb4e3b7b
Author: Michael Niedermayer <michael@niedermayer.cc>
Date:   Thu Nov 12 22:59:05 2026 +0100

    avfilter/scale_eval: factor the evaluation of a dimension out

    No functional change.

diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c
index 62e4e2de54..1778136bc2 100644
--- a/libavfilter/scale_eval.c
+++ b/libavfilter/scale_eval.c
@@ -55,6 +55,21 @@ enum var_name {
     VARS_NB
 };

+static int eval_dimension(void *log_ctx, const char *expr, const double *var_values,
+                          int in_dimension, int *out_dimension)
+{
+    double res;
+    int ret = av_expr_parse_and_eval(&res, expr, var_names, var_values,
+                                     NULL, NULL, NULL, NULL, NULL, 0, log_ctx);
+    if (ret < 0)
+        return ret;
+    if (!(res >= INT32_MIN && res <= INT32_MAX))
+        return AVERROR(EINVAL);
+
+    *out_dimension = (int) res == 0 ? in_dimension : (int) res;
+    return 0;
+}
+
 int ff_scale_eval_dimensions(void *log_ctx,
     const char *w_expr, const char *h_expr,
     AVFilterLink *inlink, AVFilterLink *outlink,
@@ -86,26 +101,13 @@ int ff_scale_eval_dimensions(void *log_ctx,
                            NULL, NULL, NULL, NULL, NULL, 0, log_ctx);
     var_values[VAR_OUT_W] = var_values[VAR_OW] = res == 0 ? inlink->w : trunc(res);

-    if ((ret = av_expr_parse_and_eval(&res, (expr = h_expr),
-                                      var_names, var_values,
-                                      NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0)
-        goto fail;
-    if (!(res >= INT32_MIN && res <= INT32_MAX)) {
-        ret = AVERROR(EINVAL);
+    if ((ret = eval_dimension(log_ctx, (expr = h_expr), var_values, inlink->h, &eval_h)) < 0)
         goto fail;
-    }

-    eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = (int) res == 0 ? inlink->h : (int) res;
+    var_values[VAR_OUT_H] = var_values[VAR_OH] = eval_h;
     /* evaluate again the width, as it may depend on the output height */
-    if ((ret = av_expr_parse_and_eval(&res, (expr = w_expr),
-                                      var_names, var_values,
-                                      NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0)
+    if ((ret = eval_dimension(log_ctx, (expr = w_expr), var_values, inlink->w, &eval_w)) < 0)
         goto fail;
-    if (!(res >= INT32_MIN && res <= INT32_MAX)) {
-        ret = AVERROR(EINVAL);
-        goto fail;
-    }
-    eval_w = (int) res == 0 ? inlink->w : (int) res;

     *ret_w = eval_w;
     *ret_h = eval_h;