import cv2
import os
import shutil
#input video
filename = '20190327.mp4'
savedpath = filename.split('.')[0] + '/'
isExists = os.path.exists(savedpath)
if not isExists:
os.makedirs(savedpath)
print('path of %s is build'%(savedpath))
else:
shutil.rmtree(savedpath)
os.makedirs(savedpath)
print('path of %s already exist and rebuild'%(savedpath))
fps = 14.91
# the gap of frame
count = 10
videoCapture = cv2.VideoCapture(filename)
i = 0
j = 0
while True:
success,frame = videoCapture.read()
i+=1
if not success:
print('video is all read')
break
if(i % count ==0):
j += 1
savedname = filename.split('.')[0] + '_' + str(j) + '_' + str(i)+'.jpg'
cv2.imwrite(savedpath + savedname ,frame)
print('image of %s is saved'%(savedname))