简体   繁体   English

创建一系列文本剪辑,然后使用moviepy将它们连接成视频

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

  1. In MoviePy there is an api to create a clip from text as well as to concatenate list of clips. 在MoviePy中,有一个api可根据文本创建片段并连接片段列表。
  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. 问题在于,每次创建一个25秒的视频文件时,循环中只有最后一个文本。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM