# 读取视频文件并逐帧存储
cap = cv2.VideoCapture(path)
frame_len = cap.get(cv2.CAP_PROP_FRAME_COUNT)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = int(cap.get(cv2.CAP_PROP_FPS))
fourcc = cv2.VideoWriter_fourcc('X', 'V', 'I', 'D') # ('I', '4', '2', '0')
videoWriter = cv2.VideoWriter(path2save, fourcc, fps, frame_size) # eg.可置frame_size=(width,height)
cap_ok = cap.isOpened()
while cap_ok:
ret, frame = cap.read() # frame: hwc
if not ret:
break
videoWriter.write(frame)
cap.release()
videoWriter.release()
# 调用自带摄像头获取视频流
def camera_init(args):
camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FRAME_WIDTH, args.width)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, args.height)
camera.set(cv2.CAP_PROP_FPS, args.fps)
return camera
Python-opencv读取和存储视频
最新推荐文章于 2024-08-20 10:56:00 发布