📜  MoviePy – 从视频文件剪辑中获取帧

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

MoviePy – 从视频文件剪辑中获取帧

在本文中,我们将了解如何从 MoviePy 中的视频文件剪辑中获取给定时间的帧。 MoviePy 是一个用于视频编辑的Python模块,可用于视频和 GIF 的基本操作。帧的组合制作视频,每次都存在一个类似于普通图像的特定帧。获取帧意味着获取一个numpy数组,表示剪辑在时间t的RGB图片或声音的(单声道或立体声)值夹子。

下面是实现

# importing matplotlib
from matplotlib import pyplot as plt
  
# importing numpy
import numpy as np
  
# 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)
    
# getting only first 5 seconds 
clip = clip.subclip(0, 5) 
  
# getting frame at time 3
frame = clip.get_frame(3)
  
# showing the frame with the help of matplotlib
plt.imshow(frame, interpolation ='nearest')
  
# show
plt.show()

输出 :

另一个例子

# importing matplotlib
from matplotlib import pyplot as plt
  
# importing numpy
import numpy as np
  
# Import everything needed to edit video clips 
from moviepy.editor import *
    
# loading video dsa gfg intro video 
clip = VideoFileClip("dsa_geek.mp4") 
     
# getting only first 5 seconds
clip = clip.subclip(0, 5)
  
  
# getting frame at time 2
frame = clip.get_frame(2)
  
# showing the frame with the help of matplotlib
plt.imshow(frame, interpolation ='nearest')
  
# show
plt.show()

输出 :