简体   繁体   中英

ImageMagick problem on Windows 10 with Windows 2 error code

I want to make a python script to create a video with moviepy but I have some problems with windows. I tried installing ImageMagick but can not find a convert.exe I do not know why it is. But I am already stuck.

my code:

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.")

my error:

[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`

In ImageMagick v7, the convert.exe program is replaced by magick.exe .

So if your Python script is looking for convert.exe , you must click "Install legacy commands" when installing ImageMagick .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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