当前位置:   article > 正文

MoviePy - 中文文档4-MoviePy实战案例-炫动的字母特效_moveletters(letter, size, funcpos=cascade):

moveletters(letter, size, funcpos=cascade):

回到目录

炫动的字母特效


这个例子,一定能很好的地说明为什么大家有兴趣基于MoviePy脚本来实现一些特效,我们也可以想像一下如果是手工做的话,绝壁手抽筋了。
 

下面就是代码实现 

  1. import numpy as np
  2. from moviepy.editor import *
  3. from moviepy.video.tools.segmenting import findObjects
  4. # 目标是创建炫动的文字,先创建TextClip,然后设置它居中
  5. screensize = (720,460)
  6. txtClip = TextClip('Cool effect',color='white', font="Amiri-Bold",
  7. kerning = 5, fontsize=100)
  8. cvc = CompositeVideoClip( [txtClip.set_pos('center')],
  9. size=screensize)
  10. # 下面的四个函数,定义了四种移动字母的方式
  11. # helper function
  12. rotMatrix = lambda a: np.array( [[np.cos(a),np.sin(a)],
  13. [-np.sin(a),np.cos(a)]] )
  14. def vortex(screenpos,i,nletters):
  15. d = lambda t : 1.0/(0.3+t**8) #damping
  16. a = i*np.pi/ nletters # angle of the movement
  17. v = rotMatrix(a).dot([-1,0])
  18. if i%2 : v[1] = -v[1]
  19. return lambda t: screenpos+400*d(t)*rotMatrix(0.5*d(t)*a).dot(v)
  20. def cascade(screenpos,i,nletters):
  21. v = np.array([0,-1])
  22. d = lambda t : 1 if t<0 else abs(np.sinc(t)/(1+t**4))
  23. return lambda t: screenpos+v*400*d(t-0.15*i)
  24. def arrive(screenpos,i,nletters):
  25. v = np.array([-1,0])
  26. d = lambda t : max(0, 3-3*t)
  27. return lambda t: screenpos-400*v*d(t-0.2*i)
  28. def vortexout(screenpos,i,nletters):
  29. d = lambda t : max(0,t) #damping
  30. a = i*np.pi/ nletters # angle of the movement
  31. v = rotMatrix(a).dot([-1,0])
  32. if i%2 : v[1] = -v[1]
  33. return lambda t: screenpos+400*d(t-0.1*i)*rotMatrix(-0.2*d(t)*a).dot(v)
  34. # WE USE THE PLUGIN findObjects TO LOCATE AND SEPARATE EACH LETTER
  35. letters = findObjects(cvc) # a list of ImageClips
  36. # 让字母动起来
  37. def moveLetters(letters, funcpos):
  38. return [ letter.set_pos(funcpos(letter.screenpos,i,len(letters)))
  39. for i,letter in enumerate(letters)]
  40. clips = [ CompositeVideoClip( moveLetters(letters,funcpos),
  41. size = screensize).subclip(0,5)
  42. for funcpos in [vortex, cascade, arrive, vortexout] ]
  43. # 连接,写入文件
  44. final_clip = concatenate_videoclips(clips)
  45. final_clip.write_videofile('../../coolTextEffects.avi',fps=25,codec='mpeg4')

一起交流,一起进步,群内提问答疑

QQ群:MoviePy中文 :819718037

回到目录

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/80413
推荐阅读
相关标签
  

闽ICP备14008679号