创建一系列文本剪辑并使用 moviepy 将它们连接成视频 [英] Create a series of text clip and concatenate them into a video using moviepy

查看:38
本文介绍了创建一系列文本剪辑并使用 moviepy 将它们连接成视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 在 MoviePy 中,有一个 api 可以从文本创建剪辑以及连接剪辑列表.
  2. 我正在尝试在循环中创建剪辑列表,然后尝试连接它们.
  3. 问题是每次创建一个 25 秒的视频文件时,只有最后一个文本在循环中.

这是代码

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')

推荐答案

我无法重现您的问题(可能是因为我使用的列表没有引发异常?),但下面的代码块对我有用.与上述内容最显着的区别是我为 MoviePy 设置了一个选项来调整不同的帧大小.

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')

如果您有一个引发 unicode 编码错误的示例,也许我可以重现您的问题.您可能会发现这个其他问题很有用:如何在 moviepy 中连接视频?

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?

这篇关于创建一系列文本剪辑并使用 moviepy 将它们连接成视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆