diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index e2a2aec0bea832e58ead44c144ed3d6de0103fe4..61ad63733b5de4fa17e107b68ae48e5bade1aca5 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1206,54 +1206,6 @@ int ff_h264_get_profile(SPS *sps)
     return profile;
 }
 
-int ff_h264_set_parameter_from_sps(H264Context *h)
-{
-    if (h->flags & CODEC_FLAG_LOW_DELAY ||
-        (h->sps.bitstream_restriction_flag &&
-         !h->sps.num_reorder_frames)) {
-        if (h->avctx->has_b_frames > 1 || h->delayed_pic[0])
-            av_log(h->avctx, AV_LOG_WARNING, "Delayed frames seen. "
-                   "Reenabling low delay requires a codec flush.\n");
-        else
-            h->low_delay = 1;
-    }
-
-    if (h->avctx->has_b_frames < 2)
-        h->avctx->has_b_frames = !h->low_delay;
-
-    if (h->cur_bit_depth_luma         != h->sps.bit_depth_luma ||
-        h->cur_chroma_format_idc      != h->sps.chroma_format_idc) {
-        if (h->avctx->codec &&
-            h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU &&
-            (h->sps.bit_depth_luma != 8 || h->sps.chroma_format_idc > 1)) {
-            av_log(h->avctx, AV_LOG_ERROR,
-                   "VDPAU decoding does not support video colorspace.\n");
-            return AVERROR_INVALIDDATA;
-        }
-        if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 14 &&
-            h->sps.bit_depth_luma != 11 && h->sps.bit_depth_luma != 13) {
-            h->cur_bit_depth_luma         =
-            h->avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
-            h->cur_chroma_format_idc      = h->sps.chroma_format_idc;
-            h->pixel_shift                = h->sps.bit_depth_luma > 8;
-
-            ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma,
-                            h->sps.chroma_format_idc);
-            ff_h264chroma_init(&h->h264chroma, h->sps.bit_depth_chroma);
-            ff_h264qpel_init(&h->h264qpel, h->sps.bit_depth_luma);
-            ff_h264_pred_init(&h->hpc, h->avctx->codec_id, h->sps.bit_depth_luma,
-                              h->sps.chroma_format_idc);
-
-            ff_videodsp_init(&h->vdsp, h->sps.bit_depth_luma);
-        } else {
-            av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth %d\n",
-                   h->sps.bit_depth_luma);
-            return AVERROR_INVALIDDATA;
-        }
-    }
-    return 0;
-}
-
 int ff_set_ref_count(H264Context *h, H264SliceContext *sl)
 {
     int ref_count[2], list_count;
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 6eb27d75ac7692c637f638c1e15d5895af78f404..5026ab2ddf5a86722f2a3118eb429deb04c3914b 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -1168,7 +1168,6 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src);
 void ff_h264_unref_picture(H264Context *h, H264Picture *pic);
 
 int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl);
-int ff_h264_set_parameter_from_sps(H264Context *h);
 
 void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int height);
 int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc);
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 9624c36d732a5e9437f1b27ce0cdbec5e42933ec..7551df7da559fe60aa5e89dfc88d6793361948ed 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -611,8 +611,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
 
         /* copy block_offset since frame_start may not be called */
         memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset));
-
-        ff_h264_set_parameter_from_sps(h);
     }
 
     if (!h->cur_pic_ptr)
@@ -1103,6 +1101,37 @@ static int h264_slice_header_init(H264Context *h, int reinit)
         goto fail;
     }
 
+    if (h->avctx->codec &&
+        h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU &&
+        (h->sps.bit_depth_luma != 8 || h->sps.chroma_format_idc > 1)) {
+        av_log(h->avctx, AV_LOG_ERROR,
+                "VDPAU decoding does not support video colorspace.\n");
+        ret = AVERROR_INVALIDDATA;
+        goto fail;
+    }
+
+    if (h->sps.bit_depth_luma < 8 || h->sps.bit_depth_luma > 14 ||
+        h->sps.bit_depth_luma == 11 || h->sps.bit_depth_luma == 13
+    ) {
+        av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth %d\n",
+               h->sps.bit_depth_luma);
+        ret = AVERROR_INVALIDDATA;
+        goto fail;
+    }
+
+    h->cur_bit_depth_luma         =
+    h->avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
+    h->cur_chroma_format_idc      = h->sps.chroma_format_idc;
+    h->pixel_shift                = h->sps.bit_depth_luma > 8;
+
+    ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma,
+                    h->sps.chroma_format_idc);
+    ff_h264chroma_init(&h->h264chroma, h->sps.bit_depth_chroma);
+    ff_h264qpel_init(&h->h264qpel, h->sps.bit_depth_luma);
+    ff_h264_pred_init(&h->hpc, h->avctx->codec_id, h->sps.bit_depth_luma,
+                      h->sps.chroma_format_idc);
+    ff_videodsp_init(&h->vdsp, h->sps.bit_depth_luma);
+
     if (nb_slices > H264_MAX_THREADS || (nb_slices > h->mb_height && h->mb_height)) {
         int max_slices;
         if (h->mb_height)
@@ -1300,8 +1329,20 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
             h->chroma_format_idc = h->sps.chroma_format_idc;
             needs_reinit         = 1;
         }
-        if ((ret = ff_h264_set_parameter_from_sps(h)) < 0)
-            return ret;
+
+        if (h->flags & CODEC_FLAG_LOW_DELAY ||
+            (h->sps.bitstream_restriction_flag &&
+             !h->sps.num_reorder_frames)) {
+            if (h->avctx->has_b_frames > 1 || h->delayed_pic[0])
+                av_log(h->avctx, AV_LOG_WARNING, "Delayed frames seen. "
+                       "Reenabling low delay requires a codec flush.\n");
+            else
+                h->low_delay = 1;
+        }
+
+        if (h->avctx->has_b_frames < 2)
+            h->avctx->has_b_frames = !h->low_delay;
+
     }
 
     h->avctx->profile = ff_h264_get_profile(&h->sps);