[英]ImageMagick problem on Windows 10 with Windows 2 error code
我想制作一個 python 腳本來創建帶有 moviepy 的視頻,但我在使用 windows 時遇到了一些問題。我嘗試安裝 ImageMagick 但找不到 convert.exe 我不知道為什么。 但我已經卡住了。
我的代碼:
import moviepy.editor as mp
import os
print("Start")
def create_vertical_video(image_file, music_file, quote):
# Open image and resize to 9:16 aspect ratio (vertical video)
if not os.path.isfile(image_file):
raise ValueError(f"{image_file} is not a valid file path")
image = mp.ImageClip(image_file).resize(height=1080)
# Open music file and set to fit the duration of the image
if not os.path.isfile(music_file):
raise ValueError(f"{music_file} is not a valid file path")
music = mp.AudioFileClip(music_file)
music = music.set_duration(image.duration)
# Split quote into multiple lines if necessary
MAX_CHARS_PER_LINE = 25
lines = []
current_line = ""
for word in quote.split():
if len(current_line) + len(word) <= MAX_CHARS_PER_LINE:
current_line += word + " "
else:
lines.append(current_line.strip())
current_line = word + " "
lines.append(current_line.strip())
# Create text clip for each line
text_clips = [mp.TextClip(line, fontsize=24, color='white', bg_color='black')
.set_pos('center').set_duration(image.duration)
for line in lines]
# Overlay text clips on image
text_overlay = mp.concatenate_videoclips(text_clips, method='compose')
final_clip = mp.CompositeVideoClip([image, text_overlay])
# Add music to final clip
final_clip = final_clip.set_audio(music)
# Save video
final_clip.write_videofile("vertical_video.mp4", fps=24)
create_vertical_video("nature.jpg","music.mp3","Don't be pushed around by the fears in your mind. Be led by the dreams in your heart.")
我的錯誤:
[WinError 2] The system cannot find the file specified.
.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`
在ImageMagick v7 中, convert.exe
程序被magick.exe
取代。
因此,如果您的 Python 腳本正在尋找convert.exe
,則必須在安裝ImageMagick時單擊“安裝舊命令” 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.