diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c

index 2eaffa5..dca5d76 100644 (file)

--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1097,6 +1097,7 @@ static int h264_slice_header_init(H264Context *h)
         nb_slices = max_slices;
     }
     h->slice_context_count = nb_slices;
+    h->max_contexts = FFMIN(h->max_contexts, nb_slices);
 
     if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_SLICE)) {
         ret = ff_h264_slice_context_init(h, &h->slice_ctx[0]);
