From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 25FAB4D11D for ; Mon, 10 Nov 2025 11:41:12 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'hDhtV134wejc0ZkU4pcMDIiBUSUzbQCtdbZFGX8Zksg=', expected b'dElnCDCHO7b9qchXPpa5sdFnT5r6Lr/+cEqJwZzymEQ=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1762774856; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=hDhtV134wejc0ZkU4pcMDIiBUSUzbQCtdbZFGX8Zksg=; b=2j8QSZSy8t4LSWAt73VzXSzlbfPB85jqek7+PhQ5ufDIMt+OAobPIvmWvB3IQXF2Lgli/ 3aO7lsAnKLIumlQoFmEG33GAyBFJiGIj4CFidPzd7iYaz4kcvLw47nZ/iDiA0wYnDjuKxES k2S9gQO2U1qSUppa5qeXH8TZ+UARQImC+cFqtrM3QVgxl+0gFxeSh2QpxpmdrQsNat4ELb5 edUBc/HUVw1vZ3fHI+bdAORMu1ELV3tDZkmoBqRGoXHGmu7D6TFSJ/uLSmpws0FPqo1sN1q 0n0UcvLepcBWXX+a1QkrPeMYbkY426kJdHwHkzxVAvkK+vnmDL/XWF+ES0gg== Received: from [172.19.0.2] (unknown [172.19.0.2]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id D5C2268FBFE; Mon, 10 Nov 2025 13:40:56 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1762774837; b=l7GytqtAPVg5smK4Aqze9AjoDuoa4ehfxz9HVQytj+k1kb4dlNB2LtlDFa8JGGY4sTQKV R3WR5BH8a9m5kLhEUtcjhPe8fELhd/fox/WdfpiyhkkRlR7vBVutJ4PL2KhIsCA2sT+ediy gpgmHTTwtNruUJ8ucDngNZ4l4SJOnbzJSoyk4K7sQsZoc3En5j+o5Zi59JAsQDfZLRT1giA xCQxD5sDOWrK2F5vnKBunfcL7ONGDLEhcUNvAjZB4a8VjEpvHOApuy6lGREmv0/UAkpjBbB 07LT9ZEiq4ZU5jvoIUbeARJHDZ/bv0WHqx5VHGvc+rfCGQ8kTJ3dKyQqJwLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1762774837; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=OW/7IatIK1JYDjLczMMBmjM3BaQYR9oyL3u8doasNNM=; b=OGAxhOZf2VTi3esyNDIvOXIxLgkFX6chUucmcgl6xLSTdQrWU6fzpmMjKRWY9ohO8/X/7 cfIv940nOuDvxcY6SRgmX9v+K7esP3VdzjUKlRomuLnwP6RjdYHQSP5OCO/8y7+lx6h4zWS DJnQiAQQxhoSNFPY3FSAIkydIuCQfJ+RWomB9M11GRSHjvbilx8pp2gAjRh8HvvRoGdfQAg jQwPmv64dT75vLGSV5D2pbnSRHaqxlAFynBocRGNclH/3ecETvbkiH5A/q/jblV7IeyeVVa Xk0BJTg3/lV2/VleGY6/M+GudLdUwuwOM749uh5rMno41Id2zLodoSfWfX9Q== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1762774828; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=dElnCDCHO7b9qchXPpa5sdFnT5r6Lr/+cEqJwZzymEQ=; b=WWOsQUABhBAYlY/cC+djsRUmiVKmeIHKB6FL2rDYmi6QjSSgh/Z3jb7FIVAJqSNG9SUP5 bbz+zG+Ytvahjmfb+UntNXPy/pVn8VQs0+iaqM4ERzOcI9v4O7WcPu0TIb6wmL5eC4mFGo0 VaFP0j++XjkM23I6SAnR2yI6qta9VKJP4Krm80VuGOJaXFycOLQirBULUSHQXpM3uPpy9Q8 E4K65pOuNqnkxysSg0z+NFm9KxTNhAJ6+98hYHq/+nS9UoPRJIyQmCMTb0VzQtrSTBqN6OG RIgXjDF0C8TRtiTWyzhnvq7JJztnHCv3Sc2WXGxgwcrduA0bCEeA9Fhi+0bw== Received: from 188d6d40ca7a (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id BB93F68FA16 for ; Mon, 10 Nov 2025 13:40:28 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Nov 2025 11:40:28 -0000 Message-ID: <176277482896.25.2442927936176169093@2cb04c0e5124> Message-ID-Hash: 46QO4J4FKSQPNU3JANGEQ3VZ6A3BEXXI X-Message-ID-Hash: 46QO4J4FKSQPNU3JANGEQ3VZ6A3BEXXI X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avfilter/vf_libplacebo: fix a more edge cases when combining rotated video with custom fit modes (PR #20884) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Niklas Haas via ffmpeg-devel Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20884 opened by Niklas Haas (haasn) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20884 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20884.patch This whole logic is beginning to get rather annoying and I'm starting to feel like a whole redesign is needed. >>From 2cc48b34340738f30fc9daa2a61a60e9cf1eb19d Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Mon, 10 Nov 2025 12:32:32 +0100 Subject: [PATCH 1/3] avfilter/vf_libplacebo: un-rotate image crop after fitting When combining rotation with a FIT_ mode other than FIT_FILL, the fitting logic was operating on the un-rotated rects, when it should have been operating on the rotated (output) rects. --- libavfilter/vf_libplacebo.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 42501c51f2..5a615aceed 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -913,14 +913,6 @@ 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_rotation rot_total = image->rotation - target->rotation; - if ((rot_total + PL_ROTATION_360) % 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); @@ -955,6 +947,14 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, case FIT_SCALE_DOWN: pl_rect2df_aspect_fit(&target->crop, &fixed, 0.0); } + + const pl_rotation rot_total = image->rotation - target->rotation; + if ((rot_total + PL_ROTATION_360) % 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 >>From c56c5f80f5256be33453b2aaad06e42132aba09d Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Mon, 10 Nov 2025 12:36:33 +0100 Subject: [PATCH 2/3] avfilter/vf_libplacebo: fix fitting math when SAR is undefined --- libavfilter/vf_libplacebo.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 5a615aceed..6ae7289265 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -920,9 +920,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 */ - const float w_adj = av_q2d(inlink->sample_aspect_ratio) / - av_q2d(outlink->sample_aspect_ratio); + double sar_in = inlink->sample_aspect_ratio.num ? + av_q2d(inlink->sample_aspect_ratio) : 1.0; + double sar_out = outlink->sample_aspect_ratio.num ? + av_q2d(outlink->sample_aspect_ratio) : 1.0; + const float w_adj = sar_in / sar_out; pl_rect2df fixed = image->crop; pl_rect2df_stretch(&fixed, w_adj, 1.0); -- 2.49.1 >>From 16391108ba87bd735c1233276afa5699b2f3b657 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Mon, 10 Nov 2025 12:38:11 +0100 Subject: [PATCH 3/3] avfilter/vf_libplacebo: also rotate SAR when fitting --- libavfilter/vf_libplacebo.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 6ae7289265..1a9dc05620 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -926,10 +926,13 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, av_q2d(inlink->sample_aspect_ratio) : 1.0; double sar_out = outlink->sample_aspect_ratio.num ? av_q2d(outlink->sample_aspect_ratio) : 1.0; - const float w_adj = sar_in / sar_out; + + 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_stretch(&fixed, w_adj, 1.0); + pl_rect2df_stretch(&fixed, sar_in / sar_out, 1.0); switch (s->fit_mode) { case FIT_FILL: @@ -952,8 +955,7 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, pl_rect2df_aspect_fit(&target->crop, &fixed, 0.0); } - const pl_rotation rot_total = image->rotation - target->rotation; - if ((rot_total + PL_ROTATION_360) % PL_ROTATION_180 == PL_ROTATION_90) { + 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); -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org