MoviePy 复合视频 - 设置单个剪辑的开始时间
在本文中,我们将了解如何在 MoviePy 中设置复合视频文件中单个剪辑的开始时间。 MoviePy 是一个用于视频编辑的Python模块,可用于视频和 GIF 的基本操作。复合的含义是组合不同的元素,复合视频是不同视频片段的组合,不像视频文件的堆叠和串联,复合文件易于实现但结构复杂。复合文件将剪辑相互组合并同时播放,可以随时设置视频播放的位置和时间。
In order to do this we will use set_start method with the VideoFileClip object
Syntax : clip.set_start(n)
Argument : It takes integer 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 and getting only first 5 seconds
clip = VideoFileClip("dsa_geek.webm").subclip(0, 5)
# setting margin
clip1 = clip.margin(40)
# rotating clip by 180 degree to get the clip3
clip2 = clip.rotate(180).set_start(4)
# 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)
# creating a composite video
final = CompositeVideoClip([clip1, clip2])
# showing final clip
clip.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
clip.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