一个视频切片,代码如下:
import cv2
vc = cv2.VideoCapture(r'F:\1\1\2\20210520000302.avi') # 读入文件地址
n = 1
if vc.isOpened():
rval, frame = vc.read()
else:
rval = False
timeF = 2 # 视频帧计数间隔,按需修改
i = 0
while rval:
rval, frame = vc.read()
if (n % timeF == 0):
i += 1
a=r'F:\1\1\1/20210520000302_01_{}.jpg'
b=cv2.imwrite(a.format(str(i).rjust(2,'0')),frame) # 存储地址
print(a)
n = n + 1
cv2.waitKey(1)
vc.release()
多个视频切片:按照上面代码做的修改。
import cv2
import os
import shutil
root_path = 'F:\\20240822015-20240822025-110\\'
out_path=r'F:\0/'
files_0 = os.listdir(root_path )
for file_0 in files_0:
b=file_0.split('.')
a=root_path+file_0
vc = cv2.VideoCapture(os.path.join('r