diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
index 99b80ba3731606b6c6a1a72b51027a83d07a7c54..2f0311437ebd717634dfe849e49157cd7269445c 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -20,11 +20,15 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "dxva2_internal.h"
 #include "h264.h"
 #include "h264data.h"
 #include "mpegutils.h"
 
+// The headers above may include w32threads.h, which uses the original
+// _WIN32_WINNT define, while dxva2_internal.h redefines it to target a
+// potentially newer version.
+#include "dxva2_internal.h"
+
 struct dxva2_picture_context {
     DXVA_PicParams_H264   pp;
     DXVA_Qmatrix_H264     qm;
diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index 79d2d2824e4630d83f1c8a5b8ff7f1be4b0e14c6..5a312eaf23368b2e8db299db2f8a8821dc854b1a 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -22,9 +22,13 @@
 
 #include "libavutil/avassert.h"
 
-#include "dxva2_internal.h"
 #include "hevc.h"
 
+// The headers above may include w32threads.h, which uses the original
+// _WIN32_WINNT define, while dxva2_internal.h redefines it to target a
+// potentially newer version.
+#include "dxva2_internal.h"
+
 #define MAX_SLICES 256
 
 struct hevc_dxva2_picture_context {
diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c
index 64fa196ca688ee278e02a7a296f467751bdecc61..c2f0b58beebb5918f965256702601c195618f6a9 100644
--- a/libavcodec/dxva2_mpeg2.c
+++ b/libavcodec/dxva2_mpeg2.c
@@ -21,10 +21,14 @@
  */
 
 #include "libavutil/log.h"
-#include "dxva2_internal.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
 
+// The headers above may include w32threads.h, which uses the original
+// _WIN32_WINNT define, while dxva2_internal.h redefines it to target a
+// potentially newer version.
+#include "dxva2_internal.h"
+
 #define MAX_SLICES 1024
 struct dxva2_picture_context {
     DXVA_PictureParameters pp;
diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
index 1eb425383e296ba6f55eafab7c413688ed6043f4..7cbbc7ef75376e7ab696e8f98ca4c68fbc3b96cd 100644
--- a/libavcodec/dxva2_vc1.c
+++ b/libavcodec/dxva2_vc1.c
@@ -20,11 +20,15 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "dxva2_internal.h"
 #include "mpegutils.h"
 #include "vc1.h"
 #include "vc1data.h"
 
+// The headers above may include w32threads.h, which uses the original
+// _WIN32_WINNT define, while dxva2_internal.h redefines it to target a
+// potentially newer version.
+#include "dxva2_internal.h"
+
 struct dxva2_picture_context {
     DXVA_PictureParameters pp;
     DXVA_SliceInfo         si;