import cv2
def get_each_frame(video_path):
# 读取视频文件
videoCapture = cv2.VideoCapture(video_path)
# 读帧
success, frame = videoCapture.read()
i = 0
# 设置固定帧率
timeF = 1 # 帧率,根据情况自行修改合适的帧率
j = 0
while success:
i = i + 1
if (i % timeF == 0):
j = j + 1
address = video_path[:-9]+ str(j) + '.jpg'
cv2.imwrite(address, frame)
print('save image:', i)
success, frame = videoCapture.read()
get_each_frame(r"E:\report\video.avi")
运行结果:
运行截图:
备注:
1.timeF为帧率,可根据自身情况做修改
2.调用函数时需要传入视频路径,提取的图片保存在视频同目录下