MoviePy - 连接多个视频文件
在本文中,我们将了解如何在 MoviePy 中连接多个视频文件剪辑。 MoviePy 是一个用于视频编辑的Python模块,可用于视频和 GIF 的基本操作。在形式语言理论和计算机编程中,字符串连接是端到端连接字符的字符串。例如,“snow”和“ball”的串联是“snowball”,同样串联多个视频片段意味着它们将一个接一个地播放并充当一个视频文件。
注意:剪辑不需要是相同的大小。如果它们的大小不同,它们都将出现在一个足够大的剪辑的中心以包含其中最大的一个。
In order to do this we will use concatenate_videoclips method
Syntax : concatenate_videoclips(clips)
Argument : It takes list of video file clips as argument
Return : It returns VideoFileClip object
下面是实现
Python3
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video dsa gfg intro video
clip = VideoFileClip("dsa_geek.webm")
# getting subclip as video is large
clip1 = clip.subclip(0, 5)
# getting subclip as video is large
clip2 = clip.subclip(60, 65)
# concatenating both the clips
final = concatenate_videoclips([clip1, clip2])
#writing the video into a file / saving the combined video
final.write_videofile("merged.webm")
# showing final clip
final.ipython_display(width = 480)
Python3
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video dsa gfg intro video
clip = VideoFileClip("dsa_geek.webm")
# getting subclip as video is large
clip1 = clip.subclip(0, 5)
# loading video gfg
clipx = VideoFileClip("geeks.mp4")
# getting subclip
clip2 = clipx.subclip(0, 5)
# clip list
clips = [clip1, clip2]
# concatenating both the clips
final = concatenate_videoclips(clips)
# showing final clip
final.ipython_display(width = 480)
输出 :
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4
Moviepy - Done !
Moviepy - video ready __temp__.mp4
另一个例子:
Python3
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video dsa gfg intro video
clip = VideoFileClip("dsa_geek.webm")
# getting subclip as video is large
clip1 = clip.subclip(0, 5)
# loading video gfg
clipx = VideoFileClip("geeks.mp4")
# getting subclip
clip2 = clipx.subclip(0, 5)
# clip list
clips = [clip1, clip2]
# concatenating both the clips
final = concatenate_videoclips(clips)
# showing final clip
final.ipython_display(width = 480)
输出 :
Moviepy - Building video __temp__.mp4.
MoviePy - Writing audio in __temp__TEMP_MPY_wvf_snd.mp3
MoviePy - Done.
Moviepy - Writing video __temp__.mp4
Moviepy - Done !
Moviepy - video ready __temp__.mp4