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); - } } } }