From patchwork Thu Nov 21 11:29:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 16364 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 74EE14462D0 for ; Thu, 21 Nov 2019 13:37:49 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F4CA68AC4B; Thu, 21 Nov 2019 13:37:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 775C368ABAA for ; Thu, 21 Nov 2019 13:37:42 +0200 (EET) Received: by mail-pg1-f196.google.com with SMTP id k13so1470427pgh.3 for ; Thu, 21 Nov 2019 03:37:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=TpOXjMFr4qGhcHQikUrK8HyFuGQhdOp36FU1POfNuXo=; b=MDhQEiSklZ1IFqX6cg0Cf7YjJRRgmOXCHMOHqd06wTG6wV2KKLgah3OjpDiRaz5ZWp e5cWtwyPStGGZwj9RdfoAwj2WQPS1yS6PqMV8Q2bZrHAzH8X+SjoE72VBNNZNMEWqZiJ KE15mBz5vI1XI9vqFng8pIliu4IxMq7ZOrHLKZQzkTOK67k9PMFis8wG+BfHiEXEJmk0 3qXBhy0amFBt9dfwMck+rBpYdbgqeHuw+POCTQsK1MO9lzWbkufgJLHPMmUnPr4zR+Ip IIH3xltOAPrhyIyDxcfeCg2Z4hCF56oReQPwbm5VXcj3fHeWOO9CFpE2l0LC/LP44SMS IExQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TpOXjMFr4qGhcHQikUrK8HyFuGQhdOp36FU1POfNuXo=; b=Q9dsSOaN+z4IoFG28amvV/zWjAO5BMjGFf5zi0duXq/OqK4FSuz+MHOz04Jp8dW3VT 46SLjMEcnP1JcIOl3mltA+HyOuY9us65WZnfARqFVkubhxnqBjVDkowgYxmC2qxv3zS5 2sa+kb+hn0JCnInJCo85HtzEUQkEci0Y8aAwW3ISZ5BJHt6lajNnDOh2xN2lHW6TmltZ hJq2gLSDtp/hNwbcm/vqiC/2h/Dxt+vNlr25ZKUVNuMMCISLnDolLpwG8PDy69xzqmEl kMKFIChMWfq+5P0XagGZSwoakoqfUTs0bnbceGCIP2mYPgfr8/e00Qwevdw3pGf0SZZN rOXw== X-Gm-Message-State: APjAAAWqKAnIcVKvYIndT2al/Okb/eurAptZLKfs72xvjY6Qj9tVSgNG AuAqEcFpci4EUhqLR1B1XYiCL0xU X-Google-Smtp-Source: APXvYqz8jZAG7pvGJl+a/cXc/dJlWKo2sQvMaFT2F7f+vY8hQozGzRaE8eA5+muWAFBk6qNF6ieGHg== X-Received: by 2002:a63:c406:: with SMTP id h6mr9211798pgd.213.1574335772741; Thu, 21 Nov 2019 03:29:32 -0800 (PST) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id t15sm2956647pgb.0.2019.11.21.03.29.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Nov 2019 03:29:31 -0800 (PST) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 21 Nov 2019 19:29:27 +0800 Message-Id: <20191121112927.13425-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 Subject: [FFmpeg-devel] [PATCH v1] avfilter/vf_showinfo: Fix erroneous results for mean and stdev with pixel bits >8 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang The following is one of the testing results, you can observe the result of 16bit isn't correct. 1, yuv420p ./ffmpeg -f lavfi -i color=black:duration=1:r=1:size=1280x720,format=yuv420p,showinfo Master: mean:[16 128 128] stdev:[0.0 0.0 0.0] After applied the patch: mean:[16 128 128] stdev:[0.0 0.0 0.0] 2, yuv420p10 ./ffmpeg -f lavfi -i color=black:duration=1:r=1:size=1280x720,format=yuv420p10,showinfo Master: mean:[32 1 1] stdev:[32.0 1.0 1.0] After applied the patch: mean:[64 512 512] stdev:[0.0 0.0 0.0] Signed-off-by: Limin Wang --- libavfilter/vf_showinfo.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 31f6b32aa4..e50c1af08e 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -202,7 +202,7 @@ static void dump_color_property(AVFilterContext *ctx, AVFrame *frame) av_log(ctx, AV_LOG_INFO, "\n"); } -static void update_sample_stats(const uint8_t *src, int len, int64_t *sum, int64_t *sum2) +static void update_sample_stats_8(const uint8_t *src, int len, int64_t *sum, int64_t *sum2) { int i; @@ -212,6 +212,25 @@ static void update_sample_stats(const uint8_t *src, int len, int64_t *sum, int64 } } +static void update_sample_stats_16(const uint8_t *src, int len, int64_t *sum, int64_t *sum2) +{ + const uint16_t *src1 = (const uint16_t *)src; + int i; + + for (i = 0; i < len/2; i++) { + *sum += src1[i]; + *sum2 += src1[i] * src1[i]; + } +} + +static void update_sample_stats(int depth, const uint8_t *src, int len, int64_t *sum, int64_t *sum2) +{ + if (depth <=8 ) + update_sample_stats_8(src, len, sum, sum2); + else + update_sample_stats_16(src, len, sum, sum2); +} + static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { AVFilterContext *ctx = inlink->dst; @@ -220,12 +239,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) uint32_t plane_checksum[4] = {0}, checksum = 0; int64_t sum[4] = {0}, sum2[4] = {0}; int32_t pixelcount[4] = {0}; + int bitdepth = desc->comp[0].depth; int i, plane, vsub = desc->log2_chroma_h; for (plane = 0; plane < 4 && s->calculate_checksums && frame->data[plane] && frame->linesize[plane]; plane++) { uint8_t *data = frame->data[plane]; int h = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(inlink->h, vsub) : inlink->h; int linesize = av_image_get_linesize(frame->format, frame->width, plane); + int width = linesize >> (bitdepth > 8); if (linesize < 0) return linesize; @@ -234,8 +255,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize); checksum = av_adler32_update(checksum, data, linesize); - update_sample_stats(data, linesize, sum+plane, sum2+plane); - pixelcount[plane] += linesize; + update_sample_stats(bitdepth, data, linesize, sum+plane, sum2+plane); + pixelcount[plane] += width; data += frame->linesize[plane]; } }