PR #21204 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21204
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21204.patch

In commit 6e0034ab7e46429731fec6d2c390fa536a9157ad, the image crop adjustment
was moved after the fitting logic. However, this moved the adjustment inside the
`if (src == ref)` branch, thus missing applying the same un-rotation to input
frames that are *not* the reference frame.

Fix this by pulling the logic back out of the branch again. While we could just
move it after the fitting logic, I think it's more clear to the intent of the
code to just preserve the (rotated) crop rect as a separate variable
`crop_orig`.

Fixes: 6e0034ab7e46429731fec6d2c390fa536a9157ad


>From 4ac3b3a6da54ee165a9e6310f34dfb367712a20b Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Mon, 15 Dec 2025 11:29:58 +0100
Subject: [PATCH] avfilter/vf_libplacebo: rotate all input frames, not just
 reference

In commit 6e0034ab7e46429731fec6d2c390fa536a9157ad, the image crop adjustment
was moved after the fitting logic. However, this moved the adjustment inside the
`if (src == ref)` branch, thus missing applying the same un-rotation to input
frames that are *not* the reference frame.

Fix this by pulling the logic back out of the branch again. While we could just
move it after the fitting logic, I think it's more clear to the intent of the
code to just preserve the (rotated) crop rect as a separate variable
`crop_orig`.

Fixes: 6e0034ab7e46429731fec6d2c390fa536a9157ad
---
 libavfilter/vf_libplacebo.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index b1788565bf..c8015a9641 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -917,6 +917,15 @@ static void update_crops(AVFilterContext *ctx, 
LibplaceboInput *in,
         image->crop.x1 = image->crop.x0 + s->var_values[VAR_CROP_W];
         image->crop.y1 = image->crop.y0 + s->var_values[VAR_CROP_H];
 
+        const pl_rect2df crop_orig = image->crop;
+        pl_rotation rot_total = PL_ROTATION_360 + image->rotation - 
target->rotation;
+        if (rot_total % PL_ROTATION_180 == PL_ROTATION_90) {
+            /* Libplacebo expects the input crop relative to the actual frame
+             * dimensions, so un-transpose them here */
+            FFSWAP(float, image->crop.x0, image->crop.y0);
+            FFSWAP(float, image->crop.x1, image->crop.y1);
+        }
+
         if (src == ref) {
             /* Only update the target crop once, for the 'reference' frame */
             target->crop.x0 = av_expr_eval(s->pos_x_pexpr, s->var_values, 
NULL);
@@ -924,16 +933,13 @@ static void update_crops(AVFilterContext *ctx, 
LibplaceboInput *in,
             target->crop.x1 = target->crop.x0 + s->var_values[VAR_POS_W];
             target->crop.y1 = target->crop.y0 + s->var_values[VAR_POS_H];
 
-
             /* Effective visual crop */
             double sar_in = q2d_fallback(inlink->sample_aspect_ratio, 1.0);
             double sar_out = q2d_fallback(outlink->sample_aspect_ratio, 1.0);
-
-            pl_rotation rot_total = PL_ROTATION_360 + image->rotation - 
target->rotation;
             if (rot_total % PL_ROTATION_180 == PL_ROTATION_90)
                 sar_in = 1.0 / sar_in;
 
-            pl_rect2df fixed = image->crop;
+            pl_rect2df fixed = crop_orig;
             pl_rect2df_stretch(&fixed, sar_in / sar_out, 1.0);
 
             switch (s->fit_mode) {
@@ -956,13 +962,6 @@ static void update_crops(AVFilterContext *ctx, 
LibplaceboInput *in,
             case FIT_SCALE_DOWN:
                 pl_rect2df_aspect_fit(&target->crop, &fixed, 0.0);
             }
-
-            if (rot_total % PL_ROTATION_180 == PL_ROTATION_90) {
-                /* Libplacebo expects the input crop relative to the actual 
frame
-                 * dimensions, so un-transpose them here */
-                FFSWAP(float, image->crop.x0, image->crop.y0);
-                FFSWAP(float, image->crop.x1, image->crop.y1);
-            }
         }
     }
 }
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to