Create a series of text clip and concatenate them into a video using moviepy

寵の児 提交于 2021-01-28 19:14:42

问题


  1. In MoviePy there is an api to create a clip from text as well as to concatenate list of clips.
  2. I am trying to create a list of clips in a loop and then trying to concatenate them.
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!