I'm looking for ways to save the video every minute and record it again. When I run my code, I capture it until I press 'q'. Is there a way to automatically save it and record it again? I use 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()
You have not posted your code and its not obvious, how you are recording but following code can add a timer for you that offers a lot of customization e.g. recording once in specified seconds, minutes or even hours.
Simply add your recording function as a job