可以在ubuntu使用,生成的图像名称是6位按顺序的数字
'''
读取文件列表,将视频文件单独拿出来,隔帧抽图并保存
'''
import cv2
import os
import glob
mp4s = glob.glob('*.mp4')
for one_mp4 in mp4s:
print(one_mp4)
sourceFileName = one_mp4
video_path = os.path.join("", "", sourceFileName)
times = 0
namenumber = 0
frameFrequency = 1
outPutDirName = 'VedioPicture/' + sourceFileName + '/'
if not os.path.exists(outPutDirName):
os.makedirs(outPutDirName)
camera = cv2.VideoCapture(video_path)
while True:
times += 1
namenumber += 1
res, image = camera.read()
if not res:
print('not res , not image')
break
if times % frameFrequency == 0:
if (namenumber < 10):
namenumber2str = '00000' + str(namenumber)
elif (namenumber < 100):
namenumber2str = '0000' + str(namenumber)
elif (namenumber < 1000):
namenumber2str = '000' + str(namenumber)
elif (namenumber < 10000):
namenumber2str = '00' + str(namenumber)
elif (namenumber < 100000):
namenumber2str = '0' + str(namenumber)
else:
namenumber2str = str(namenumber)
cv2.imwrite(outPutDirName + namenumber2str + '.jpg', image)
print outPutDirName + namenumber2str + '.jpg'
print one_mp4 + '图片提取结束'
camera.release()