From patchwork Thu Jul 4 14:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 50336 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp3759214vqv; Thu, 4 Jul 2024 07:39:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU+y+hExQOQsTJoDBB5bP897Ton+2zawka56J6D1C3iY5u93phuLxqVaImNjppXcLWkaluGx0uzWwtYxJju7IlVp3fEIuLVle7wJA== X-Google-Smtp-Source: AGHT+IHuiOfkIWng1KBfxQ7cPpVV5WfAf39xM62pY+ClMRpFb6H3RNUj9HsjuXZ2miZizPYRp9l9 X-Received: by 2002:a05:6402:254c:b0:57a:2fe7:6699 with SMTP id 4fb4d7f45d1cf-58e5abdb3b0mr1435761a12.14.1720103950523; Thu, 04 Jul 2024 07:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720103950; cv=none; d=google.com; s=arc-20160816; b=WQvZdPTwkmCJAG73eam3CQRLwMAz8hkdkeeFysAFW852E2jpaiYATkygmq1Wr6fWYM st4RT/YWepSuuOpok81dC6OYJoykZRx83nSF7Ig7MTQk3lnFhaXhsi3WbVQLDn/ZgG6G NVA7j05HthX2S5jVv5O3r8cVBU0AdyODWZJbvIL4cHG3svGsw70AZ/lGFj3LnkHRt61u LNKemb3v73lNCNuZk93ckx0Th+l8DoITUpZDpdnZgnvUTHYBAeScQcFEdw7HIRsc4I52 qhBq1bTG4e/R1Ia425EbnmSZSUYICrfpABop5xJFqhYlCH5R4oGVR1HHn1h+OjjOrk5d oCSw== 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=eYAXC8Quf8+mDvcGArwLwpp+qyh5aCVZu6dB7ftvL4rtfQXu0tmstUlIwrALACXIUF QsNSHfRfJ/nextljQYjQHwWAmw3jGXbMBFRZKdjbZsPkqT4tWh0Hqgl9RXJLTXK7VnUD dT8BKBFE/eZLv3zU+in4jD+zMJjB1tuOr5fBAU9NWucD8Jg0pVkLXHHeLfexeD/iuva+ FytBjNSSBZWMbajoqdEUEa+cX1V1RjkKWrQ+wVy7jI3pc38c7YC/9tSoggIA4jL0h6Ef IFNKWNX3exhUUjBXyTOsr1ZkDmDRQqbl32lwMqWHVbKZBgq0e4YuOlajh2NsqJt/tgQB srXw==; 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=JB17UmTZ; 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 4fb4d7f45d1cf-58c028764fasi2579419a12.546.2024.07.04.07.39.09; Thu, 04 Jul 2024 07:39:10 -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=JB17UmTZ; 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 F10EC68D9BF; Thu, 4 Jul 2024 17:31:19 +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 D3FC468D9AE for ; Thu, 4 Jul 2024 17:31:07 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1720103467; bh=95knvmWuOEtA4tyVc+nJk7D7pMYalEilxDEYKoRMMsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JB17UmTZI0ut8bVqmVxsE0qZBxFSWjGbDYIvBah2Xk9bFB1Su5QkVCExO5KlIFBMt 66MQgmhd69bsVPI4kzc1wRQrMdaEZnr8HZ2e+KBhR1vrfJYkUxiIK+syI1yOYUkBuI YM2AaNbjUe5FCGKjuXKzCog0UGo4ljolXH2fO57Y= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 80DFA408E3; Thu, 4 Jul 2024 16:31:07 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Jul 2024 16:31:00 +0200 Message-ID: <20240704143104.1821386-4-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240704143104.1821386-1-ffmpeg@haasn.xyz> References: <20240704143104.1821386-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/8] 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: vjwA9sFC27ZC 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);