尝试使用 moviepy、imagemagick、anaconda、pycharm 社区从 python 中的文本文件制作文本视频

问题描述 投票:0回答:0

我正在尝试使用 moviepy 在 python 中制作输入文本视频,但在 IDE pycharm(社区)和 anaconda(spyder)中均未检测到 imagemagick,moviepy 与其他代码一起工作良好,不涉及文本,代码是下面:

from moviepy.editor import TextClip, concatenate_videoclips
import math
import os
os.environ['IMAGEIO_ffmpeg_EXE'] = 'C:/Program Files/ImageMagick-7.1.0-Q16-HDRI/ffmpeg.exe'

def append_text_as_frames(txtClip, text, duration, fps):
    nframes = int(math.ceil(duration * fps))
    txtClipList = []
    for i in range(nframes):
        txt = TextClip(text[:int(i/nframes*len(text))], color='white', fontsize=70, font='Amiri-Bold').set_duration(1/fps)
        txt = txt.set_pos(('center', 'center'))
        txtClipList.append(txt)
    return txtClipList


filename = "input_text.txt"
with open(filename, "r", encoding="utf8") as f:
    text = f.read()

duration = len(text) / 10 # assuming a typing speed of 10 characters per second
fps = 30

txtClipList = append_text_as_frames(TextClip('', color='white', fontsize=70, font='Amiri-Bold'), text, duration, fps)
final_clip = concatenate_videoclips(txtClipList)

final_clip.write_videofile("my_video.mp4", fps=fps)

OSError:MoviePy 错误:由于以下错误,创建 None 失败:

convert.exe:标签预期

@C:\Users\faisal\AppData\Local\Temp\tmpmj_kvwnl.txt' @ error/annotate.c/GetMultilineTypeMetrics/797. convert.exe: no images defined 
PNG32:C:\Users aisal\AppData\Local\Temp mpq7w_xi84.png' @ error/convert.c/ConvertImageCommand/3342。 .

.此错误可能是由于您的计算机上未安装 ImageMagick,或者(对于 Windows 用户)您没有在文件 conf.py 中指定 ImageMagick 二进制文件的路径,或者您指定的路径是不正确

pycharm anaconda imagemagick spyder moviepy
© www.soinside.com 2019 - 2024. All rights reserved.