From ac6283a7d26bad8814372ca70bb8e980a51209dd Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Wed, 19 Mar 2025 12:53:44 +0100
Subject: [PATCH 66/77] avcodec/mpegvideo_enc: Don't reset statistics twice

This happens currently for the non-main slice contexts.
But these variables get reset at the start of encode_thread()
anyway for all slices, so this is unnecessary.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpegvideo_enc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6c1d157b64..7492a9fdbd 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3585,6 +3585,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
     return 0;
 }
 
+#define ADD(field)   dst->field += src->field;
 #define MERGE(field) dst->field += src->field; src->field=0
 static void merge_context_after_me(MPVEncContext *const dst, MPVEncContext *const src)
 {
@@ -3599,14 +3600,14 @@ static void merge_context_after_encode(MPVEncContext *const dst, MPVEncContext *
 
     MERGE(dct_count[0]); //note, the other dct vars are not part of the context
     MERGE(dct_count[1]);
-    MERGE(mv_bits);
-    MERGE(i_tex_bits);
-    MERGE(p_tex_bits);
-    MERGE(i_count);
-    MERGE(misc_bits);
-    MERGE(encoding_error[0]);
-    MERGE(encoding_error[1]);
-    MERGE(encoding_error[2]);
+    ADD(mv_bits);
+    ADD(i_tex_bits);
+    ADD(p_tex_bits);
+    ADD(i_count);
+    ADD(misc_bits);
+    ADD(encoding_error[0]);
+    ADD(encoding_error[1]);
+    ADD(encoding_error[2]);
 
     if (dst->dct_error_sum) {
         for(i=0; i<64; i++){
-- 
2.45.2