Skip to content

Video editing with Python

Autodetect ImageMagick on windows (#1041)

Nexarius4d70eabd784a
diff --git a/moviepy/config.py b/moviepy/config.py
index 5046edf4..6da1fb37 100644
--- a/moviepy/config.py
+++ b/moviepy/config.py
@@ -57,14 +57,29 @@ else:
if IMAGEMAGICK_BINARY == "auto-detect":
if os.name == "nt":
+ # Try a few different ways of finding the ImageMagick binary on Windows
try:
key = wr.OpenKey(wr.HKEY_LOCAL_MACHINE, "SOFTWARE\\ImageMagick\\Current")
IMAGEMAGICK_BINARY = wr.QueryValueEx(key, "BinPath")[0] + r"\magick.exe"
key.Close()
except Exception:
- IMAGEMAGICK_BINARY = "unset"
+ try:
+ imagemagick_path = sp.check_output(
+ r'dir /B /O-N "C:\Program Files\ImageMagick-*"',
+ shell=True,
+ encoding="utf-8",
+ ).split("\n")[0]
+ IMAGEMAGICK_BINARY = sp.check_output(
+ rf'dir /B /S "C:\Program Files\{imagemagick_path}\*convert.exe"',
+ shell=True,
+ encoding="utf-8",
+ ).split("\n")[0]
+ except Exception:
+ IMAGEMAGICK_BINARY = "unset"
+
elif try_cmd(["convert"])[0]:
IMAGEMAGICK_BINARY = "convert"
+
else:
IMAGEMAGICK_BINARY = "unset"
else: