From patchwork Thu Jul 4 11:51:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 50326 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp3658322vqv; Thu, 4 Jul 2024 04:54:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWV/ogNJfMWHKOQINXE2ITbSGNV5GGrp4x+SfVIX4Qu3vzni1C1JoGG/UsvY2dpk6FG8KkRw2f4cSxfslEyoNaIUR+kYZL/+ISpmQ== X-Google-Smtp-Source: AGHT+IGURFcUhZPGByZC9tpvzpyx4dPtaOkXukAhMVtcG9FOtJWzVr9vgKG/rApkQ+MapP0WyAhf X-Received: by 2002:a17:906:288d:b0:a72:83ad:f087 with SMTP id a640c23a62f3a-a77bd9e46a9mr88540466b.10.1720094063840; Thu, 04 Jul 2024 04:54:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720094063; cv=none; d=google.com; s=arc-20160816; b=XX03IjZSb8WfAe5MicCmE/ddAreri1TUjDp2yOc2c4wrkFtqR9x/ce3C1XHIOumXpe cjyFOnrbT3FhrRrWsn1/SEX9I0sMywW2ikWcU5c+TB50t50ud+ovWs4lcRM48gEAYLdv VPpBlfPTSMFF/y8uC/bMze87cQdvMGUKq2NAWvEpPUamNVvYeCMmrqyykON3EOl+DxnI 7FsYRft43Eguc+thcl8KCOANAd2B6ueDQ9bffEB23qRmJDkWzR5Bjv1qr/9XOGmcb4uP VecJk92E6z6tvIoNybKJh281CpVFzv0uKjE8kp/skyQefY2K1UkVNwwyjXjbjmSnZ8QT 8F4g== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=oGhMEOzfMXGtDYddgsjzWvllwAiQGCH/nVqaLtb/1aY=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=d2Z+hULI45eZIc5kmLHwEhTHr/alh9aO+FMnZtJdfc1YOcElYRzcCMlXd8qlvmP+sN 2OtLtoCfMNXnBJYVUzPSaXPBaVWFeTWDNgTCmV73ItxZtX6w637vBkhq6rUBF8s3Z7/r wNMZE3wWIeFLY56/jQtkUAl4PNEdUf64qKGOlCx9VYlkH53ggqHiShO4gSjTBY3Qwmpj dtcT9r5HhQq1uBkcfPxfq4yVfwMeLpYL6yh2+DgQgSrYQU5/pCFYecfTr6s14GVP4Ulf OZOb7uBcbVSDmcIBII9Eo+jwUwGP6fEQdC5M4t8G9TDNLELeTFZ7oUkoPFe7SKeQlM3n 7AGA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=ousrc4C3; 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 a640c23a62f3a-a77c0b02901si28719566b.122.2024.07.04.04.54.23; Thu, 04 Jul 2024 04:54:23 -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=ousrc4C3; 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 0F4F768D953; Thu, 4 Jul 2024 14:54:06 +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 E6B7568DA12 for ; Thu, 4 Jul 2024 14:53:50 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1720094030; bh=95knvmWuOEtA4tyVc+nJk7D7pMYalEilxDEYKoRMMsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ousrc4C34CQyljf2+4GEb/OlCYUwIwts1uQEw7PiIZtfm3iQ35mO8cYrHx/TZxwSh oRJLtrI5iOWsWtNXICfSXJfMRYuVoU6xyahB5C+lPNVznGw4fwaEz6mDoFnuwGETY0 mAGnz6CNovKldj5NwNN97mk+vOxPfYorYDK8z3Xs= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 469F840564; Thu, 4 Jul 2024 13:53:50 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Jul 2024 13:51:59 +0200 Message-ID: <20240704115202.1235954-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240704115202.1235954-1-ffmpeg@haasn.xyz> References: <20240704115202.1235954-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/6] avfilter/swscale: always fix interlaced chroma location 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: EIMvbmI2LnRL From: Niklas Haas The current logic only fixes it when the user does not explicitly specify the chroma location. However, this does not make a lot of sense. Since there is no way to specify this property per-field, it effectively *prevents* the user from being able to correctly scale interlaced frames with top-aligned chroma. It makes more sense to consider the user setting in the progressive case only, and automatically adapt it to the correct interlaced field positions, following the details of the MPEG specification. --- libavfilter/vf_scale.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 841075193e..0b6701673f 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -709,12 +709,18 @@ static int config_props(AVFilterLink *outlink) * chroma positions. MPEG chroma positions are used by convention. * Note that this works for both MPEG-1/JPEG and MPEG-2/4 chroma * locations, since they share a vertical alignment */ - if (desc->log2_chroma_h == 1 && scale->in_v_chr_pos == -513) { - in_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; + if (desc->log2_chroma_h == 1) { + if (in_v_chr_pos == -513) + in_v_chr_pos = 128; /* explicitly default missing info */ + in_v_chr_pos += 256 * (i == 2); /* offset by one luma row for odd rows */ + in_v_chr_pos >>= i > 0; /* double luma row distance */ } - if (outdesc->log2_chroma_h == 1 && scale->out_v_chr_pos == -513) { - out_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; + if (outdesc->log2_chroma_h == 1) { + if (out_v_chr_pos == -513) + out_v_chr_pos = 128; + out_v_chr_pos += 256 * (i == 2); + out_v_chr_pos >>= i > 0; } av_opt_set_int(s, "src_h_chr_pos", scale->in_h_chr_pos, 0);