moviepy==1.0.2
字幕由大变小,由具体大到具体小
from moviepy.editor import TextClip, CompositeVideoClip
from moviepy.video.fx.resize import resize
screen_size = (800, 600)
initial_fontsize = 100
final_fontsize = 50
txt_clip = TextClip("Hello World", fontsize=initial_fontsize, color='white', font="Arial")
duration = 5
resize_func = lambda t: max(final_fontsize, initial_fontsize - (initial_fontsize - final_fontsize) * t / duration)
txt_clip = resize(txt_clip, lambda t: resize_func(t) / initial_fontsize).set_duration(duration).set_pos('center')
final_clip = CompositeVideoClip([txt_clip], size=screen_size)
final_clip.write_videofile("text_shrinking.mp4", fps=24)
由小变大
# 固定放大放大大小
from moviepy.editor import TextClip, CompositeVideoClip
from moviepy.video.fx.resize import resize
screen_size = (800, 600)
initial_fontsize = 50
final_fontsize = 100
txt_clip = TextClip("Hello World", fontsize=initial_fontsize, color='white', font="Arial")
duration = 5
resize_func = lambda t: initial_fontsize + (final_fontsize - initial_fontsize) * t / duration
txt_clip = resize(txt_clip, lambda t: resize_func(t) / initial_fontsize).set_duration(duration).set_pos('center')
final_clip = CompositeVideoClip([txt_clip], size=screen_size)
final_clip.write_videofile("text_shrinking.mp4", fps=24)
标签:效果,clip,initial,duration,字幕,fontsize,大小,final,resize
From: https://www.cnblogs.com/msmsga/p/18603008