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 1BA5045452 for ; Fri, 31 Mar 2023 16:49:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 97F7168C290; Fri, 31 Mar 2023 19:49:37 +0300 (EEST) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 839B768C224 for ; Fri, 31 Mar 2023 19:49:31 +0300 (EEST) Received: by mail-pl1-f177.google.com with SMTP id o11so21809737ple.1 for ; Fri, 31 Mar 2023 09:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680281369; 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=Wb7jizZSuquV/wg5Lv6s7o01csWuqXwVJewYwKK7EpQ=; b=jeyUPMD7qE5xecsGadVps4ZHCOxUeue/nRDh3+RuzDWWKAbghJiweWQxUwYdZPN5EX DeY8rEjsPS2ZQu/Jt+TnxCH8BCi75NqekgRQedtfO8tXrCEzlzMUx0Jgh1d5Tas27T15 w8hnCEzN0rOi2cW1pBKxQIruGx+su6B6sQlWYYDljG9VmgOPz9ZcEKTCWZS87Mw+JDF8 ZsKG8vegamqgyNVLFLf4HK+tmyQVMmTJ1IKPQOIdSsFhw9mkMA3aTMBl73hjiSShsspl 6IyAwafBm1bKdAetIgJdz+gs4kJV0eVCB8qjFNYdZ6cu/t9h6LMLIqWXU5JQiiZ+m2pY Z+GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680281369; 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=Wb7jizZSuquV/wg5Lv6s7o01csWuqXwVJewYwKK7EpQ=; b=owyqtXvMOoBIMRM24Qgpd7/t9Xa9KQQUPU5siSBJClxJ/+RZSAUz6Q/s2c24T9VtXd KxMM1DvPUqWXrNiFJwEwc05h9bkMa76GdNSbQETzvc2DFaQi4hlNyOhBYxOl+JQxN8PT gwQgFXhKFGLAgdq10ZLGdCSNbtCO5NgnlwD90HWKV+xCkpgBx/CbfhUKGohw0Yut6CT7 gQ6rkzTBadtqflIRpDI7Vr9ygj2zTIhDNU4yHXw7hFR4UnoK1rztRgGmbFox+gsAI+tj S9bJKFfcJbZTuRzjIdKtb7OkuqegM1Ijq29sx/+dUhxtHZqP96fvYskBz6wecUUhkOcc 0Yqg== X-Gm-Message-State: AAQBX9dgfrahvMSlUqJxivjTCHZo0VMAachb51ZPVFMd1GvawZtIU8nO kPs7Dpe5NloefVMKh6rIHZxHY4HykKo= X-Google-Smtp-Source: AKy350ZcuJvzVNKM2G28jaeVgfsKVNe/Gtjh9TSgzwBd1KqNLRIMW+/BB7mpFDymmW6zyRpVRQIZ0A== X-Received: by 2002:a17:903:2803:b0:19e:73df:b0e9 with SMTP id kp3-20020a170903280300b0019e73dfb0e9mr23710945plb.21.1680281369374; Fri, 31 Mar 2023 09:49:29 -0700 (PDT) Received: from wilferico.thefacebook.com ([2620:10d:c090:400::5:b0e]) by smtp.gmail.com with ESMTPSA id w7-20020a170902d70700b0019aa6bf4450sm1772117ply.188.2023.03.31.09.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 09:49:29 -0700 (PDT) From: Chema Gonzalez To: ffmpeg-devel@ffmpeg.org Date: Fri, 31 Mar 2023 09:49:21 -0700 Message-Id: <20230331164923.4051693-2-chemag@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230331164923.4051693-1-chemag@gmail.com> References: <20230331164923.4051693-1-chemag@gmail.com> 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 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 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] Warning: 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..bd33322593 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, "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)); -- 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".