这个问题目前已经搞定了
使用moviepy
[Python] 纯文本查看 复制代码 import numpy as np
import bezier
from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects
# WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT.
screensize = (960,544)
txtClip = TextClip('王迪',color='white', font="MicrosoftYaHei",
kerning = 5, fontsize=100)
cvc = CompositeVideoClip( [txtClip.set_pos('center')],
size=screensize)
# THE NEXT FOUR FUNCTIONS DEFINE FOUR WAYS OF MOVING THE LETTERS
print ( TextClip.list("font") )
nodes1 = np.asfortranarray([
[0, 0.25, .25, 1],
[0, 0.1, 1, 1],
])
# 三阶bezier curve
curve1 = bezier.Curve(nodes1, degree=3)
# for t in range(0,10):
# print(t,curve1.evaluate(t/10))
# 字符当前在屏幕上的位置,第几个字符,字符总数
def moveUp(screenpos,i,nletters):
v = np.array([0,1])
s = 1
d = lambda t : 1 if t <=s else 0
return lambda t: screenpos +d(t)*v*(320*(1-curve1.evaluate(t/s)[1][0]))
# WE USE THE PLUGIN findObjects TO LOCATE AND SEPARATE EACH LETTER
letters = findObjects(cvc) # a list of ImageClips
# WE ANIMATE THE LETTERS
def moveLetters(letters, funcpos):
return [ letter.set_pos(funcpos(letter.screenpos,i,len(letters)))
for i,letter in enumerate(letters)]
# 遍历函数数组,将灭一个函数赋值给CompositeVideoClip,
clip = CompositeVideoClip( moveLetters(letters,moveUp),
size = screensize).subclip(0,5)
# WE CONCATENATE EVERYTHING AND WRITE TO A FILE
clip.write_videofile('./new.mp4',fps=25,codec='mpeg4') |