From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 579C5459BE for ; Sat, 1 Apr 2023 17:48:01 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1949068BF6F; Sat, 1 Apr 2023 20:47:54 +0300 (EEST) 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-Google-Smtp-Source: AKy350bsT79GPV1GAXVHGC9h3ThgrjnB3D9USH109H+ieD0Qnmorc2ac2XX7E3odpko7EHZfBUgYJg== 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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)); -- 2.39.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".