📜  MoviePy 复合视频 - 设置剪辑位置

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

MoviePy 复合视频 - 设置剪辑位置

在本文中,我们将了解如何在 MoviePy 中设置复合视频文件中剪辑的位置。 MoviePy 是一个用于视频编辑的Python模块,可用于视频和 GIF 的基本操作。复合的含义是组合不同的元素,复合视频是不同视频片段的组合,不像视频文件的堆叠和串联,复合文件易于实现但结构复杂。复合文件将剪辑相互组合并同时播放,可以随时设置视频播放的位置和时间。当第一个剪辑大小大于第二个剪辑时,第二个剪辑看起来在一个更大的窗口中,并且它的默认位置是左上角的大小,尽管我们可以随时更改它。

下面是实现

Python3
# Import everything needed to edit video clips
from moviepy.editor import *
  
# loading video dsa gfg intro video
clip = VideoFileClip("dsa_geek.webm")
  
# getting only first 5 seconds
clip1 = clip.subclip(0, 5)
  
# rotating clip by 180 degree to get the clip3
clip2 = clip1.rotate(180)
 
# resizing the clip2 reducing it by 50 % clip2 = clip2.resize(0.5)
 
# setting start time to the clip2
clip2 = clip2.set_start(3)
 
# setting position of the clip2
clip2 = clip2.set_position((100, 100))
  
# creating a composite video
final = CompositeVideoClip([clip1, clip2])
  
# 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)
 
# resizing the clip2 reducing it by 50 % clip2 = clip2.resize(0.5)
 
# setting position of the clip2
clip2 = clip2.set_position((150, 100))
 
 
# 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)
 
# resizing the clip2 reducing it by 50 % clip2 = clip2.resize(0.5)
 
# setting position of the clip2
clip2 = clip2.set_position((150, 100))
 
 
# 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