import cv2 as cv
import os
path_video = '' #file_path
path_save = '' #保存路径
for root, dirs, files_video in os.walk(path_video):
print(files_video)#所有视频名称
for files_name in files_video:
print(files_name)
count = 0
video_address = path_video + files_name
os.makedirs(path_save+files_name + '/', exist_ok=True)
video = cv.VideoCapture( video_address )
if (video.isOpened() == False):
print("error opening video stream or file!")
while (video.isOpened()):
ret, frame = video.read()
if ret == False:
break
#time_stamp_fromvideo = video.get(cv.CAP_PROP_POS_MSEC)
pic_path = path_save+files_name + '/'
cv.imwrite(pic_path + files_name + '_' + str(count) + '.jpg', frame) # 存储为图像,保存名为 文件夹名_数字(第几个文件).jpg
#print(time_stamp_fromvideo)
#print("\n")
cv.waitKey(1)
count=count+1
video.release()
print('the current video' + files_name + ' is done')