繁体   English   中英

ImageMagick 问题 Windows 10 与 Windows 2 错误代码

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM