# --*-- coding: utf-8 --*--
import os
import sys
import cv2
gef getFrame(srcRoot,saveRoot):
fileList = os.listdir(srcRoot)
for i in range(len(fileList))
tmpName = 0
frameFrequency = 5 # 每5帧抽1帧
if not fileList[i].endswith('.mkv'):
continue
filePath = srcRoot + '\\'+ fileList[i] # .\DK\0-1.mkv
print(filePath)
if not os.path.exists(saveRoot):
os.makedirs(saveRoot)
single_path = os.path.join(saveRoot, fileList[i].split('.')[0])
if not os.path.exists(single_path):
os.makedirs(single_path)
videoFile = cv2.VideoCapture(filePath) # 打开视频
while True:
tmpName += 1
res, image = videoFile.read() # 按帧读取视频
if not res:
print('not res , not image')
break
if tmpName % frameFrequency == 0:
save_path = os.path.join(single_path, str(tmpName)+'.jpg')
cv2.imwrite(save_path, image)
print(save_path, 'save done!')
print(i, filePath + '图片提取结束')
videoFile.release()
videoPath = sys.argv[1] # .\DK
saveRoot = sys.argv[2] # .\DK_Sampling_5Frame
getFrame(videoPath,saveRoot)
#useage: python GetFrame.py videoPath saveRoot
python-对一个目录下的多个视频进行抽帧
最新推荐文章于 2024-08-28 09:20:11 发布