📜  MoviePy - 创建复合视频剪辑

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

MoviePy - 创建复合视频剪辑

在本文中,我们将了解如何在 MoviePy 中合成视频文件。 MoviePy 是一个用于视频编辑的Python模块,可用于视频和 GIF 的基本操作。复合的含义是组合不同的元素,复合视频是不同视频片段的组合,不像视频文件的堆叠和串联,复合文件易于实现但结构复杂。复合文件将剪辑相互组合并同时播放,可以随时设置视频播放的位置和时间。

下面是实现

Python3
# Import everything needed to edit video clips
from moviepy.editor import *
  
# loading video dsa gfg intro video and getting only first 5 seconds
clip1 = VideoFileClip("dsa_geek.webm").subclip(0, 5)
  
# rotating clip1 by 90 degree to get the clip2
clip2 = clip1.margin(40).set_start(3)
  
# rotating clip1 by 180 degree to get the clip3
clip3 = clip1.rotate(180).set_start(6)
  
# creating a composite video
final = CompositeVideoClip([clip2, clip1, clip3])
  
# showing final clip
final.ipython_display(width = 480)


Python3
# Import everything needed to edit video clips
from moviepy.editor import *
 
# loading video gfg
clip = VideoFileClip("geeks.mp4")
 
 
# getting subclip from it
clip1 = clip.subclip(0, 5)
 
# mirroring image according to the y axis
clip2 = clip.fx(vfx.mirror_y).set_start((4))
 
 
# creating a composite video
final = CompositeVideoClip([clip1, clip2])
  
# 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 gfg
clip = VideoFileClip("geeks.mp4")
 
 
# getting subclip from it
clip1 = clip.subclip(0, 5)
 
# mirroring image according to the y axis
clip2 = clip.fx(vfx.mirror_y).set_start((4))
 
 
# creating a composite video
final = CompositeVideoClip([clip1, clip2])
  
# 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