运用 Python按照一定的帧数间隔截取视频
import cv2 as cv
import os.path
path = './img'#图片储存路径,用于存储截取后的图片,此处为相对路径
def cutVideo():
i = 0
video = cv.VideoCapture('video.mp4') # 读取视频文件
while(True):
ret,frame = video.read()
if frame is None:
break;
c = cv.waitKey(50)
if c == 27:
break
i=i+1
if i%20==0:#图片截取帧数间隔
cv.imwrite(path+'/img'+str(int(i/20))+'.jpg',frame)#图片保存
cutVideo()