📜  MoviePy – 在视频中插入文本

📅  最后修改于: 2022-05-13 01:54:25.859000             🧑  作者: Mango

MoviePy – 在视频中插入文本

在本文中,我们将了解如何在 MoviePy 中将文本插入到视频剪辑中。 MoviePy 是一个用于视频编辑的Python模块,可用于视频和 GIF 的基本操作。视频是由帧组成的,帧的组合创建一个视频,每一帧都是一个单独的图像。 VideoClip 是 MoviePy 中所有其他视频剪辑的基类。为了做到这一点,我们需要安装 ImageMagick,否则它将无法工作。向视频添加文本类似于创建复合视频。

下面是实现

# Import everything needed to edit video clips 
from moviepy.editor import *
    
# loading video dsa gfg intro video 
clip = VideoFileClip("dsa_geek.mp4") 
    
# clipping of the video  
# getting video for only starting 10 seconds 
clip = clip.subclip(0, 10) 
    
# Reduce the audio volume (volume x 0.8) 
clip = clip.volumex(0.8) 
    
# Generate a text clip 
txt_clip = TextClip("GeeksforGeeks", fontsize = 75, color = 'black') 
    
# setting position of text in the center and duration will be 10 seconds 
txt_clip = txt_clip.set_pos('center').set_duration(10) 
    
# Overlay the text clip on the first video clip 
video = CompositeVideoClip([clip, txt_clip]) 
    
# showing video 
video.ipython_display(width = 280) 
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

                                                                                                                       
Moviepy - Done !
Moviepy - video ready __temp__.mp4

另一个例子

# Import everything needed to edit video clips 
from moviepy.editor import *
    
# loading video file clip
clip = VideoFileClip("geeks.mp4") 
    
# clipping of the video  
# getting video for only starting 10 seconds 
clip = clip.subclip(0, 5) 
    
# Reduce the audio volume (volume x 0.5) 
clip = clip.volumex(0.5) 
    
# Generate a text clip 
txt_clip = TextClip("GfG-MoviePy", fontsize = 75, color = 'green') 
    
# setting position of text in the center and duration will be 5 seconds 
txt_clip = txt_clip.set_pos('bottom').set_duration(5) 
    
# Overlay the text clip on the first video clip 
video = CompositeVideoClip([clip, txt_clip]) 
    
# showing video 
video.ipython_display(width = 280) 
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

                                                                                                                       
Moviepy - Done !
Moviepy - video ready __temp__.mp4