问题
- In MoviePy there is an api to create a clip from text as well as to concatenate list of clips.
- I am trying to create a list of clips in a loop and then trying to concatenate them.
- Problem is every time it creates a video file of 25 seconds only with the last text in a loop.
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')
回答1:
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.
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. You may find this other question useful: How to concatenate videos in moviepy?
来源:https://stackoverflow.com/questions/28429005/create-a-series-of-text-clip-and-concatenate-them-into-a-video-using-moviepy