diff --git a/ffmpeg.h b/ffmpeg.h
index ebe5bf04061a4d3163dcc57479bb8ffb7a8d61e0..081913bcfccfceb9121373cfda433786f04f7a31 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -602,6 +602,9 @@ extern const OptionDef options[];
 extern const HWAccel hwaccels[];
 extern int hwaccel_lax_profile_check;
 extern AVBufferRef *hw_device_ctx;
+#if CONFIG_QSV
+extern char *qsv_device;
+#endif
 
 
 void term_init(void);
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 6862456c27082f66cbef55aa1642b181c9ee2bc8..a4b8d24991db9d3d1701ab54e0c977816424b117 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -3679,5 +3679,10 @@ const OptionDef options[] = {
         "set VAAPI hardware device (DRM path or X11 display name)", "device" },
 #endif
 
+#if CONFIG_QSV
+    { "qsv_device", HAS_ARG | OPT_STRING | OPT_EXPERT, { &qsv_device },
+        "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
+#endif
+
     { NULL, },
 };
diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c
index 68ff5bd5dc14139d6a1c60f32d268cf041840c01..86824b60f20d09845dd785417c05850fe960e386 100644
--- a/ffmpeg_qsv.c
+++ b/ffmpeg_qsv.c
@@ -28,6 +28,8 @@
 
 #include "ffmpeg.h"
 
+char *qsv_device = NULL;
+
 static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
 {
     InputStream *ist = s->opaque;
@@ -44,15 +46,26 @@ static void qsv_uninit(AVCodecContext *s)
 static int qsv_device_init(InputStream *ist)
 {
     int err;
+    AVDictionary *dict = NULL;
+
+    if (qsv_device) {
+        err = av_dict_set(&dict, "child_device", qsv_device, 0);
+        if (err < 0)
+            return err;
+    }
 
     err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV,
-                                 ist->hwaccel_device, NULL, 0);
+                                 ist->hwaccel_device, dict, 0);
     if (err < 0) {
         av_log(NULL, AV_LOG_ERROR, "Error creating a QSV device\n");
-        return err;
+        goto err_out;
     }
 
-    return 0;
+err_out:
+    if (dict)
+        av_dict_free(&dict);
+
+    return err;
 }
 
 int qsv_init(AVCodecContext *s)