From patchwork Sun Mar 22 15:55:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramiro Polla X-Patchwork-Id: 18355 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 81D2344A7AA for ; Sun, 22 Mar 2020 18:18:22 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5FADC68B4E3; Sun, 22 Mar 2020 18:18:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C2A468B0E6 for ; Sun, 22 Mar 2020 18:18:16 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id i3so5734169qtv.8 for ; Sun, 22 Mar 2020 09:18:15 -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; bh=YgHP9bBXJZShDaL7aOvh2TA2drwYpBwU8fA82XoIezE=; b=OkUrAiz8RHajeVhuJaaRIeCLNTxSMhrsKUts0gL7UwQr+OOYbx3rzvuI11hjs99QLj QdCLr3qVaSw7pFUsXYjINIH+/AlGbJXPdyKe0qNMBRFfQkmsm83nlp4Sr3G/QV14bN/r ixyyRV3ZCiSUlpGAGtLWsxCSzcoFbnZj0tMM+u+OXsd9yOfE9cKfk3oskIGzgFZtovP5 ruAFij5jAW8gbS4OQNx96eHo0SmudmCHdgJ3asgyFZswXVekXN/ffMYANbKYL0UN13Ce /Sbp3sQdJnM50ZRPYE/MnikhPG5IDmuFiZSiALpUz0WxeMjeJXkpsw9kFWF1hng+qAU2 gSag== 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=YgHP9bBXJZShDaL7aOvh2TA2drwYpBwU8fA82XoIezE=; b=hu0iFh3udBhomz1nYDauSQx2yCeQk15HEgx71BhWCMYdxnW29cBMw7XezyibBJ6jxJ thdnOEf8DR8cupHvc0Ztb71U+qdZieRSSVBDZgiZ6w8gIMea6dLpMae7HMgYi1WOcfUt NVCgdcqbTfsKaRAkH1qcfhY4ZaNRWqFWMeWy0Nw5g8/BJlu8cssVh7ipv6ImdFZoQ7Vd dledinPIbpdW96p6LOYullIXH0peEOOl9++ii0Bzj6P11/mVZCT8baLEr5GVcWj0jZQb D3iuZYh7YyjFafCuwiWd632BYXUuMpoNxlqQ2cGXU5CeMpnqKWogzDTTvAH1G9DVdH87 /RZA== X-Gm-Message-State: ANhLgQ1PsUW2HKYz+w4l06E+0QDSFRiy2MXM4xWIoME/pJvhV1DMkRRK IXAFd2jCZlXyna4luJA3XqKO0miYeyg= X-Google-Smtp-Source: ADFU+vva5W4B1Hs196odl6rPQgxitTbKhrNEhXlYIDMLH0NYAZCChVaXkrV1ZiRp5NxeGjySFWxRzg== X-Received: by 2002:ac8:111a:: with SMTP id c26mr18014152qtj.249.1584892534468; Sun, 22 Mar 2020 08:55:34 -0700 (PDT) Received: from localhost.localdomain ([2804:1b2:8082:f225:59d4:a024:6301:5915]) by smtp.gmail.com with ESMTPSA id r40sm10297286qtc.39.2020.03.22.08.55.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Mar 2020 08:55:33 -0700 (PDT) From: Ramiro Polla To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Mar 2020 16:55:24 +0100 Message-Id: <20200322155525.23410-1-ramiro.polla@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/mpegvideo_enc: fix multi-threaded motion estimation rounding for mpeg4 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: Ramiro Polla MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" ff_init_me() was being called after ff_update_duplicate_context(), which caused the propagation of the initialization to other thread contexts to be delayed by one frame. In the case of mpeg4 (or flipflop_rounding), this would make the hpel_put functions differ between the first thread (which would be correctly initialized) and the other threads (which would be stale from the previous frame). --- libavcodec/mpegvideo_enc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index b2eb9cf318..8c2672f76a 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -3699,6 +3699,9 @@ static int encode_picture(MpegEncContext *s, int picture_number) s->q_chroma_intra_matrix16 = s->q_intra_matrix16; } + if(ff_init_me(s)<0) + return -1; + s->mb_intra=0; //for the rate distortion & bit compare functions for(i=1; ithread_context[i], s); @@ -3706,9 +3709,6 @@ static int encode_picture(MpegEncContext *s, int picture_number) return ret; } - if(ff_init_me(s)<0) - return -1; - /* Estimate motion for every MB */ if(s->pict_type != AV_PICTURE_TYPE_I){ s->lambda = (s->lambda * s->me_penalty_compensation + 128) >> 8; From patchwork Sun Mar 22 15:55:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramiro Polla X-Patchwork-Id: 18353 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 CF56044A8B2 for ; Sun, 22 Mar 2020 18:02:53 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AE81768B0D6; Sun, 22 Mar 2020 18:02:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E344D68B08E for ; Sun, 22 Mar 2020 18:02:46 +0200 (EET) Received: by mail-qt1-f193.google.com with SMTP id t9so5595296qto.9 for ; Sun, 22 Mar 2020 09:02:46 -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; bh=XYBkY0IYhpgjN5YRvNePwxty2PQPk/KplH025lIvD9E=; b=dXhHuGvrNVF/OXxehzwoJmXwx6qCf+lDyHPkrnn8b2gOqh/UaTCKP5QkIR1TmRKhNB II5V0g/aChBaPUvYKZKpVBjHDgVc2uY8FKIRmVeUyXvAc/+pVKF6u+rSzpdoDd8aWw3c k14Leenq8fyUyCSmBRLW0x7CKsdoh0A7okGYacrGU1BvM9c860RZukJC9X9HOprBaZDr 5Lwuafe8oaI9PI7ONAJk2oXz7sEQ+qucx4F+ic+eyRXaCoW68VYbNGHiNWltRkcycB6Y zvpnMSDxqGzL1DQ8jjlG6H/UiaijqZsEP39N4pznfoiShS3yAom0p5nIP7bX0eQx+uq4 NI5A== 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; bh=XYBkY0IYhpgjN5YRvNePwxty2PQPk/KplH025lIvD9E=; b=kOs2i4Yqq5n/6bEQmAN3LLEydxG2Yk/u/imf1Rg0W+QCt7gcszikMBvUbqeAbXdJna NFcjU030wUyGdf2ZZT4Ad4TKdkh0fgQuljidUH6osb402EdsVZy91YnxUDmRYUilmptJ LuJAD3WSSeoQxpvAvsKEvBbl815hyWkU14ZOwXgo4jpVyLipkOjoBjNJsBgaF6dA/px8 hcVj7kMm6P8OVRsHu+oEa/Ru3iTgPvzzdm2tW1HGHC87tv+YSc8QHi9vD8is7NBNGXyT XdJ5TBlQuc+84fXvITOWcyGTbqxVewwrm+zwryR7vbuOTJaMq+CG8Fbc/6GjJk/a6Cgw 75PQ== X-Gm-Message-State: ANhLgQ0rc0V95xbyh0WnSZMcAEyabwuJ775DIUTkQPPe8G7hZCZY0wt5 VA2JF1KfqH3a66bmbFpBMJ+GO77U7Ig= X-Google-Smtp-Source: ADFU+vuZXfTo2nDEyFCdLUlbFtaMDaxnDctXjlhEQe6cWuoL2fPAzE1LvssD47rHi1E+JiRXCyBdIw== X-Received: by 2002:aed:2591:: with SMTP id x17mr17619097qtc.380.1584892539366; Sun, 22 Mar 2020 08:55:39 -0700 (PDT) Received: from localhost.localdomain ([2804:1b2:8082:f225:59d4:a024:6301:5915]) by smtp.gmail.com with ESMTPSA id r40sm10297286qtc.39.2020.03.22.08.55.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Mar 2020 08:55:38 -0700 (PDT) From: Ramiro Polla To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Mar 2020 16:55:25 +0100 Message-Id: <20200322155525.23410-2-ramiro.polla@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200322155525.23410-1-ramiro.polla@gmail.com> References: <20200322155525.23410-1-ramiro.polla@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/motion_est: fix penalty_factor for b frames 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: Ramiro Polla MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" In ff_estimate_b_frame_motion(), penalty_factor would be used before being initialized in estimate_motion_b(). Also, the initialization would happen more than once unnecessarily. --- libavcodec/motion_est.c | 15 ++++++++------- tests/ref/vsynth/vsynth2-mpeg2-422 | 6 +++--- tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd | 6 +++--- tests/ref/vsynth/vsynth2-mpeg4-adap | 6 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 02c75fd470..1feb46cec3 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1123,9 +1123,6 @@ static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y, uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_DMV; int mv_scale; - c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); - c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); - c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); c->current_mv_penalty= mv_penalty; get_limits(s, 16*mb_x, 16*mb_y); @@ -1491,7 +1488,6 @@ void ff_estimate_b_frame_motion(MpegEncContext * s, int mb_x, int mb_y) { MotionEstContext * const c= &s->me; - const int penalty_factor= c->mb_penalty_factor; int fmin, bmin, dmin, fbmin, bimin, fimin; int type=0; const int xy = mb_y*s->mb_stride + mb_x; @@ -1517,18 +1513,23 @@ void ff_estimate_b_frame_motion(MpegEncContext * s, dmin= direct_search(s, mb_x, mb_y); else dmin= INT_MAX; + + c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); + c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); + c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); + // FIXME penalty stuff for non-MPEG-4 c->skip=0; fmin = estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + - 3 * penalty_factor; + 3 * c->mb_penalty_factor; c->skip=0; bmin = estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + - 2 * penalty_factor; + 2 * c->mb_penalty_factor; ff_dlog(s, " %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]); c->skip=0; - fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor; + fbmin= bidir_refine(s, mb_x, mb_y) + c->mb_penalty_factor; ff_dlog(s, "%d %d %d %d\n", dmin, fmin, bmin, fbmin); if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) { diff --git a/tests/ref/vsynth/vsynth2-mpeg2-422 b/tests/ref/vsynth/vsynth2-mpeg2-422 index ec7244f9f9..e945a4cc0e 100644 --- a/tests/ref/vsynth/vsynth2-mpeg2-422 +++ b/tests/ref/vsynth/vsynth2-mpeg2-422 @@ -1,4 +1,4 @@ -b2fa9b73c3547191ecc01b8163abd4e5 *tests/data/fate/vsynth2-mpeg2-422.mpeg2video -379164 tests/data/fate/vsynth2-mpeg2-422.mpeg2video -704f6a96f93c2409219bd48b74169041 *tests/data/fate/vsynth2-mpeg2-422.out.rawvideo +6fc8dc1d76379e459051ca393101c090 *tests/data/fate/vsynth2-mpeg2-422.mpeg2video +379173 tests/data/fate/vsynth2-mpeg2-422.mpeg2video +9199d5aaa1709d2584e21e58d76d44fb *tests/data/fate/vsynth2-mpeg2-422.out.rawvideo stddev: 4.17 PSNR: 35.73 MAXDIFF: 70 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd b/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd index 16de39edfc..f5bbecfcb2 100644 --- a/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd +++ b/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd @@ -1,4 +1,4 @@ -907a30295ed8323780eee08e606af0ab *tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video -269722 tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video -d2d9793bf8f3427b5cc17a1be78ddd64 *tests/data/fate/vsynth2-mpeg2-ivlc-qprd.out.rawvideo +f612ea89aa79a7f7b93a8acf332705c4 *tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video +269723 tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video +88e17886e6383755829d7da519fd5e79 *tests/data/fate/vsynth2-mpeg2-ivlc-qprd.out.rawvideo stddev: 5.54 PSNR: 33.25 MAXDIFF: 94 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth2-mpeg4-adap b/tests/ref/vsynth/vsynth2-mpeg4-adap index a3223f6363..1ae0a65e4f 100644 --- a/tests/ref/vsynth/vsynth2-mpeg4-adap +++ b/tests/ref/vsynth/vsynth2-mpeg4-adap @@ -1,4 +1,4 @@ -4bff98da2342836476da817428594403 *tests/data/fate/vsynth2-mpeg4-adap.avi -213508 tests/data/fate/vsynth2-mpeg4-adap.avi -0c709f2b81f4593eaa29490332c2cb39 *tests/data/fate/vsynth2-mpeg4-adap.out.rawvideo +fcb79c0dcc00b306b79c354e589b6b69 *tests/data/fate/vsynth2-mpeg4-adap.avi +213526 tests/data/fate/vsynth2-mpeg4-adap.avi +71a34a48a81485f938d2c60a3d34ed39 *tests/data/fate/vsynth2-mpeg4-adap.out.rawvideo stddev: 4.87 PSNR: 34.36 MAXDIFF: 86 bytes: 7603200/ 7603200