From patchwork Wed May 29 12:06:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerion Entrup X-Patchwork-Id: 49344 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:8f0d:0:b0:460:55fa:d5ed with SMTP id i13csp590561vqu; Wed, 29 May 2024 05:07:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWd5sFtk1oSnMF5tSaP7ujw5Wo6IJCs3hIq2CmrYKLcJoxPst/2J7GBc/lPdM9kzQbuAEA/hKuUSwvTSTvXTeHct35bBXCk1Sj6vg== X-Google-Smtp-Source: AGHT+IEB//Q1mhEwLDmITGFX4wnO0Psrerb2bY+FaJwAoBDOm+CZmYXviqMmDZ9TbfBhC2Q2Tc0/ X-Received: by 2002:a50:cc8f:0:b0:572:d1e1:b4b3 with SMTP id 4fb4d7f45d1cf-578519709eamr10028338a12.7.1716984443923; Wed, 29 May 2024 05:07:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716984443; cv=none; d=google.com; s=arc-20160816; b=tpqPnO9mMwkqHvPY2p4wUxBE8CdYAR/1C78dU68gifCM+QjyyY7RCtFBXKtDpGWIgH nJqYgwGfB/qAURGhQtPJHSKUnOM4VDruvlD8WzRer4XBZuvw6Fms+xKM36LMC6glmHH4 oiZNoRsfU+pReCDPCG44NBuBK7mLofl59qnns1YUQ8CWHh3eeHw/p6XFzZe1gbFhQ9lC TIEDPCY3grom+Y9Uxy8IwK//cKMOFicMXA+gkpDjz41eKr3+0WmVtjLtSRPgRKbQynHI RJAqU+ifVsaryYSsA9vgIVynoUMISdXzwuKxD8388+pygBz3656m7CyAvatKyFgqYiqh 7VNA== 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=Q2nyK24BTskBb0r8Z11wp/Mio8ezgzGWifb/TDchrQU=; fh=6LVlYnaY8ZoxjLFIeeGaXxpgN2Z6G7plFIYEzwDBHt4=; b=Sg8EwU7OO8DjUO/8dKW0Hdy6MNrSTo9bKcDkYOpCOfBnOjz8lBy06R8WsMFj5/v1xT xUBi90Y3CFUVKKLyD1W6enSXaNxyyvYcfTm62GLGc6JGxDkXFUajboM9UB291UbPnlLm YyPCKAFrepcnYUa8v/q6tOnAxL4vxv+VHos3oGKQETfkTds/nYu9lV6fKbNw51lDSeFr a4lZIlTk9/DII/KQ/WQEK8j/PxMUUlI2Y+Zav7xZE5jQrJGr4Z+JFern7GnlhHygNAHL 1DfJVw+7Z3iFD5CNJ2dvpOXkcwC1KpeIQ+jk9lGpjSCXMU7Mceh2SilScyE7Fc9jvZNl 4RYw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@flump.de header.s=mail header.b=THcn1tOJ; 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-578610eb692si5576937a12.568.2024.05.29.05.07.23; Wed, 29 May 2024 05:07: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=@flump.de header.s=mail header.b=THcn1tOJ; 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 59D2868D3A7; Wed, 29 May 2024 15:07:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from flump.de (flump.de [185.163.118.210]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E4CCE68D3C5 for ; Wed, 29 May 2024 15:07:13 +0300 (EEST) Received: from falbala.sra.uni-hannover.de (unknown [130.75.33.21]) by flump.de (Postfix) with ESMTPSA id 3EB34F4D868; Wed, 29 May 2024 14:07:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flump.de; s=mail; t=1716984433; bh=ibyjaZFeD9xgxiblp9n8upTlQRYagOedIFfM5VvvXUY=; h=From:To:Cc:Subject:Date; b=THcn1tOJ/FhdvwhWBOAYP5d7ZiVmwSwukjbEh8rJTtzZZA9gl3sigcPs4zWZHaA3A KVXxkagw8EZ02t7JOso/DmiGJce+7roCX8wYfbROEUfW4d2Xwf57+eLvlm9UKOVQBr afF4dZUS73RJJJKKX1I3o8r5Q/WYI+fVFKkyfQKg= From: Gerion Entrup To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 May 2024 14:06:07 +0200 Message-ID: <20240529120607.517822-1-gerion.entrup@flump.de> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavfilter/signature_lookup: fix jaccard distance 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: Sachin Tilloo Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GlDVmk/3HJxf Actually, the jaccard distance is defined as D = 1 - intersect / union. Additionally, the distance value is compared against a constant that must be between 0 and 1, which is not the case here. Both facts together has led to the fact, that the function always returned a matching course signature. To leave the constant intact and to avoid floating point computation, this commit multiplies with 1 << 16 making the constant effectively 9000 / (1<<16) =~ 0.14. Reported-by: Sachin Tilloo Reviewed-by: Sachin Tilloo Tested-by: Sachin Tilloo --- libavfilter/signature_lookup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavfilter/signature_lookup.c b/libavfilter/signature_lookup.c index b39a3e225b..b90b63f3f2 100644 --- a/libavfilter/signature_lookup.c +++ b/libavfilter/signature_lookup.c @@ -127,9 +127,10 @@ static int get_jaccarddist(SignatureContext *sc, CoarseSignature *first, CoarseS { int jaccarddist, i, composdist = 0, cwthcount = 0; for (i = 0; i < 5; i++) { - if ((jaccarddist = intersection_word(first->data[i], second->data[i])) > 0) { + if ((jaccarddist = (1 << 16) * intersection_word(first->data[i], second->data[i])) > 0) { jaccarddist /= FFMAX(union_word(first->data[i], second->data[i]), 1); } + jaccarddist = (1 << 16) - jaccarddist; if (jaccarddist >= sc->thworddist) { if (++cwthcount > 2) { /* more than half (5/2) of distances are too wide */