diff --git a/doc/APIchanges b/doc/APIchanges
index 91f41a5020ad31140b75cf149d30b820d62ce652..e5c392ead5166f45ac85e4a1ea72b9dfe8e086b1 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2018-02-xx - xxxxxxx - lavc 58.11.100 - avcodec.h
+  Add AVCodecContext.extra_hw_frames.
+
 2018-02-06 - 0fd475704e - lavd 58.1.100 - avdevice.h
   Deprecate use of av_input_audio_device_next(), av_input_video_device_next(),
   av_output_audio_device_next(), av_output_video_device_next().
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ad0b48a83996c50d19792d828e899a4ecc6fb5c0..bc0eacd66b09a4b4f9629c14c6486b5c5d81d856 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3255,6 +3255,20 @@ typedef struct AVCodecContext {
      * (with the display dimensions being determined by the crop_* fields).
      */
     int apply_cropping;
+
+    /*
+     * Video decoding only.  Sets the number of extra hardware frames which
+     * the decoder will allocate for use by the caller.  This must be set
+     * before avcodec_open2() is called.
+     *
+     * Some hardware decoders require all frames that they will use for
+     * output to be defined in advance before decoding starts.  For such
+     * decoders, the hardware frame pool must therefore be of a fixed size.
+     * The extra frames set here are on top of any number that the decoder
+     * needs internally in order to operate normally (for example, frames
+     * used as reference pictures).
+     */
+    int extra_hw_frames;
 } AVCodecContext;
 
 #if FF_API_CODEC_GET_SET
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index f67b2147591ec47cf8bc915b02b5d81c8315ab68..e984d9754e6b9320f33b95e7249fd1eeac5017c1 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1229,6 +1229,15 @@ int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
 
     ret = hwa->frame_params(avctx, frames_ref);
     if (ret >= 0) {
+        AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
+
+        if (frames_ctx->initial_pool_size) {
+            // If the user has requested that extra output surfaces be
+            // available then add them here.
+            if (avctx->extra_hw_frames > 0)
+                frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+        }
+
         *out_frames_ref = frames_ref;
     } else {
         av_buffer_unref(&frames_ref);
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index d89f58d540351791549b48c5c9ac634e0e6b774a..ac9ce4b30196eb4588867f0f23bc707c2b0ec61b 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -476,6 +476,7 @@ static const AVOption avcodec_options[] = {
 {"ignore_level", "ignore level even if the codec level used is unknown or higher than the maximum supported level reported by the hardware driver", 0, AV_OPT_TYPE_CONST, { .i64 = AV_HWACCEL_FLAG_IGNORE_LEVEL }, INT_MIN, INT_MAX, V | D, "hwaccel_flags" },
 {"allow_high_depth", "allow to output YUV pixel formats with a different chroma sampling than 4:2:0 and/or other than 8 bits per component", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"},
 {"allow_profile_mismatch", "attempt to decode anyway if HW accelerated decoder's supported profiles do not exactly match the stream", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"},
+{"extra_hw_frames", "Number of extra hardware frames to allocate for the user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, V|D },
 {NULL},
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index e36cea30b55867b359608652b531920fcf117c6f..3597a1a380ef39c71b7725d4e247e1b64c420034 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  10
+#define LIBAVCODEC_VERSION_MINOR  11
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \