我正在寻找每分钟保存视频并再次录制的方法。当我运行我的代码时,我会捕获它,直到我按下“q”。有没有办法自动保存并重新记录?我使用 imutils,cv2
import imutils
import cv2 # opencv 모듈
video = ""
result_path = "result_video.avi"
if video == "":
print("[webcam start]")
vs = cv2.VideoCapture(0)
else:
print("[video start]")
vs = cv2.VideoCapture(video)
writer = None
while True:
ret, frame = vs.read()
if frame is None:
break
frame = imutils.resize(frame, width=320, height=240)
cv2.imshow("frame", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
if writer is None:
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
writer = cv2.VideoWriter(result_path, fourcc, 25, (frame.shape[1], frame.shape[0]), True)
if writer is not None:
writer.write(frame)
vs.release()
cv2.destroyAllWindows()