[英]Create a series of text clip and concatenate them into a video using moviepy
Here is the code 这是代码
for text in a list:
try:
txt_clip = TextClip(text,fontsize=70,color='white')
txt_clip = txt_clip.set_duration(2)
clip_list.append(txt_clip)
except UnicodeEncodeError:
txt_clip = TextClip("Issue with text",fontsize=70,color='white')
txt_clip = txt_clip.set_duration(2)
clip_list.append(txt_clip)
final_clip = concatenate_videoclips(clip_list)
final_clip.write_videofile("my_concatenation.mp4",fps=24, codec='mpeg4')
I wasn't able to recreate your issue (maybe because the list I used doesn't raise the exception?), but the code chunk below works for me. 我无法重新创建您的问题(也许是因为我使用的列表没有引发异常?),但是下面的代码块对我有用。 The most significant difference from what you have above is that I set an option for MoviePy to adjust varying frame sizes. 与上面的内容最大的不同是,我为MoviePy设置了一个选项来调整不同的帧大小。
from moviepy.editor import *
text_list = ["Piggy", "Kermit", "Gonzo", "Fozzie"]
clip_list = []
for text in text_list:
try:
txt_clip = TextClip(text, fontsize = 70, color = 'white').set_duration(2)
clip_list.append(txt_clip)
except UnicodeEncodeError:
txt_clip = TextClip("Issue with text", fontsize = 70, color = 'white').set_duration(2)
clip_list.append(txt_clip)
final_clip = concatenate(clip_list, method = "compose")
final_clip.write_videofile("my_concatenation.mp4", fps = 24, codec = 'mpeg4')
If you had an example that raises the unicode encode error, maybe I would be able to reproduce your issue. 如果您有引发unicode编码错误的示例,也许我可以重现您的问题。 You may find this other question useful: How to concatenate videos in moviepy? 您可能会发现另一个有用的问题: 如何将Moviepy中的视频串联起来?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.