diff --git a/cmdutils.c b/cmdutils.c
index 03a4836207466c2560666a1932a06edaf6c66389..6960f8c99c41b93b0a222be6983125f2ae41cfd7 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -107,6 +107,15 @@ static void log_callback_report(void *ptr, int level, const char *fmt, va_list v
     }
 }
 
+void init_dynload(void)
+{
+#ifdef _WIN32
+    /* Calling SetDllDirectory with the empty string (but not NULL) removes the
+     * current working directory from the DLL search path as a security pre-caution. */
+    SetDllDirectory("");
+#endif
+}
+
 static void (*program_exit)(int ret);
 
 void register_exit(void (*cb)(int ret))
diff --git a/cmdutils.h b/cmdutils.h
index 83ea4ad39ecb620a9d28670ca258b12475c10e1e..67bf4848b7567d1a5ce697dbef8f6aacaf5a60d0 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -61,6 +61,11 @@ void register_exit(void (*cb)(int ret));
  */
 void exit_program(int ret) av_noreturn;
 
+/**
+ * Initialize dynamic library loading
+ */
+void init_dynload(void);
+
 /**
  * Initialize the cmdutils option system, in particular
  * allocate the *_opts contexts.
diff --git a/ffmpeg.c b/ffmpeg.c
index d6282bdfff1732698f091466ad273dae9315b5ef..bae515d0ce113bfba220e64034a8596bf9c5e04e 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -4293,6 +4293,8 @@ int main(int argc, char **argv)
     int ret;
     int64_t ti;
 
+    init_dynload();
+
     register_exit(ffmpeg_cleanup);
 
     setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
diff --git a/ffplay.c b/ffplay.c
index 651e0cf4f1ebfe59f0ed1cbd33b0d240cd6fd2f7..adbe9cb4e1fd9e6d6e4434fcf318e8a9b988b021 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -3776,6 +3776,8 @@ int main(int argc, char **argv)
     char dummy_videodriver[] = "SDL_VIDEODRIVER=dummy";
     char alsa_bufsize[] = "SDL_AUDIO_ALSA_SET_BUFFER_SIZE=1";
 
+    init_dynload();
+
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
     parse_loglevel(argc, argv, options);
 
diff --git a/ffprobe.c b/ffprobe.c
index a49be6a3f83d2e97e29f982419ee48e3d69b7e5c..657867d8ec0c267e185c1f3d479718ecb2766dfa 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -3241,6 +3241,8 @@ int main(int argc, char **argv)
     char *w_name = NULL, *w_args = NULL;
     int ret, i;
 
+    init_dynload();
+
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
     register_exit(ffprobe_cleanup);
 
diff --git a/ffserver.c b/ffserver.c
index 1a2758367736bb39d31a187fbbfbded91d88f0a5..453d790e6cda57b463a0fda79eaf508e218ba63d 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -3980,6 +3980,7 @@ int main(int argc, char **argv)
     int cfg_parsed;
     int ret = EXIT_FAILURE;
 
+    init_dynload();
 
     config.filename = av_strdup("/etc/ffserver.conf");