diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 7ad93f9e4c..07c82cc54d 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -632,6 +632,8 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64],
 
             if ((cbp | motion_x | motion_y | s->dquant) == 0 &&
                 s->mv_type == MV_TYPE_16X16) {
+                const MPVMainEncContext *const m =
+                     (MPVMainEncContext *)s->parent_ctx;
                 /* Check if the B-frames can skip it too, as we must skip it
                  * if we skip here why didn't they just compress
                  * the skip-mb bits instead of reusing them ?! */
@@ -648,9 +650,9 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64],
 
                     s->mb_skipped = 1;
                     for (i = 0; i < s->max_b_frames; i++) {
+                        const Picture *const pic = m->reordered_input_picture[i + 1];
                         uint8_t *b_pic;
                         int diff;
-                        Picture *pic = s->reordered_input_picture[i + 1];
 
                         if (!pic || pic->f->pict_type != AV_PICTURE_TYPE_B)
                             break;
@@ -890,8 +892,8 @@ static void mpeg4_encode_gop_header(MPVMainEncContext *m)
     put_bits(&s->pb, 16, GOP_STARTCODE);
 
     time = s->current_picture_ptr->f->pts;
-    if (s->reordered_input_picture[1])
-        time = FFMIN(time, s->reordered_input_picture[1]->f->pts);
+    if (m->reordered_input_picture[1])
+        time = FFMIN(time, m->reordered_input_picture[1]->f->pts);
     time = time * s->avctx->time_base.num;
     s->last_time_base = FFUDIV(time, s->avctx->time_base.den);
 
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 4a03cde7fe..fefcb90188 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -115,7 +115,6 @@ typedef struct MPVContext {
     ptrdiff_t linesize;        ///< line size, in bytes, may be different from width
     ptrdiff_t uvlinesize;      ///< line size, for chroma in bytes, may be different from width
     Picture *picture;          ///< main picture buffer
-    Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding
 
     /** bit output */
     PutBitContext pb;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index aef4de0fe6..4a90799d17 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -871,8 +871,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         }
     }
 
-    if (!(avctx->stats_out = av_mallocz(256))               ||
-        !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT))
+    if (!(avctx->stats_out = av_mallocz(256)))
         return AVERROR(ENOMEM);
 
     if (s->noise_reduction) {
@@ -1017,7 +1016,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
     av_freep(&m->cplx_tab);
     av_freep(&m->bits_tab);
 
-    av_freep(&s->reordered_input_picture);
     av_freep(&s->dct_offset);
 
     return 0;
@@ -1438,11 +1436,11 @@ static int select_input_picture(MPVMainEncContext *m)
     int i, ret;
 
     for (i = 1; i < MAX_PICTURE_COUNT; i++)
-        s->reordered_input_picture[i - 1] = s->reordered_input_picture[i];
-    s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL;
+        m->reordered_input_picture[i - 1] = m->reordered_input_picture[i];
+    m->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL;
 
     /* set next picture type & ordering */
-    if (!s->reordered_input_picture[0] && m->input_picture[0]) {
+    if (!m->reordered_input_picture[0] && m->input_picture[0]) {
         if (s->frame_skip_threshold || s->frame_skip_factor) {
             if (m->picture_in_gop_number < m->gop_size &&
                 s->next_picture_ptr &&
@@ -1458,9 +1456,9 @@ static int select_input_picture(MPVMainEncContext *m)
 
         if (/*s->picture_in_gop_number >= s->gop_size ||*/
             !s->next_picture_ptr || s->intra_only) {
-            s->reordered_input_picture[0] = m->input_picture[0];
-            s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;
-            s->reordered_input_picture[0]->f->coded_picture_number =
+            m->reordered_input_picture[0] = m->input_picture[0];
+            m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;
+            m->reordered_input_picture[0]->f->coded_picture_number =
                 s->coded_picture_number++;
         } else {
             int b_frames = 0;
@@ -1543,16 +1541,16 @@ static int select_input_picture(MPVMainEncContext *m)
                 m->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I)
                 b_frames--;
 
-            s->reordered_input_picture[0] = m->input_picture[b_frames];
-            if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)
-                s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;
-            s->reordered_input_picture[0]->f->coded_picture_number =
+            m->reordered_input_picture[0] = m->input_picture[b_frames];
+            if (m->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)
+                m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;
+            m->reordered_input_picture[0]->f->coded_picture_number =
                 s->coded_picture_number++;
             for (i = 0; i < b_frames; i++) {
-                s->reordered_input_picture[i + 1] = m->input_picture[i];
-                s->reordered_input_picture[i + 1]->f->pict_type =
+                m->reordered_input_picture[i + 1] = m->input_picture[i];
+                m->reordered_input_picture[i + 1]->f->pict_type =
                     AV_PICTURE_TYPE_B;
-                s->reordered_input_picture[i + 1]->f->coded_picture_number =
+                m->reordered_input_picture[i + 1]->f->coded_picture_number =
                     s->coded_picture_number++;
             }
         }
@@ -1560,15 +1558,16 @@ static int select_input_picture(MPVMainEncContext *m)
 no_output_pic:
     ff_mpeg_unref_picture(s->avctx, &s->new_picture);
 
-    if (s->reordered_input_picture[0]) {
-        s->reordered_input_picture[0]->reference =
-           s->reordered_input_picture[0]->f->pict_type !=
+    if (m->reordered_input_picture[0]) {
+        m->reordered_input_picture[0]->reference =
+           m->reordered_input_picture[0]->f->pict_type !=
                AV_PICTURE_TYPE_B ? 3 : 0;
 
-        if ((ret = ff_mpeg_ref_picture(s->avctx, &s->new_picture, s->reordered_input_picture[0])))
+        if ((ret = ff_mpeg_ref_picture(s->avctx, &s->new_picture,
+                                       m->reordered_input_picture[0])))
             return ret;
 
-        if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) {
+        if (m->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) {
             // input is a shared pix, so we can't modify it -> allocate a new
             // one & ensure that the shared one is reuseable
 
@@ -1578,23 +1577,23 @@ no_output_pic:
                 return i;
             pic = &s->picture[i];
 
-            pic->reference = s->reordered_input_picture[0]->reference;
+            pic->reference = m->reordered_input_picture[0]->reference;
             if (alloc_picture(s, pic, 0) < 0) {
                 return -1;
             }
 
-            ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f);
+            ret = av_frame_copy_props(pic->f, m->reordered_input_picture[0]->f);
             if (ret < 0)
                 return ret;
 
             /* mark us unused / free shared pic */
-            av_frame_unref(s->reordered_input_picture[0]->f);
-            s->reordered_input_picture[0]->shared = 0;
+            av_frame_unref(m->reordered_input_picture[0]->f);
+            m->reordered_input_picture[0]->shared = 0;
 
             s->current_picture_ptr = pic;
         } else {
             // input is not a shared pix -> reuse buffer for current_pix
-            s->current_picture_ptr = s->reordered_input_picture[0];
+            s->current_picture_ptr = m->reordered_input_picture[0];
             for (i = 0; i < 4; i++) {
                 if (s->new_picture.f->data[i])
                     s->new_picture.f->data[i] += INPLACE_OFFSET;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 6dc940d3aa..91d41f86e8 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -40,6 +40,8 @@ typedef struct MPVMainEncContext {
     MPVMainContext common;
 
     Picture *input_picture[MAX_PICTURE_COUNT];   ///< next pictures in display order
+    /** pointer to the next pictures in coded order */
+    Picture *reordered_input_picture[MAX_PICTURE_COUNT];
 
     int me_penalty_compensation;
     int me_pre;                          ///< prepass for motion estimation
