MoviePy 复合视频 - 添加交叉淡入淡出效果
在本文中,我们将了解如何在 MoviePy 中的复合视频文件中添加交叉淡入淡出效果。 MoviePy 是一个用于视频编辑的Python模块,可用于视频和 GIF 的基本操作。复合的含义是组合不同的元素,复合视频是不同视频片段的组合,不像视频文件的堆叠和串联,复合文件易于实现但结构复杂。复合文件将剪辑相互组合并同时播放,可以随时设置视频播放的位置和时间。设置了交叉淡入淡出效果,以便在剪辑更改时发生平滑过渡。交叉淡入淡出是指在电影或广播或电视节目中淡入(声音或图像),同时淡出另一个声音或图像。
In order to do this we will use crossfadein method with the VideoFileClip object
Syntax : clip.crossfadein(n)
Argument : It takes float 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 only first 5 seconds
clip1 = clip.subclip(0, 5)
# rotating clip by 180 degree to get the clip3
clip2 = clip1.rotate(180).set_start(4)
# adding cross fade of 2 seconds in the clip2
clip2 = clip2.crossfadein(2.0)
# 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)
# adding cross fade of 2 seconds in the clip2
clip2 = clip2.crossfadein(2.0)
# 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)
# adding cross fade of 2 seconds in the clip2
clip2 = clip2.crossfadein(2.0)
# 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