一.使用場景
此處問題為我使用MoviePy模塊給視頻添加文字水印的時候遇到的報錯,
安裝imageio和MoviePy
以及requests模塊,就已經可以使用MoviePy很多功能了,但是某些函數,還需要用到這個叫
ImageMagick
的軟件。如果你不安裝它會提示這樣的錯誤:
Traceback (most recent call last): File "F:\Tool\PythonVE\Movie\lib\site-packages\moviepy\video\VideoClip.py", line 1156, in __init__ subprocess_call(cmd, verbose=False) File "F:\Tool\PythonVE\Movie\lib\site-packages\moviepy\tools.py", line 42, in subprocess_call proc = sp.Popen(cmd, **popen_params) File "f:\tool\python36\Lib\subprocess.py", line 709, in __init__ restore_signals, start_new_session) File "f:\tool\python36\Lib\subprocess.py", line 997, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 系統找不到指定的文件。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "F:/A/MoviePy/Cut.py", line 14, in <module> txt_clip = TextClip("字幕", fontsize=70, color='white') File "F:\Tool\PythonVE\Movie\lib\site-packages\moviepy\video\VideoClip.py", line 1165, in __init__ raise IOError(error) OSError: MoviePy Error: creation of None failed because of the following error: [WinError 2] 系統找不到指定的文件。 .This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
重點在最后一句:
.This error can be due to the fact that ImageMagick is not installed on your computer,
or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
二.解決方案:
2.1下載imagemagick
我們需要自己下載,在官網 http://www.imagemagick.org/script/download.php 可以根據不同的操作系統來下載,Windows在最下面。
下載好后,選擇自己喜歡的位置,來安裝,瘋狂點擊Next
就行,不需要配置環境變量。
2.1配置ImageMagick
安裝了還不夠,還要讓MoviePy
能夠找到它的位置。進入到你的python
根目錄,打開MoviePy
的配置環境變量的文件:\Python36\Lib\site-packages\moviepy\config_defaults.py
你會看到:
按照它的提示改就好了。ffmpeg
不用改,因為是MoviePy
幫我們裝的,它肯定知道它的位置了。主要是改IMAGEMAGICK_BINARY
。把原來的注釋掉,改成下面的樣子:(當然你要根據你剛才安裝的目錄來選擇)
位置為安裝ImageMagick后產生的文件中:
三.驗證
再次運行代碼,沒有報錯,正確添加水印視頻