[FFmpeg-cvslog] avcodec/mpegvideo_enc: Move code to initialize variables immediately

Andreas Rheinhardt git at videolan.org
Wed Mar 26 06:10:57 EET 2025


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Wed Mar 19 14:47:00 2025 +0100| [479dac17f889b4e037448e8e3c27e17073819ec4] | committer: Andreas Rheinhardt

avcodec/mpegvideo_enc: Move code to initialize variables immediately

Also avoid casts and parentheses.
(This is only possible now because ff_update_duplicate_context()
no longer touches the PutBitContext.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=479dac17f889b4e037448e8e3c27e17073819ec4
---

 libavcodec/mpegvideo_enc.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index c8206015dc..f507fa5788 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3717,8 +3717,11 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
     s->c.mb_intra = 0; //for the rate distortion & bit compare functions
     for (int i = 0; i < context_count; i++) {
         MPVEncContext *const slice = s->c.enc_contexts[i];
-        uint8_t *start, *end;
-        int h;
+        int h = s->c.mb_height;
+        uint8_t *start = pkt->data + (int64_t)pkt->size * slice->c.start_mb_y / h;
+        uint8_t *end   = pkt->data + (int64_t)pkt->size * slice->c.  end_mb_y / h;
+
+        init_put_bits(&slice->pb, start, end - start);
 
         if (i) {
             ret = ff_update_duplicate_context(&slice->c, &s->c);
@@ -3729,12 +3732,6 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
         }
         slice->me.temp = slice->me.scratchpad = slice->c.sc.scratchpad_buf;
         ff_me_init_pic(slice);
-
-        h     = s->c.mb_height;
-        start = pkt->data + (size_t)(((int64_t) pkt->size) * slice->c.start_mb_y / h);
-        end   = pkt->data + (size_t)(((int64_t) pkt->size) * slice->c.  end_mb_y / h);
-
-        init_put_bits(&s->c.enc_contexts[i]->pb, start, end - start);
     }
 
     /* Estimate motion for every MB */



More information about the ffmpeg-cvslog mailing list