From df3ea2c7516e6cdbb3c5c4befb80744d7a291099 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 19 Mar 2025 14:47:00 +0100 Subject: [PATCH 70/77] 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@outlook.com> --- 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 116ca007ba..62e3e5a22f 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -3720,8 +3720,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); @@ -3732,12 +3735,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 */ -- 2.45.2