From patchwork Tue Jun 20 15:12:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 42258 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp1463582pzb; Tue, 20 Jun 2023 08:13:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6B2kpg2xEhJlMzFQos3qQVZmtyOrdDpl2sAr40QnCfMEbI7Z2L8pPNSiP+NvmG85nkLbjQ X-Received: by 2002:a05:6402:517:b0:51a:53e0:843e with SMTP id m23-20020a056402051700b0051a53e0843emr5363997edv.23.1687273980898; Tue, 20 Jun 2023 08:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687273980; cv=none; d=google.com; s=arc-20160816; b=kKO78ERtqb0CiQcNNDUztrN7rnNJZri/9zMY+GJpBGanOE3812whuqOvPOwBZ8Yj1l w+Z5HZOQQ0An/1/ciWccrYJ1HVXyugPQu1FRW4GQx2U8ru7XXB2zHdvfwLM/WgduusYp RPlNQ/wgDNWPTRs2CRfE0aYf1dHoR+gPXvA86lu/njANtV5naUEpnk3AdHDrzMIC1JqB pKCQ7ALYzfrjEZgZp78VXDtQm2pSy6DRgUey5rPJtPeYJFx73L816FZZnRhBDqtu0Nqu UcN2gufpOWDPX1c4pSQFyyzm8lRUdFnqWE4pF5Kf8jpGFVJKJ3Q1H4UBIFKchhHpdp9U jHEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=bUL27BwViMjCxw3mBttu2Yk/2vj3eYYbYoFJXsC12x0=; b=xftE1M1drZoxHuywjmog9Icq/WMCR9G9XSwGrxHfPg461jCYxQxid5naHb4w5jMiCd UqwSiRbF71o72slA/1MKxth5gUOwITX+Fwxwsk51100rZzZZKooar3OMwqNVw3ZEjArI so3h1qB05reuMLVbGAkY9q2NltDUE7gptp15l/LW/prvGHTbUVmv6XDkK3xvETurELix 2pKqzSBfqZoV9pNsp/7gPbswbEwt4NXNlWcEHPe6YeNhVPiKWBw1eoND90z5T3rq9M2j Z2CYzVvX4fsbKMbCyhmKYqy+iUfUwcQcUT882Ja382vceNdPg2a0e2KvPU643C1MB9yn jAzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=b7hyuJnb; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b15-20020aa7cd0f000000b0051a2d16339dsi1277949edw.436.2023.06.20.08.13.00; Tue, 20 Jun 2023 08:13:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=b7hyuJnb; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 57FA368B14C; Tue, 20 Jun 2023 18:12:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1886A68B14C for ; Tue, 20 Jun 2023 18:12:51 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id CDA2140648; Tue, 20 Jun 2023 17:12:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1687273970; bh=/fk7EKBOGHl7oUjdn6uNkLRSmi/bp806Mn+VGINrZpM=; h=From:To:Cc:Subject:Date:From; b=b7hyuJnbosdggqiSaF+7ybBBhd1ndPgste2AfQ4uqqz5jaokg7+BoDnjXDGNzpQj+ asN0ayefkyHaZ4RTUMDpMraokgkAyi0bLqklqqDn+AJ4qr1WMnkDsL77WnbMBcuOAy vBcXpIRItOJ2ih58lSPhcy85qIyhN0pWafpK/3X8= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Jun 2023 17:12:48 +0200 Message-ID: <20230620151248.21755-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavfi/vf_libplacebo: simplify SAR normalization X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KWarKH0mdsSs From: Niklas Haas The old logic was trying to be excessively clever in "deducing" that the user wanted to stretch/scale the image when ow/oh differed from iw/ih aspect ratio. But this is almost surely unintended except in pathological cases, and in those cases users should simply disable normalize_sar and do all the stretching/scaling logic themselves. This is especially important in multi-input mode, where the canvas may be vastly different from the input dimensions of any stream. Also, passing through input 0 SAR in multi-input mode is arbitrary and nearly useless, so again force output SAR to 1:1 here. --- libavfilter/vf_libplacebo.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 0f7c6481925..e58183a5caa 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -160,7 +160,6 @@ typedef struct LibplaceboContext { // Parsed expressions for input/output crop AVExpr *crop_x_pexpr, *crop_y_pexpr, *crop_w_pexpr, *crop_h_pexpr; AVExpr *pos_x_pexpr, *pos_y_pexpr, *pos_w_pexpr, *pos_h_pexpr; - AVRational target_sar; float pad_crop_ratio; float corner_rounding; int force_original_aspect_ratio; @@ -795,9 +794,9 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, target->crop.y0 = av_expr_eval(s->pos_y_pexpr, s->var_values, NULL); target->crop.x1 = target->crop.x0 + s->var_values[VAR_POS_W]; target->crop.y1 = target->crop.y0 + s->var_values[VAR_POS_H]; - - if (s->target_sar.num) { - float aspect = pl_rect2df_aspect(&target->crop) * av_q2d(s->target_sar); + if (s->normalize_sar) { + float aspect = pl_rect2df_aspect(&image->crop); + aspect *= av_q2d(in->link->sample_aspect_ratio); pl_rect2df_aspect_set(&target->crop, aspect, s->pad_crop_ratio); } } @@ -1188,7 +1187,6 @@ static int libplacebo_config_output(AVFilterLink *outlink) const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format); AVHWFramesContext *hwfc; AVVulkanFramesContext *vkfc; - AVRational scale_sar; /* Frame dimensions */ RET(ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink, @@ -1198,20 +1196,15 @@ static int libplacebo_config_output(AVFilterLink *outlink) s->force_original_aspect_ratio, s->force_divisible_by); - scale_sar = (AVRational){outlink->h * inlink->w, outlink->w * inlink->h}; - if (inlink->sample_aspect_ratio.num) - scale_sar = av_mul_q(scale_sar, inlink->sample_aspect_ratio); - - if (s->normalize_sar) { - /* Apply all SAR during scaling, so we don't need to set the out SAR */ + if (s->normalize_sar || s->nb_inputs > 1) { + /* SAR is normalized, or we have multiple inputs, set out to 1:1 */ outlink->sample_aspect_ratio = (AVRational){ 1, 1 }; - s->target_sar = scale_sar; } else { /* This is consistent with other scale_* filters, which only * set the outlink SAR to be equal to the scale SAR iff the input SAR * was set to something nonzero */ if (inlink->sample_aspect_ratio.num) - outlink->sample_aspect_ratio = scale_sar; + outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; } /* Frame rate */