From patchwork Sat Apr 1 17:47:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chema Gonzalez X-Patchwork-Id: 40966 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1609500pzb; Sat, 1 Apr 2023 10:47:54 -0700 (PDT) X-Google-Smtp-Source: AKy350aSAwQ0CAUlMzXc3B8UoBzj546q73iv0GUxvHXuO7wbguhTy6vIdLqUlTkfipV7dcl/ZHJC X-Received: by 2002:a17:907:a586:b0:946:c60b:470b with SMTP id vs6-20020a170907a58600b00946c60b470bmr18239726ejc.63.1680371274760; Sat, 01 Apr 2023 10:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680371274; cv=none; d=google.com; s=arc-20160816; b=LzxwJM3YaYuootepzEJGE5aX7TFX3vRosBdRf2Ki8txYRL5BTz0kE0t6hM8rfBlp75 3ZYu2CbQKU2NFb1wyIgrcLFg28UgmeAJWEq8oc/KAlRBnBSIszrHX5JoQZiC+WGXwUUk 67pPg3cK3YSsH5elwNePN7iAE4qDdbcDOTbxRHVrmBMSq+PsZ5vXWQK9FR2BGhknbEfi c7zKIu1cVI4e62OAq6kysMvYtbWf2SJ59m1uW8tCKBfrdO2xGzt6ItShMdWqgiq/zUUG 38EmoRdX7Ur3NqfzxT7vyO7yAL2jOzp2S4Epqfmq4fV3N8YS+PFn50m/4CD0FMolVC6V 3vsA== 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=gsyRo5KaKjna5EDnvtPAZiHk5YbebIEyB0iHKZCC4Y4=; b=TACygvQazikvQArz0nIseLeLednKCcnH4ytaPzGm0kZ+OY3b+CfqPjTXNA7asZYf3B 4jFDMddQg11yAuZtNa+KgakU4KpkY9n0EDR4JzEUqghG++cQzrpVNzE2rgPzp8X7hG2d +kMxhOuV4LFUK7qy+83uDdfo+mCxV44AgaQub1EepPUFCPOFrdWADXaTjh0eG3cgWkMI BCFtSS6vSixn8qqOg1H4ldpaLjgCAOYxoZtRnVqloM1sBPFr8ryn2R+SqYJlnqq2OdNa W9+wh0cV1bdyEUrrtd+4BIqInzeATr4oevXldxos/gmyxp+azKUuTKM6QgIK6DOmOzeq Z+GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=p0iGYBlY; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u10-20020aa7d98a000000b005021cd581a0si4447629eds.402.2023.04.01.10.47.54; Sat, 01 Apr 2023 10:47:54 -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=@gmail.com header.s=20210112 header.b=p0iGYBlY; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 49DDE68BEB0; Sat, 1 Apr 2023 20:47:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3DA3A68BF58 for ; Sat, 1 Apr 2023 20:47:44 +0300 (EEST) Received: by mail-pf1-f170.google.com with SMTP id cm5so10876499pfb.0 for ; Sat, 01 Apr 2023 10:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680371261; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=aWi2S0/tib9N0XKm6rtXvgXfz/PWmtEJEYWpbCUO6NY=; b=p0iGYBlY5g04R3q65oj5rkvfq16n045eW76BmNwcy7RDgAEd2SxtHeSipa5DxO49Qf wbAVbmwPxOJ0+XuL1o4+PYFmOQaURC/gnwKGJHJGs0TMPfdLvENRXM3f1OBtHeCWwnMU 2B6w93ohyGA85LduqcmT11vGa3HxM6ywy6OQj8GuUqukYBsoLeHE7BuoYXLB68bNmmIx GU18/q05WQPRdG4elyTatLn1V7qEYrfAjJvh6U3/GsvRDkZrkOYdllFLmHyV4yX2AzIO JJ3UJPxCsPros4eTn7TrH8Td4OcPxdzn3ybujFPFw9lhN7K/koEzhnw95xDtp6thKH/z B7fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680371261; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aWi2S0/tib9N0XKm6rtXvgXfz/PWmtEJEYWpbCUO6NY=; b=53uoAAn0V70SJ+gJ878Nbk2Lpy21c6rK+EY01EedXPdfDsHCYx6Q/tUqUka0n9m2fm zrzy/om0eAg90YuHksgyaU3qVRgeBvm2sz2piTUwkEgtoSyVy8LMJBQLJ5u8qILpwQ1N yDrGlf+VDzFc20f+ycY/EGJFxj9lbcyrxBQ6NhZBCnTriKcZ4wMECrwxq/BeNULuMRTZ j/x3+4gx1FDHLA/DLMriG3SsqhVuanxf8015sJsTrkkSNhBt9DdbmmU/vIBH9j3ACmTG XRGRVM6aQ2z1U+PxA+i3oK2lg0USeT9kb4AgwLyqkSUb7ZzQu5SXz+uyZNmkLkiqNhRn Ixnw== X-Gm-Message-State: AAQBX9d/M13bStgIAWDhTuXGwSUDo9fwWIb1IRPN1X/PHq1P1yn0JXkt 2uMbTtor8BMRlwH5eK2qR+58MV2dOs0= X-Received: by 2002:a62:1ac9:0:b0:62d:b4aa:79f9 with SMTP id a192-20020a621ac9000000b0062db4aa79f9mr14953498pfa.28.1680371261487; Sat, 01 Apr 2023 10:47:41 -0700 (PDT) Received: from wilferico.thefacebook.com ([2620:10d:c090:400::5:b0e]) by smtp.gmail.com with ESMTPSA id w22-20020a056a0014d600b005810c4286d6sm1508972pfu.0.2023.04.01.10.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Apr 2023 10:47:41 -0700 (PDT) From: Chema Gonzalez To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Apr 2023 10:47:35 -0700 Message-Id: <20230401174737.85192-1-chemag@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: add warning when color ranges differ 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: Chema Gonzalez Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WOp08cvdVgUZ The PSNR filter uses the pixel values without considering the color ranges. This is incorrect. Patch adds a warning so at least the user knows it. Let's see an example: (1) Let's get a simple black pixel/white pixel image. ``` $ echo -n -e "\x00\x00\x00\xff\xff\xff" > /tmp/foo.rgb24 ``` (2) From this image, let's distill full and limited range y4m copies. ``` $ ffmpeg -y -f rawvideo -video_size 2x1 -pix_fmt rgb24 -i /tmp/foo.rgb24 -vf scale="out_range=full" -pix_fmt yuv420p /tmp/foo.full.y4m $ xxd /tmp/foo.full.y4m 00000000: 5955 5634 4d50 4547 3220 5732 2048 3120 YUV4MPEG2 W2 H1 00000010: 4632 353a 3120 4970 2041 303a 3020 4334 F25:1 Ip A0:0 C4 00000020: 3230 6a70 6567 2058 5953 4353 533d 3432 20jpeg XYSCSS=42 00000030: 304a 5045 4720 5843 4f4c 4f52 5241 4e47 0JPEG XCOLORRANG 00000040: 453d 4655 4c4c 0a46 5241 4d45 0a00 ff80 E=FULL.FRAME.... 00000050: 80 . ``` and ``` $ ffmpeg -y -f rawvideo -video_size 2x1 -pix_fmt rgb24 -i /tmp/foo.rgb24 -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/foo.limited.y4m $ xxd /tmp/foo.limited.y4m 00000000: 5955 5634 4d50 4547 3220 5732 2048 3120 YUV4MPEG2 W2 H1 00000010: 4632 353a 3120 4970 2041 303a 3020 4334 F25:1 Ip A0:0 C4 00000020: 3230 6a70 6567 2058 5953 4353 533d 3432 20jpeg XYSCSS=42 00000030: 304a 5045 4720 5843 4f4c 4f52 5241 4e47 0JPEG XCOLORRANG 00000040: 453d 4c49 4d49 5445 440a 4652 414d 450a E=LIMITED.FRAME. 00000050: 10eb 8080 .... ``` Note that the 2x images are the same (both have 1x pixel at the darkest black, and one at the brightest white). Only difference is the range. (3) Let's calculate the PSNR score: ``` $ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "psnr" -f null - ... [Parsed_psnr_0 @ 0x2f5dac0] PSNR y:22.972065 u:inf v:inf average:25.982365 min:25.982365 max:25.982365 ``` As we are comparing an image with itself, we expect "y:inf" as the luma PSNR. Issue here is that the PSNR filter just uses the pixel values, ignoring the color ranges. A possible solution would be to have the filter do the conversion. Proposed solution is to add a warning. ``` $ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "psnr" -f null - ... [Parsed_psnr_0 @ 0x2f5dac0] master and reference frames use different color ranges (pc != tv) ... [Parsed_psnr_0 @ 0x2f5dac0] PSNR y:22.972065 u:inf v:inf average:25.982365 min:25.982365 max:25.982365 ``` Tested: Ran fate. ``` $ make fate -j ... TEST seek-lavf-ppmpipe TEST seek-lavf-pgmpipe TEST seek-lavf-mxf_opatom ``` --- libavfilter/vf_psnr.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c index 15cde7e8c8..058a8932f4 100644 --- a/libavfilter/vf_psnr.c +++ b/libavfilter/vf_psnr.c @@ -188,6 +188,13 @@ static int do_psnr(FFFrameSync *fs) td.planeheight[c] = s->planeheight[c]; } + if (master->color_range != ref->color_range) { + av_log(ctx, AV_LOG_WARNING, "master and reference " + "frames use different color ranges (%s != %s)\n", + av_color_range_name(master->color_range), + av_color_range_name(ref->color_range)); + } + ff_filter_execute(ctx, compute_images_mse, &td, NULL, FFMIN(s->planeheight[1], s->nb_threads)); From patchwork Sat Apr 1 17:47:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chema Gonzalez X-Patchwork-Id: 40967 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1609559pzb; Sat, 1 Apr 2023 10:48:03 -0700 (PDT) X-Google-Smtp-Source: AKy350Yyc1yGFRVI2Ah1mNwy2AibqAKnFZw4wb9dHQU+c+mb5znk2d2XMSEi0pPIBtc0E9tdjAz8 X-Received: by 2002:aa7:c590:0:b0:4ac:b431:4762 with SMTP id g16-20020aa7c590000000b004acb4314762mr27444677edq.23.1680371283605; Sat, 01 Apr 2023 10:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680371283; cv=none; d=google.com; s=arc-20160816; b=Bc3vNbGYFqvRHYKqX6DmMktzduTHVG/7hKDyoGTTVg1e8NhLs9h0mBUi1pMbN9b3iA IoH5CKNJ6wbUh4tjXK/tSzx+xJHMZvP1h1LeKBDIo3zXkX2DYBCzWWrU16BlXjNnboO5 32AFqsS61ZMHGgMrjG/46VMm0hyianPWahZwDRmxag1kmUjM+lNaLGbDD2eaLkKuRxAq jx3U2RSbO804abEbU5/RKTSjyl13K+yod+/lkee6gzKLnJJzEni4uF+3qmkCtwkJLXAJ KrdjHl8DLTYE7k041ogS6GvxRIkdOJFZNh945YTVu+UhXLqc3nNgfFXrEgeq+K+ZqHSR 6XZA== 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=s0ELqlVAAPl8cUsdSfnQJacAV10vjCGxzFI0cav/MxY=; b=hK/WMqMPfy9eux3oy+vIseUc7ES2UUv/CkD0o/1oR4rhdkuQDtqTk3Fj1Ef2WIKttx pfg2AhLkvof8wH0pAhLNA4CQb7O4Udd9qmL6e0sr+XzmJI8u1rvyiq4mOJupl3C65i+k ytN12bdpvf1a270U2hdbj9++7BdJbjCpyunxelVHTxOjBz6XQlBwN21mK9TSdmUQ+pdY iPFNLP62WgIsZtksE4LkNWF2u2Yghv2lRadqx2ylOseONFj/Z2fgJSvftRCeUztFPmIk AMGVpNNfLoNekdlzhFDgp4C85EWMO0zds38qW6nMI0sKWnar4/KNsWNXeZ5fYBz7X4EY EbHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="XjcNTin/"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s16-20020a056402015000b004fc995b3385si5006959edu.634.2023.04.01.10.48.03; Sat, 01 Apr 2023 10:48:03 -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=@gmail.com header.s=20210112 header.b="XjcNTin/"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5165168BF70; Sat, 1 Apr 2023 20:47:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5424568BF5C for ; Sat, 1 Apr 2023 20:47:47 +0300 (EEST) Received: by mail-pg1-f178.google.com with SMTP id 184so608412pga.12 for ; Sat, 01 Apr 2023 10:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680371265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HPc6ZboDBlo685m4wFNuP1nJubruhfJKbCzIZvDlKR0=; b=XjcNTin/RXCYbxEuL97e/R196k2lznDe4sCRxzXGRYcPApu3qGtygReMOfoDxvqd1I LwgK2o08LQ0u+qHmFek1aJc0EHXsJFpxbU38abTEo30mTQ01GqXlS2flZgMHlMxDalyN xvJE4lNrwsJ7duvEDrOw4GUMPElaLNUse67yCbu4kS790lXmn/IAkd5TDs/wKnuCnZD6 2a1vEppFe1IkOIKppakOHd5ZP4VzzySIN79Kb/PN7ZnLiq817X/jTDcztDMGqGbJ9WLO jo0hnt5hlAG5BExc1CHSF3VSVnBVYb/rByYRNqLJxRHu4IQVQIhmtU7HTM9ns98wfIc5 FsmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680371265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HPc6ZboDBlo685m4wFNuP1nJubruhfJKbCzIZvDlKR0=; b=6NEnRhyx01b7z3KjiufZpyPYlFx2SgjPqs4VCnq6tMhL76bWnEid1XKVkvtMi17rUq ToTg4MllC62T5iTCYj2qQDQT88YwcTZi+Wv/mdc/t2iGH66gOjlQZjRbQvPEr9ABn1fa Z4gjIQEthACq4k3CkcpZ4denKyYzUqGfUzdVXdz3724QH5p/NiKdegSG/h+t8ZVNZzAJ D8NUz1rWjqG82v8h/UoTOaVzUOxF46zb7VbC0lnwKmKJ5pMqZhqSRkxF1wwC6/3ve+s7 ZAbwoSqcurZNCevSHEXbJwBZR//HmRBsGUrGa9tzbv6p58nofLK165EyJFJYxP514Cen IP7A== X-Gm-Message-State: AAQBX9d45fMNRmXgdyC3zT77UE7PjZZACPJJTSGsD72GyJ72hWP3cwOT J159ROUoUL+7Maol6wWDdBn65ID7y6I= X-Received: by 2002:a62:2905:0:b0:62d:e5eb:2d73 with SMTP id p5-20020a622905000000b0062de5eb2d73mr6370620pfp.34.1680371264866; Sat, 01 Apr 2023 10:47:44 -0700 (PDT) Received: from wilferico.thefacebook.com ([2620:10d:c090:400::5:b0e]) by smtp.gmail.com with ESMTPSA id w22-20020a056a0014d600b005810c4286d6sm1508972pfu.0.2023.04.01.10.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Apr 2023 10:47:44 -0700 (PDT) From: Chema Gonzalez To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Apr 2023 10:47:36 -0700 Message-Id: <20230401174737.85192-2-chemag@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230401174737.85192-1-chemag@gmail.com> References: <20230401174737.85192-1-chemag@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavfi/vf_ssim: add warning when color ranges differ 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: Chema Gonzalez Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KlNr/YKAiQ9T The SSIM filter uses the pixel values without considering the color ranges. This is incorrect. Patch adds a warning so at least the user knows it. Let's see an example. (1) Let's get FR and LR versions of the same image. ``` $ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=full" -pix_fmt yuv420p /tmp/lena.full.y4m $ xxd /tmp/lena.full.y4m |head 00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H 00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0: 00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS 00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR 00000040: 5241 4e47 453d 4655 4c4c 0a46 5241 4d45 RANGE=FULL.FRAME 00000050: 0a72 7271 7070 706f 6f6e 6d6d 6c6d 6d6d .rrqpppoonmmlmmm 00000060: 6c6e 6e6d 6d6e 6e6e 6d6c 6d6d 6d6d 6d6d lnnmmnnnmlmmmmmm 00000070: 6d6e 6d6b 6c6d 6e6e 6d6c 6d6d 6e6e 6f6f mnmklmnnmlmmnnoo 00000080: 6f6f 6e6e 6e6e 6f70 7172 7375 7676 7370 oonnnnopqrsuvvsp 00000090: 6d69 6662 5e59 534d 4845 3d35 302e 2d2c mifb^YSMHE=50.-, ``` ``` $ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/lena.limited.y4m $ xxd /tmp/lena.limited.y4m | head 00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H 00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0: 00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS 00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR 00000040: 5241 4e47 453d 4c49 4d49 5445 440a 4652 RANGE=LIMITED.FR 00000050: 414d 450a 7272 7170 7070 6f6f 6e6e 6e6d AME.rrqpppoonnnm 00000060: 6e6e 6e6d 6f6e 6e6e 6e6e 6e6e 6d6e 6e6e nnnmonnnnnnnmnnn 00000070: 6e6e 6e6e 6f6e 6c6d 6e6f 6e6e 6d6e 6e6f nnnnonlmnonnmnno 00000080: 6f6f 6f6f 6f6f 6f6f 6f6f 7071 7273 7576 oooooooooopqrsuv 00000090: 7673 706e 6a68 6461 5c57 524e 4b44 3d39 vspnjhda\WRNKD=9 ``` Note that the 2x images are the same. Only difference is the range, and the precision issues related to range conversion. (2) Let's calculate the SSIM score: ``` $ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi "ssim" -f null - ... [Parsed_ssim_0 @ 0x360ab00] SSIM Y:0.942347 (12.391801) U:0.995808 (23.776062) V:0.996104 (24.093747) All:0.960217 (14.003012) ``` As we are comparing an image with itself, we expect "Y: 1" as the luma SSIM. Issue here is that the SSIM filter just uses the pixel values, ignoring the color ranges. Proposed solution is to add a warning. ``` $ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "ssim" -f null - ... [Parsed_ssim_0 @ 0x3766280] master and reference frames use different color ranges (pc != tv) ... [Parsed_ssim_0 @ 0x3766280] SSIM Y:0.000000 (0.000000) U:0.000000 (0.000000) V:0.000000 (0.000000) All:0.000000 (0.000000) ``` Tested: Ran fate. ``` $ make fate -j ... TEST seek-lavf-ppmpipe TEST seek-lavf-pgmpipe TEST seek-lavf-mxf_opatom ``` --- libavfilter/vf_ssim.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavfilter/vf_ssim.c b/libavfilter/vf_ssim.c index 1933b9b82d..53eb72fe6a 100644 --- a/libavfilter/vf_ssim.c +++ b/libavfilter/vf_ssim.c @@ -358,6 +358,13 @@ static int do_ssim(FFFrameSync *fs) td.planeheight[n] = s->planeheight[n]; } + if (master->color_range != ref->color_range) { + av_log(ctx, AV_LOG_WARNING, "master and reference " + "frames use different color ranges (%s != %s)\n", + av_color_range_name(master->color_range), + av_color_range_name(ref->color_range)); + } + ff_filter_execute(ctx, s->ssim_plane, &td, NULL, FFMIN((s->planeheight[1] + 3) >> 2, s->nb_threads)); From patchwork Sat Apr 1 17:47:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chema Gonzalez X-Patchwork-Id: 40968 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1609625pzb; Sat, 1 Apr 2023 10:48:11 -0700 (PDT) X-Google-Smtp-Source: AKy350arqcNc2oaStfZc5AqLyXY2VVbQc/yBmUgxCRLFgNKf3toj3sFxdoDHDgYHOIuX5OtfzB1i X-Received: by 2002:a17:906:94cd:b0:931:f9f8:bf9e with SMTP id d13-20020a17090694cd00b00931f9f8bf9emr29374785ejy.74.1680371291494; Sat, 01 Apr 2023 10:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680371291; cv=none; d=google.com; s=arc-20160816; b=tdpi0QsJ6wDmR1FjvB8u66LW0IwOarroyKoTFjGhRK0GK7+4opCKW9/EEA7X3UnaqT zt67nn8utvzPPE7biHqIBv8IP28C1ASMWANBvAemimQNSlqhx+3IqcyZJblO8P5vAskO /KfoaP1T53BT//CAzB6lbkAALuH/HRMXVThWbZhTzsvRPdexcS6cVFvaC1jZlpx8Fy7q vxvTubpx1/nM934Da5UoDJQrvwLcnxf83+UnI6O16gsVKthAYpZ26nKlBjU9qdopHfyU n0OyrFm9JMGUGZARSOhmOldIzxHnZMM6oqbHKhOawX6llZHxFOKXM1HO3wBzfYBHrHRQ MVvA== 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=eVdmjydks8YzwQugnd0B4XhzbRQKqQQCm3nOt0JaaBQ=; b=sjhifOi8dwwbUutY+XbOJuIN9rKNGAsaYGjTfz0uEI0TEsCnTLz2IqOJv/2gjwlF0x EMIJAvkOrox9QoxIUR2RwgCR2wukUssamladzXqWb/BM0EnEFE5Kh5sKnn/LZoKWEGmA q/YvMxv0SWK6aETZj9QJOfJ/UzkJVMiK3sAELN26xz8L9fjwowsRlYMX/n+71PDyxy13 XXuhEBvWMxVPsc6cuNxk6fZN2DFZ1cYSQO/tGWpgfFI1lNiHZ13U2WwPbyYz2ay9mV/t lZmE7u4izAzrzwLIirgIlgItn3oBasbXGqMHXfOONc5qEEQC5O0DvkFFLmiwGRo9M5Tx dUqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=LbQ3qm0c; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hk21-20020a170906c9d500b00930cbf016a0si4351082ejb.967.2023.04.01.10.48.11; Sat, 01 Apr 2023 10:48:11 -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=@gmail.com header.s=20210112 header.b=LbQ3qm0c; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6308C68BF85; Sat, 1 Apr 2023 20:47:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 77BEE68BF5D for ; Sat, 1 Apr 2023 20:47:48 +0300 (EEST) Received: by mail-pj1-f44.google.com with SMTP id p13-20020a17090a284d00b0023d2e945aebso10972366pjf.0 for ; Sat, 01 Apr 2023 10:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680371266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Xhs+8hgNdKgd/1CK4JYCmkc1qKNScohKrxa0kX8Y3tk=; b=LbQ3qm0cyo9tcHRLTyw9dForveoTmoryUSm8eaXezcoDarJAkwnGYJhx8LgfyEGCfU SBvRxhv/Ol/0VsBmM01GBonvHp7UYAk6uPKGn30OnVCRyrgzjrudZZn4nhLruYE3FhCK cf34zH533V0w/A5Zk6vIERBa9Rc7ZU6EdRFl7RT5W4IiMmqThBU0ZRnPgH4PrjT72902 INrf5TtaWH/JgIjX60RlDBU1EzhfbReh6FA5We7tRzsel5aPcjOmzXdkQBLL8m+WSVgV kstp4+NQA5BiGMIkehU5chlPBU6Jt2R67TUYnNbmuimLc0IiYyoiBYSRDS2MybcpzwJz +FrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680371266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xhs+8hgNdKgd/1CK4JYCmkc1qKNScohKrxa0kX8Y3tk=; b=WMTs4Y7BLuSOA7wl4et8XfwSblw3nQ6GRN5IoNMgJQRYKD3E25ru0FYkONuzsy5SUj VYnwMpEH+tX+67/8+rtX2Km+/pNAO24Wdi+Ehd5g2AdumEvkbNE/zQrfqcIJTnCyodJt BUBoThk1VGusTBYa+SPn5MBm+GhRVjFvDPGO1hGwxsJeVaU/xgGyCBqRrv6htfKhGZ0o siiBABuihWHpTLaXTzPOoGYWHonhElxOOdZYsDDXWo0RPFjIizM4PEK4ToSyurmhxApI AIYyJApZ/FsQBSmcUeDEFNLCC2OPIEylB7D9ioL+def0+FFKGMrlI9Rc9+0A7H7t+0tL w5Mw== X-Gm-Message-State: AAQBX9dpgkixRIRVmME8lj4r25RYMO9z2jW69msWk6sT9kcJBGKFDuZf UY+Obj/Ev0puJyXMAxdyO/2O55F1TDc= X-Received: by 2002:a05:6a20:4f28:b0:de:9f78:f677 with SMTP id gi40-20020a056a204f2800b000de9f78f677mr26089611pzb.23.1680371266310; Sat, 01 Apr 2023 10:47:46 -0700 (PDT) Received: from wilferico.thefacebook.com ([2620:10d:c090:400::5:b0e]) by smtp.gmail.com with ESMTPSA id w22-20020a056a0014d600b005810c4286d6sm1508972pfu.0.2023.04.01.10.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Apr 2023 10:47:46 -0700 (PDT) From: Chema Gonzalez To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Apr 2023 10:47:37 -0700 Message-Id: <20230401174737.85192-3-chemag@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230401174737.85192-1-chemag@gmail.com> References: <20230401174737.85192-1-chemag@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: add warning when color ranges differ 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: Chema Gonzalez Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9mCzsAAVwDaq The VMAF filter uses the pixel values without considering the color ranges. This is incorrect. Patch adds a warning so at least the user knows it. Let's see an example. (1) Let's get FR and LR versions of the same image. ``` $ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=full" -pix_fmt yuv420p /tmp/lena.full.y4m $ xxd /tmp/lena.full.y4m |head 00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H 00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0: 00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS 00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR 00000040: 5241 4e47 453d 4655 4c4c 0a46 5241 4d45 RANGE=FULL.FRAME 00000050: 0a72 7271 7070 706f 6f6e 6d6d 6c6d 6d6d .rrqpppoonmmlmmm 00000060: 6c6e 6e6d 6d6e 6e6e 6d6c 6d6d 6d6d 6d6d lnnmmnnnmlmmmmmm 00000070: 6d6e 6d6b 6c6d 6e6e 6d6c 6d6d 6e6e 6f6f mnmklmnnmlmmnnoo 00000080: 6f6f 6e6e 6e6e 6f70 7172 7375 7676 7370 oonnnnopqrsuvvsp 00000090: 6d69 6662 5e59 534d 4845 3d35 302e 2d2c mifb^YSMHE=50.-, ``` ``` $ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/lena.limited.y4m $ xxd /tmp/lena.limited.y4m | head 00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H 00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0: 00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS 00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR 00000040: 5241 4e47 453d 4c49 4d49 5445 440a 4652 RANGE=LIMITED.FR 00000050: 414d 450a 7272 7170 7070 6f6f 6e6e 6e6d AME.rrqpppoonnnm 00000060: 6e6e 6e6d 6f6e 6e6e 6e6e 6e6e 6d6e 6e6e nnnmonnnnnnnmnnn 00000070: 6e6e 6e6e 6f6e 6c6d 6e6f 6e6e 6d6e 6e6f nnnnonlmnonnmnno 00000080: 6f6f 6f6f 6f6f 6f6f 6f6f 7071 7273 7576 oooooooooopqrsuv 00000090: 7673 706e 6a68 6461 5c57 524e 4b44 3d39 vspnjhda\WRNKD=9 ``` Note that the 2x images are the same. Only difference is the range, and the precision issues related to range conversion. (2) Let's calculate the VMAF score: ``` $ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi libvmaf="model=path=/usr/share/model/vmaf_v0.6.1neg.json" -report -f null - ... [Parsed_libvmaf_0 @ 0x3cc9b40] VMAF score: 85.530109 ``` As we are comparing an image with itself, we expect the score to be close to 100. Issue here is that the VMAF filter just uses the pixel values, ignoring the color ranges. Proposed solution is to add a warning. ``` $ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi libvmaf="model=path=/us r/share/model/vmaf_v0.6.1neg.json" -report -f null - ... [Parsed_libvmaf_0 @ 0x3cc9b40] distorted and reference frames use different color ranges (pc != tv) ... [Parsed_libvmaf_0 @ 0x3cc9b40] VMAF score: 85.530109 ``` Tested: Ran fate. ``` $ make fate -j ... TEST seek-lavf-ppmpipe TEST seek-lavf-pgmpipe TEST seek-lavf-mxf_opatom ``` --- libavfilter/vf_libvmaf.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c index 2586f37d99..67f0d6a22f 100644 --- a/libavfilter/vf_libvmaf.c +++ b/libavfilter/vf_libvmaf.c @@ -141,6 +141,13 @@ static int do_vmaf(FFFrameSync *fs) if (ctx->is_disabled || !ref) return ff_filter_frame(ctx->outputs[0], dist); + if (dist->color_range != ref->color_range) { + av_log(ctx, AV_LOG_WARNING, "distorted and reference " + "frames use different color ranges (%s != %s)\n", + av_color_range_name(dist->color_range), + av_color_range_name(ref->color_range)); + } + err = copy_picture_data(ref, &pic_ref, s->bpc); if (err) { av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n");