diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 8113d2ff7d..8774f4e7ad 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -625,7 +625,7 @@ retry:
         ff_mpv_common_end(m);
     }
 
-    if (!s->context_initialized) {
+    if (!m->context_initialized) {
         if ((ret = ff_mpv_common_init(m)) < 0)
             return ret;
 
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 20a1348d88..b502878a4a 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -498,7 +498,7 @@ retry:
     if (ret < 0)
         return ret;
 
-    if (!s->context_initialized)
+    if (!m->context_initialized)
         // we need the idct permutation for reading a custom matrix
         ff_mpv_idct_init(s);
 
@@ -540,7 +540,7 @@ retry:
         return ret;
     }
 
-    if (!s->context_initialized) {
+    if (!m->context_initialized) {
         avctx->pix_fmt = h263_get_format(avctx);
         if ((ret = ff_mpv_common_init(m)) < 0)
             return ret;
@@ -568,9 +568,9 @@ retry:
      * an H263EncContext */
     if (s->width  != avctx->coded_width  ||
         s->height != avctx->coded_height ||
-        s->context_reinit) {
+        m->context_reinit) {
         /* H.263 could change picture size any time */
-        s->context_reinit = 0;
+        m->context_reinit = 0;
 
         ret = ff_set_dimensions(avctx, s->width, s->height);
         if (ret < 0)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 69d0bb809b..3b21b88337 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1087,7 +1087,7 @@ static int mpeg_decode_update_thread_context(AVCodecContext *avctx,
 
     if (avctx == avctx_from               ||
         !ctx_from->mpeg_ctx_allocated ||
-        !s1->s.context_initialized)
+        !s1->context_initialized)
         return 0;
 
     err = ff_mpeg_update_thread_context(avctx, avctx_from);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 6e3981b523..ca6988fc48 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -2324,7 +2324,7 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
             return AVERROR_PATCHWELCOME;
         }
         if (rgb != ctx->rgb || s->chroma_format != chroma_format)
-            s->context_reinit = 1;
+            m->context_reinit = 1;
         s->avctx->bits_per_raw_sample = bits_per_raw_sample;
         ctx->rgb = rgb;
         s->chroma_format = chroma_format;
@@ -2340,7 +2340,7 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
         if (width && height) {
             if (s->width && s->height &&
                 (s->width != width || s->height != height))
-                s->context_reinit = 1;
+                m->context_reinit = 1;
             s->width  = width;
             s->height = height;
         }
@@ -2489,7 +2489,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
                 !(s->width && s->codec_tag == AV_RL32("MP4S"))) {
                 if (s->width && s->height &&
                     (s->width != width || s->height != height))
-                    s->context_reinit = 1;
+                    m->context_reinit = 1;
                 s->width  = width;
                 s->height = height;
             }
@@ -3527,7 +3527,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
 {
     Mpeg4DecContext *s = dst->priv_data;
     const Mpeg4DecContext *s1 = src->priv_data;
-    int init = s->m.s.context_initialized;
+    int init = s->m.context_initialized;
 
     int ret = ff_mpeg_update_thread_context(dst, src);
 
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 0e98680056..be18b428f5 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -737,7 +737,7 @@ av_cold int ff_mpv_common_init(MPVMainContext *m)
     s->parse_context.state = -1;
 #endif
 
-    s->context_initialized = 1;
+    m->context_initialized = 1;
     m->thread_context[0]   = s;
     m->slice_context_count = nb_slices;
 
@@ -814,8 +814,8 @@ void ff_mpv_common_end(MPVMainContext *m)
     ff_mpv_picture_free(s->avctx, &s->next_picture);
     ff_mpv_picture_free(s->avctx, &s->new_picture);
 
-    s->context_initialized      = 0;
-    s->context_reinit           = 0;
+    m->context_initialized      = 0;
+    m->context_reinit           = 0;
     s->last_picture_ptr         =
     s->next_picture_ptr         =
     s->current_picture_ptr      = NULL;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 8632fadae5..df5a51577a 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -103,7 +103,6 @@ typedef struct MPVContext {
     /* the following fields are managed internally by the encoder */
 
     /* sequence parameters */
-    int context_initialized;
     int coded_picture_number;  ///< used to set pic->coded_picture_number, should not be used for/by anything else
     int picture_number;       //FIXME remove, unclear definition
     int mb_width, mb_height;   ///< number of MBs horizontally & vertically
@@ -460,10 +459,6 @@ typedef struct MPVContext {
 
     int vbv_ignore_qmax;
 
-    /* flag to indicate a reinitialization is required, e.g. after
-     * a frame size change */
-    int context_reinit;
-
     ERContext er;
 
     int error_rate;
@@ -505,6 +500,11 @@ typedef struct MPVContext {
 typedef struct MPVMainContext {
     MPVContext s;
 
+    int context_initialized;
+    /* flag to indicate a reinitialization is required, e.g. after
+     * a frame size change */
+    int context_reinit;
+
     int slice_context_count;   ///< number of used thread_contexts
     /* The first entry of this array points to the above MPVContext. */
     MPVContext *thread_context[MAX_THREADS];
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 57c93de621..a4f751af71 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -66,7 +66,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
 
     // FIXME can parameters change on I-frames?
     // in that case dst may need a reinit
-    if (!s->context_initialized) {
+    if (!m->context_initialized) {
         void *private_ctx = s->private_ctx;
         int err;
         memcpy(s, s1, sizeof(*s));
@@ -77,7 +77,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
         s->bitstream_buffer      = NULL;
         s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;
 
-        if (s1->context_initialized) {
+        if (m1->context_initialized) {
 //             s->picture_range_start  += MAX_PICTURE_COUNT;
 //             s->picture_range_end    += MAX_PICTURE_COUNT;
             ff_mpv_idct_init(s);
@@ -91,7 +91,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
         }
     }
 
-    if (s->height != s1->height || s->width != s1->width || s->context_reinit) {
+    if (s->height != s1->height || s->width != s1->width || m->context_reinit) {
         s->height = s1->height;
         s->width  = s1->width;
         if ((ret = ff_mpv_common_frame_size_change(m)) < 0)
@@ -202,7 +202,7 @@ int ff_mpv_common_frame_size_change(MPVMainDecContext *m)
     MPVDecContext *const s = &m->s;
     int err = 0;
 
-    if (!s->context_initialized)
+    if (!m2->context_initialized)
         return AVERROR(EINVAL);
 
     ff_mpv_free_context_frame(m2);
@@ -243,12 +243,12 @@ int ff_mpv_common_frame_size_change(MPVMainDecContext *m)
         if (err < 0)
             goto fail;
     }
-    s->context_reinit = 0;
+    m2->context_reinit = 0;
 
     return 0;
  fail:
     ff_mpv_free_context_frame(m2);
-    s->context_reinit = 1;
+    m2->context_reinit = 1;
     return err;
 }
 
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 1a59b2a578..27e17c8677 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -228,7 +228,7 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
             new_w = rv->orig_width;
             new_h = rv->orig_height;
         }
-        if (new_w != s->width || new_h != s->height || !s->context_initialized) {
+        if (new_w != s->width || new_h != s->height || !m->context_initialized) {
             AVRational old_aspect = s->avctx->sample_aspect_ratio;
             av_log(s->avctx, AV_LOG_DEBUG,
                    "attempting to change resolution to %dx%d\n", new_w, new_h);
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index a3437099b2..4ed23b65dd 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1384,7 +1384,7 @@ static int rv34_decoder_alloc(RV34DecContext *r)
 
     if (!(r->cbp_chroma       && r->cbp_luma && r->deblock_coefs &&
           r->intra_types_hist && r->mb_type)) {
-        r->s.s.context_reinit = 1;
+        r->s.context_reinit = 1;
         rv34_decoder_free(r);
         return AVERROR(ENOMEM);
     }
@@ -1524,10 +1524,10 @@ int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecConte
     const MPVDecContext *const s1 = &m1->s;
     int err;
 
-    if (dst == src || !s1->context_initialized)
+    if (dst == src || !m1->context_initialized)
         return 0;
 
-    if (s->height != s1->height || s->width != s1->width || s->context_reinit) {
+    if (s->height != s1->height || s->width != s1->width || m->context_reinit) {
         s->height = s1->height;
         s->width  = s1->width;
         if ((err = ff_mpv_common_frame_size_change(m)) < 0)
@@ -1544,7 +1544,7 @@ int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecConte
 
     // Do no call ff_mpeg_update_thread_context on a partially initialized
     // decoder context.
-    if (!s1->context_initialized)
+    if (!m1->context_initialized)
         return 0;
 
     return ff_mpeg_update_thread_context(dst, src);
@@ -1666,12 +1666,12 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
         if (s->mb_num_left > 0 && s->current_picture_ptr) {
             av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n",
                    s->mb_num_left);
-            if (!s->context_reinit)
+            if (!m->context_reinit)
                 ff_er_frame_end(&s->er);
             ff_mpv_frame_end(m);
         }
 
-        if (s->width != si.width || s->height != si.height || s->context_reinit) {
+        if (s->width != si.width || s->height != si.height || m->context_reinit) {
             int err;
 
             av_log(s->avctx, AV_LOG_WARNING, "Changing dimensions to %dx%d\n",
@@ -1743,7 +1743,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
         }
         s->mb_x = s->mb_y = 0;
         ff_thread_finish_setup(s->avctx);
-    } else if (s->context_reinit) {
+    } else if (m->context_reinit) {
         av_log(s->avctx, AV_LOG_ERROR, "Decoder needs full frames to "
                "reinitialize (start MB is %d).\n", si.start);
         return AVERROR_INVALIDDATA;
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 502ea2bae4..995761700b 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -797,13 +797,13 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
         }
     }
 
-    if (s->context_initialized &&
+    if (m->context_initialized &&
         (s->width  != avctx->coded_width ||
          s->height != avctx->coded_height)) {
         ff_vc1_decode_end(avctx);
     }
 
-    if (!s->context_initialized) {
+    if (!m->context_initialized) {
         if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
             goto err;
         if ((ret = ff_vc1_decode_init_alloc_tables(v)) < 0) {
