From patchwork Sun Dec 10 22:11:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 6691 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2079253jah; Sun, 10 Dec 2017 14:12:37 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ9DV0du2A/hr49muJNB9qNPUCv9MnuGEipSPMXJDjBcyKLRvX8wKbAT2/MCfNYKZarDQzC X-Received: by 10.28.125.85 with SMTP id y82mr8123764wmc.25.1512943957365; Sun, 10 Dec 2017 14:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512943957; cv=none; d=google.com; s=arc-20160816; b=yLlXoArGxxvwGQ7Zz5ZuHS0aeL3DUpUNl47wlrjnDiAxLAYsoAz8jcfKlH0Vpf/Ery jNT81B9SOc6JnPNlQQRzA/9jcetdhN0ti46Itp34JK71cbaJs/G91Uc10Nj4UU4Sl3vf Ur+9V6FQdCAI9JX1Mb+F0GPvIAfD0/TTfeLLBiGWmqBJJpvObjdXPpjY/tZfgGmvWZob xvj+zFsCkI57uewTLPMHpVo5qXGIHzO5Wsu6aLPNkEo/eXIiPcMFteoGhBlKLM0ZgFAU 2bzntikUwcD+ys5oju/vYA9R91stShw46OnOFPlLq4IBGYR9bivk/H18VdlNwJ8KgKQe O6HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=p8L5QkIfFR43/HQ0FhjgScNPWB8tl6TuOlPEy1ks3k0=; b=uM+A0ZM+6SBkNri3qQiWJQILqxY1LbSGlcsTtVaN1bjYN76mB1VwOyQlDgD+xTuniA kmQ9GIhGZbE1MAE29QRbZd8ooTmraqJbXYU1I6PpcyFXMomhbLiGbHs+ydOGgZQWHWPf Woyfan5oJtwIPiSBZ8kRvhKO2uzyGy/1zsUt9CnTxKI6jLDOu29eX7TEftzrz3INvxqd Vxe1elKj8cC5MDWl62lyYfWbv+C8MZ7NMDVU5VwDW8/hvBkNrXGoHMLGpgMbrmx0jMub mycpHqqlkW3FQ6tFBVxJPM7MtQb2Xp/spFA3q3wIcY0XdAiuQ5+I53kWeARnsP4l2Bvt jdkw== ARC-Authentication-Results: i=1; mx.google.com; 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 v18si9626783wrf.180.2017.12.10.14.12.37; Sun, 10 Dec 2017 14:12:37 -0800 (PST) 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; 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 C948B68A6D3; Mon, 11 Dec 2017 00:11:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E09EE68A6B4 for ; Mon, 11 Dec 2017 00:11:35 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3BA4BE112A; Sun, 10 Dec 2017 23:11:43 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oY5iP18U66sN; Sun, 10 Dec 2017 23:11:42 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 1D8AEE183D; Sun, 10 Dec 2017 23:11:41 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Dec 2017 23:11:22 +0100 Message-Id: <20171210221122.15674-7-cus@passwd.hu> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171210221122.15674-1-cus@passwd.hu> References: <20171210221122.15674-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 7/7] avfilter/vf_framerate: fix scene score with negative linesize 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also, do not overread input if linesize > width, or linesize is not divisible by 8, and use the proper rounded width/height for MAFD calculation. Signed-off-by: Marton Balint --- libavfilter/vf_framerate.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c index 5fffc2a172..5ed9ae4cb7 100644 --- a/libavfilter/vf_framerate.c +++ b/libavfilter/vf_framerate.c @@ -136,12 +136,12 @@ static av_always_inline int64_t sad_8x8_16(const uint16_t *src1, ptrdiff_t strid return sum; } -static int64_t scene_sad16(FrameRateContext *s, const uint16_t *p1, int p1_linesize, const uint16_t* p2, int p2_linesize, int height) +static int64_t scene_sad16(FrameRateContext *s, const uint16_t *p1, int p1_linesize, const uint16_t* p2, int p2_linesize, const int width, const int height) { int64_t sad; int x, y; - for (sad = y = 0; y < height; y += 8) { - for (x = 0; x < p1_linesize; x += 8) { + for (sad = y = 0; y < height - 7; y += 8) { + for (x = 0; x < width - 7; x += 8) { sad += sad_8x8_16(p1 + y * p1_linesize + x, p1_linesize, p2 + y * p2_linesize + x, @@ -151,12 +151,12 @@ static int64_t scene_sad16(FrameRateContext *s, const uint16_t *p1, int p1_lines return sad; } -static int64_t scene_sad8(FrameRateContext *s, uint8_t *p1, int p1_linesize, uint8_t* p2, int p2_linesize, int height) +static int64_t scene_sad8(FrameRateContext *s, uint8_t *p1, int p1_linesize, uint8_t* p2, int p2_linesize, const int width, const int height) { int64_t sad; int x, y; - for (sad = y = 0; y < height; y += 8) { - for (x = 0; x < p1_linesize; x += 8) { + for (sad = y = 0; y < height - 7; y += 8) { + for (x = 0; x < width - 7; x += 8) { sad += s->sad(p1 + y * p1_linesize + x, p1_linesize, p2 + y * p2_linesize + x, @@ -181,11 +181,11 @@ static double get_scene_score(AVFilterContext *ctx, AVFrame *crnt, AVFrame *next ff_dlog(ctx, "get_scene_score() process\n"); if (s->bitdepth == 8) - sad = scene_sad8(s, crnt->data[0], crnt->linesize[0], next->data[0], next->linesize[0], crnt->height); + sad = scene_sad8(s, crnt->data[0], crnt->linesize[0], next->data[0], next->linesize[0], crnt->width, crnt->height); else - sad = scene_sad16(s, (const uint16_t*)crnt->data[0], crnt->linesize[0] >> 1, (const uint16_t*)next->data[0], next->linesize[0] >> 1, crnt->height); + sad = scene_sad16(s, (const uint16_t*)crnt->data[0], crnt->linesize[0] >> 1, (const uint16_t*)next->data[0], next->linesize[0] >> 1, crnt->width, crnt->height); - mafd = (double)sad * 100.0 / (crnt->height * crnt->width) / (1 << s->bitdepth); + mafd = (double)sad * 100.0 / FFMAX(1, (crnt->height & ~7) * (crnt->width & ~7)) / (1 << s->bitdepth); diff = fabs(mafd - s->prev_mafd); ret = av_clipf(FFMIN(mafd, diff), 0, 100.0); s->prev_mafd = mafd;