MoviePy - 获取光标触摸的视频剪辑帧的颜色
在本文中,我们将了解如何在 MoviePy 中获取视频文件剪辑在给定时间的单帧颜色。 MoviePy 是一个用于视频编辑的Python模块,可用于视频和 GIF 的基本操作。视频是由帧组成的,帧的组合创建一个视频,每一帧都是一个单独的图像。我们可以在 VideoFileClip 对象的 save_frame 方法的帮助下随时存储特定帧。通过打开交互式我们可以得到光标点击的位置和颜色。
方法 clip.show 可以预览剪辑的一帧,而无需将其写入文件:以下行在 PyGame 窗口中显示该帧
In order to do this we will use show method with the VideoFileClip object
Syntax : clip.show(t, interactive = True))
Argument : It takes time and iterative = True as argument
Return : It returns None
下面是实现
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
clip = clip.subclip(0, 5)
# showing frame at 2 second
clip.show(2, interactive = True)
Python3
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video gfg
clip = VideoFileClip("geeks.mp4")
# getting only first 5 seconds
clip = clip.subclip(0, 5)
# showing frame at 3 second
clip.show(3, interactive = True)
输出 :
position, color : (262, 174), [246 135 102]
position, color : (566, 131), [251 255 255]
position, color : (227, 269), [38 38 38]
position, color : (419, 319), [255 255 255]
另一个例子
Python3
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video gfg
clip = VideoFileClip("geeks.mp4")
# getting only first 5 seconds
clip = clip.subclip(0, 5)
# showing frame at 3 second
clip.show(3, interactive = True)
输出 :
position, color : (248, 305), [239 239 239]
position, color : (136, 93), [239 239 239]
position, color : (229, 181), [ 17 147 6]
position, color : (122, 83), [239 239 239]
position, color : (358, 125), [239 239 239]