我正在尝试使用 moviepy 生成带有文本的视频。首先,我想显示一条消息,然后显示另一条消息。就我而言,我想显示“Dog”一秒钟而不是“Cat Cat”。为此,我使用以下代码:
从moviepy.editor导入*
def my_func(messeges):
clips = {}
count = 0
for messege in messeges:
count += 1
clips[count] = TextClip(messege, fontsize=270, color='green')
clips[count] = clips[count].set_pos('center').set_duration(1)
clips[count].write_videofile(str(count) + '.avi', fps=24, codec='mpeg4')
videos = [clips[i+1] for i in range(count)]
video = concatenate(videos)
video.write_videofile('test.avi', fps=24, codec='mpeg4')
video = VideoFileClip('test.avi')
video.write_gif('test.gif', fps=24)
if __name__ == '__main__':
ms = []
ms += ['Dog']
ms += ['Cat Cat']
my_func(ms)
这是我得到的结果:
有人知道为什么我对猫有问题吗?