From patchwork Tue Oct 6 14:28:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22740 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 9A710449F4D for ; Tue, 6 Oct 2020 17:30:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 791D768B6BF; Tue, 6 Oct 2020 17:30:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4026168B2F8 for ; Tue, 6 Oct 2020 17:30:42 +0300 (EEST) Received: by mail-ej1-f68.google.com with SMTP id md26so17936494ejb.10 for ; Tue, 06 Oct 2020 07:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FUXgA3KYAmUBC1esfyOC53sIuvzgiYuD7JJtPLEWejM=; b=uvM1Nb7etGZG8NUVIcii3NsL3Ow/QDG8zEWJj1++BPCtFy0GlPFeSRd18f+Tljzr6b veF+E59weUZPrK5JVMRormdtqOcBFfCowOrysYCHeMuAK2qw76y0kI6dQwUAZY7HUQZi HlPg8IldA69qXCUIaYiQc41dsJt2RQ1taI8CSeFglY8yavBYylA9laAa6OyS2w1lqOXb Zrr/Ls43KqU9bgn0EZOZHwFMX+tQEIA1ACW7LPDjEP9cMVPZGMVSy2Jfmen9H1mwkQQT 1iW7HtJgXRQyB/4CZdds240Va6AAxDnDXbHACtCHzWfxjx3Ydqzc/Yr8zDbiNiRJJysA N09g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=FUXgA3KYAmUBC1esfyOC53sIuvzgiYuD7JJtPLEWejM=; b=D1owNmazMrdx7O4q1YCApIUjeEkJgMYfXtfz3lDm8NZB+B6Lq9NyJoU+vAb3IpR7DS aIbfKri8dfomYWh2ZFa1dwzQJgv7jCN9pmEDDh5wpNabgCXevcS2cc7pVsGiACVcaIRp /SQ0oLO5ZvReMBEwVlBvd5v8SxbOus6IdpNKDmab3jhCdyZN82b/QFr4rLbRALkVZiJf ZPfPOKZYWbRTdOc9rzR53voOa2i7mMbp58XsUL8gBuD9TqSElzEx/HNX6YAXQolJ5Kkl oPgYRmg62eNK0JXF+QPN3cXIamjjlkQyK4k14moiQwxS73ZdoO9k1fHvX+C9zvaI8Yww Lskw== X-Gm-Message-State: AOAM533xHH2CNyogpV3K49MHsR7eXGaPRqn8vPdunf8idVWFTjXNUVaI Y0Zv07U7F1Jt9Oin63/D9ASSt8McO7Y= X-Google-Smtp-Source: ABdhPJzbuilFu+b3NMZQOUq7ewF2BJP8Gbhrz565ciQASw6opeAGuM/kmlEZ4ZInuoGZPYpXTPb1Dg== X-Received: by 2002:a17:906:f8d5:: with SMTP id lh21mr5327211ejb.185.1601994641204; Tue, 06 Oct 2020 07:30:41 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id z20sm2249781eji.104.2020.10.06.07.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2020 07:30:40 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Oct 2020 16:28:39 +0200 Message-Id: <20201006142840.289130-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201006142840.289130-1-andreas.rheinhardt@gmail.com> References: <20201006142840.289130-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/vf_minterpolate: Fix left shift of negative value 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This has happened when initializing the motion estimation context if width or height of the video was smaller than the block size used for motion estimation and if the motion interpolation mode indicates not to use motion estimation. The solution is of course to only initialize the motion estimation context if the interpolation mode uses motion estimation. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_minterpolate.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/libavfilter/vf_minterpolate.c b/libavfilter/vf_minterpolate.c index e1fe5e32b5..bf45662913 100644 --- a/libavfilter/vf_minterpolate.c +++ b/libavfilter/vf_minterpolate.c @@ -368,6 +368,15 @@ static int config_input(AVFilterLink *inlink) 2 * mi_ctx->mb_size); return AVERROR(EINVAL); } + ff_me_init_context(me_ctx, mi_ctx->mb_size, mi_ctx->search_param, + width, height, 0, (mi_ctx->b_width - 1) << mi_ctx->log2_mb_size, + 0, (mi_ctx->b_height - 1) << mi_ctx->log2_mb_size); + + if (mi_ctx->me_mode == ME_MODE_BIDIR) + me_ctx->get_cost = &get_sad_ob; + else if (mi_ctx->me_mode == ME_MODE_BILAT) + me_ctx->get_cost = &get_sbad_ob; + mi_ctx->pixel_mvs = av_mallocz_array(width * height, sizeof(PixelMVS)); mi_ctx->pixel_weights = av_mallocz_array(width * height, sizeof(PixelWeights)); mi_ctx->pixel_refs = av_mallocz_array(width * height, sizeof(PixelRefs)); @@ -395,13 +404,6 @@ static int config_input(AVFilterLink *inlink) return AVERROR(EINVAL); } - ff_me_init_context(me_ctx, mi_ctx->mb_size, mi_ctx->search_param, width, height, 0, (mi_ctx->b_width - 1) << mi_ctx->log2_mb_size, 0, (mi_ctx->b_height - 1) << mi_ctx->log2_mb_size); - - if (mi_ctx->me_mode == ME_MODE_BIDIR) - me_ctx->get_cost = &get_sad_ob; - else if (mi_ctx->me_mode == ME_MODE_BILAT) - me_ctx->get_cost = &get_sbad_ob; - return 0; fail: for (i = 0; i < NB_FRAMES; i++) @@ -830,9 +832,10 @@ static int inject_frame(AVFilterLink *inlink, AVFrame *avf_in) return 0; } -static int detect_scene_change(MIContext *mi_ctx) +static int detect_scene_change(AVFilterContext *ctx) { - AVMotionEstContext *me_ctx = &mi_ctx->me_ctx; + MIContext *mi_ctx = ctx->priv; + AVFilterLink *input = ctx->inputs[0]; uint8_t *p1 = mi_ctx->frames[1].avf->data[0]; ptrdiff_t linesize1 = mi_ctx->frames[1].avf->linesize[0]; uint8_t *p2 = mi_ctx->frames[2].avf->data[0]; @@ -841,9 +844,9 @@ static int detect_scene_change(MIContext *mi_ctx) if (mi_ctx->scd_method == SCD_METHOD_FDIFF) { double ret = 0, mafd, diff; uint64_t sad; - mi_ctx->sad(p1, linesize1, p2, linesize2, me_ctx->width, me_ctx->height, &sad); + mi_ctx->sad(p1, linesize1, p2, linesize2, input->w, input->h, &sad); emms_c(); - mafd = (double) sad * 100.0 / (me_ctx->height * me_ctx->width) / (1 << mi_ctx->bitdepth); + mafd = (double) sad * 100.0 / (input->h * input->w) / (1 << mi_ctx->bitdepth); diff = fabs(mafd - mi_ctx->prev_mafd); ret = av_clipf(FFMIN(mafd, diff), 0, 100.0); mi_ctx->prev_mafd = mafd; @@ -1191,7 +1194,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *avf_in) if (!mi_ctx->frames[0].avf) return 0; - mi_ctx->scene_changed = detect_scene_change(mi_ctx); + mi_ctx->scene_changed = detect_scene_change(ctx); for (;;) { AVFrame *avf_out;