diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 1cee6346de3530c7c8ccfce5efdfe61d13e32f19..a63f45ad20119ac4238dabc113d3880dad002dc6 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1171,6 +1171,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
     }
 
     if (h->context_initialized && needs_reinit) {
+        h->context_initialized = 0;
         if (sl != h->slice_ctx) {
             av_log(h->avctx, AV_LOG_ERROR,
                    "changing width %d -> %d / height %d -> %d on "