Python 按指定视频帧间隔截图
import cv2
import os.path
from tqdm import tqdm
file_path = r"F:\\Files\\"
path_dir = os.listdir(file_path)
save_path = r"L:\\0\\"
name_count = 1
video_path = file_path + "1.avi"
video = cv2.VideoCapture(video_path)
if video.isOpened():
rval, frame = video.read()
print("开始读取视频")
else:
rval = False
print("读取视频失败")
timeF = 1
c = 1
if not os.path.exists(save_path):
os.makedirs(save_path)
print("创建保存截图目录")
while rval:
if c % timeF == 0:
imageName = str(name_count).zfill(5)
cv2.imwrite(save_path + imageName + '.jpg', frame)
print("保存图片:" + save_path + imageName + '.jpg')
name_count = name_count + 1
c = c + 1
cv2.waitKey(1)
rval, frame = video.read()
video.release()