mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-06-16 04:32:47 +02:00
avfilter/vf_libplacebo: rotate all input frames, not just reference
In commit6e0034ab7e, 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:6e0034ab7e
This commit is contained in:
+10
-11
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user