diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 99e31be463..48d26f37cd 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1105,10 +1105,6 @@ static inline void add_dequant_dct(MpegEncContext *s,
  */
 static void mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
 {
-    const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
-
-    s->cur_pic.qscale_table[mb_xy] = s->qscale;
-
     if (s->avctx->debug & FF_DEBUG_DCT_COEFF) {
        /* print DCT coefficients */
        av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
@@ -3365,8 +3361,6 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     }
                 }
 
-                s->cur_pic.qscale_table[xy] = best_s.qscale;
-
                 copy_context_after_encode(s, &best_s);
 
                 pb_bits_count= put_bits_count(&s->pb);
@@ -3521,6 +3515,8 @@ static int encode_thread(AVCodecContext *c, void *arg){
                 mpv_reconstruct_mb(s, s->block);
             }
 
+            s->cur_pic.qscale_table[xy] = s->qscale;
+
             /* clean the MV table in IPS frames for direct mode in B-frames */
             if(s->mb_intra /* && I,P,S_TYPE */){
                 s->p_mv_table[xy][0]=0;
diff --git a/tests/ref/seek/vsynth_lena-mpeg4-adap b/tests/ref/seek/vsynth_lena-mpeg4-adap
index fe841ef973..7777491651 100644
--- a/tests/ref/seek/vsynth_lena-mpeg4-adap
+++ b/tests/ref/seek/vsynth_lena-mpeg4-adap
@@ -2,45 +2,45 @@ ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:   5652 size:  6855
 ret: 0         st:-1 flags:0  ts:-1.000000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:   5652 size:  6855
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161318 size: 19176
+ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161352 size: 19191
 ret: 0         st: 0 flags:0  ts: 0.800000
-ret: 0         st: 0 flags:1 dts: 0.880000 pts: NOPTS    pos:  75056 size: 19178
+ret: 0         st: 0 flags:1 dts: 0.880000 pts: NOPTS    pos:  75104 size: 19178
 ret:-1         st: 0 flags:1  ts:-0.320000
 ret:-1         st:-1 flags:0  ts: 2.576668
 ret: 0         st:-1 flags:1  ts: 1.470835
-ret: 0         st: 0 flags:1 dts: 1.360000 pts: NOPTS    pos: 118696 size: 20018
+ret: 0         st: 0 flags:1 dts: 1.360000 pts: NOPTS    pos: 118586 size: 20060
 ret: 0         st: 0 flags:0  ts: 0.360000
-ret: 0         st: 0 flags:1 dts: 0.400000 pts: NOPTS    pos:  35800 size: 17261
+ret: 0         st: 0 flags:1 dts: 0.400000 pts: NOPTS    pos:  35840 size: 17261
 ret:-1         st: 0 flags:1  ts:-0.760000
 ret:-1         st:-1 flags:0  ts: 2.153336
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 0.880000 pts: NOPTS    pos:  75056 size: 19178
+ret: 0         st: 0 flags:1 dts: 0.880000 pts: NOPTS    pos:  75104 size: 19178
 ret: 0         st: 0 flags:0  ts:-0.040000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:   5652 size:  6855
 ret: 0         st: 0 flags:1  ts: 2.840000
-ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161318 size: 19176
+ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161352 size: 19191
 ret: 0         st:-1 flags:0  ts: 1.730004
-ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161318 size: 19176
+ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161352 size: 19191
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.400000 pts: NOPTS    pos:  35800 size: 17261
+ret: 0         st: 0 flags:1 dts: 0.400000 pts: NOPTS    pos:  35840 size: 17261
 ret: 0         st: 0 flags:0  ts:-0.480000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:   5652 size:  6855
 ret: 0         st: 0 flags:1  ts: 2.400000
-ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161318 size: 19176
+ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161352 size: 19191
 ret: 0         st:-1 flags:0  ts: 1.306672
-ret: 0         st: 0 flags:1 dts: 1.360000 pts: NOPTS    pos: 118696 size: 20018
+ret: 0         st: 0 flags:1 dts: 1.360000 pts: NOPTS    pos: 118586 size: 20060
 ret: 0         st:-1 flags:1  ts: 0.200839
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:   5652 size:  6855
 ret: 0         st: 0 flags:0  ts:-0.920000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:   5652 size:  6855
 ret: 0         st: 0 flags:1  ts: 2.000000
-ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161318 size: 19176
+ret: 0         st: 0 flags:1 dts: 1.840000 pts: NOPTS    pos: 161352 size: 19191
 ret: 0         st:-1 flags:0  ts: 0.883340
-ret: 0         st: 0 flags:1 dts: 0.880000 pts: NOPTS    pos:  75056 size: 19178
+ret: 0         st: 0 flags:1 dts: 0.880000 pts: NOPTS    pos:  75104 size: 19178
 ret:-1         st:-1 flags:1  ts:-0.222493
 ret:-1         st: 0 flags:0  ts: 2.680000
 ret: 0         st: 0 flags:1  ts: 1.560000
-ret: 0         st: 0 flags:1 dts: 1.360000 pts: NOPTS    pos: 118696 size: 20018
+ret: 0         st: 0 flags:1 dts: 1.360000 pts: NOPTS    pos: 118586 size: 20060
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.880000 pts: NOPTS    pos:  75056 size: 19178
+ret: 0         st: 0 flags:1 dts: 0.880000 pts: NOPTS    pos:  75104 size: 19178
 ret:-1         st:-1 flags:1  ts:-0.645825
diff --git a/tests/ref/vsynth/vsynth1-mpeg4-adap b/tests/ref/vsynth/vsynth1-mpeg4-adap
index 67705f0f43..d3ad12e921 100644
--- a/tests/ref/vsynth/vsynth1-mpeg4-adap
+++ b/tests/ref/vsynth/vsynth1-mpeg4-adap
@@ -1,4 +1,4 @@
-0f1cbbdc3f9b91f2d9ac3d1fc2cf7d4e *tests/data/fate/vsynth1-mpeg4-adap.avi
-325518 tests/data/fate/vsynth1-mpeg4-adap.avi
-1e6c596f9f491fbf15920ef1bace7fb8 *tests/data/fate/vsynth1-mpeg4-adap.out.rawvideo
-stddev:   14.12 PSNR: 25.13 MAXDIFF:  184 bytes:  7603200/  7603200
+3b4fe7ad106cb112364d062b20ad80a8 *tests/data/fate/vsynth1-mpeg4-adap.avi
+325594 tests/data/fate/vsynth1-mpeg4-adap.avi
+96c5a7759413ab24afaa926abb3c5fe0 *tests/data/fate/vsynth1-mpeg4-adap.out.rawvideo
+stddev:   14.11 PSNR: 25.13 MAXDIFF:  184 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-adap b/tests/ref/vsynth/vsynth2-mpeg4-adap
index e058cd1ce3..140b17649c 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-adap
+++ b/tests/ref/vsynth/vsynth2-mpeg4-adap
@@ -1,4 +1,4 @@
-9465ef120d560537d8fcfb5564782e01 *tests/data/fate/vsynth2-mpeg4-adap.avi
-203004 tests/data/fate/vsynth2-mpeg4-adap.avi
-d7851ab1ca9744f8e618a24193e5ef76 *tests/data/fate/vsynth2-mpeg4-adap.out.rawvideo
-stddev:    4.56 PSNR: 34.95 MAXDIFF:   84 bytes:  7603200/  7603200
+21d205e0f42ce613481b202d52593225 *tests/data/fate/vsynth2-mpeg4-adap.avi
+202870 tests/data/fate/vsynth2-mpeg4-adap.avi
+1c45877fe27fb5fbfcdaff4a1da94de4 *tests/data/fate/vsynth2-mpeg4-adap.out.rawvideo
+stddev:    4.55 PSNR: 34.95 MAXDIFF:   84 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth3-mpeg4-adap b/tests/ref/vsynth/vsynth3-mpeg4-adap
index 6386f13466..70a25831d9 100644
--- a/tests/ref/vsynth/vsynth3-mpeg4-adap
+++ b/tests/ref/vsynth/vsynth3-mpeg4-adap
@@ -1,4 +1,4 @@
-6b2f641f2e68b11b992fd6ba1ed66a21 *tests/data/fate/vsynth3-mpeg4-adap.avi
-41012 tests/data/fate/vsynth3-mpeg4-adap.avi
-3483a2032cb02c3a37f5e43b128e59ed *tests/data/fate/vsynth3-mpeg4-adap.out.rawvideo
-stddev:    5.79 PSNR: 32.87 MAXDIFF:   49 bytes:    86700/    86700
+10512ee1a666ed95643557e1cf699363 *tests/data/fate/vsynth3-mpeg4-adap.avi
+41100 tests/data/fate/vsynth3-mpeg4-adap.avi
+9ba2c3cab3f08d2a345b849d0b30e3e1 *tests/data/fate/vsynth3-mpeg4-adap.out.rawvideo
+stddev:    5.79 PSNR: 32.88 MAXDIFF:   49 bytes:    86700/    86700
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-adap b/tests/ref/vsynth/vsynth_lena-mpeg4-adap
index 91edafe9b0..912b9b2efa 100644
--- a/tests/ref/vsynth/vsynth_lena-mpeg4-adap
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-adap
@@ -1,4 +1,4 @@
-633da125f46391eef33bb031cd728f4b *tests/data/fate/vsynth_lena-mpeg4-adap.avi
-187598 tests/data/fate/vsynth_lena-mpeg4-adap.avi
-21312bfcb28c40299fb27a5b03477f8c *tests/data/fate/vsynth_lena-mpeg4-adap.out.rawvideo
-stddev:    3.63 PSNR: 36.92 MAXDIFF:   71 bytes:  7603200/  7603200
+5af033cfe87bc2abf688b602e5a1a35c *tests/data/fate/vsynth_lena-mpeg4-adap.avi
+187652 tests/data/fate/vsynth_lena-mpeg4-adap.avi
+515efcfb456cf7b460f356fe0dc7c808 *tests/data/fate/vsynth_lena-mpeg4-adap.out.rawvideo
+stddev:    3.63 PSNR: 36.93 MAXDIFF:   71 bytes:  7603200/  7603200
