我正在寻找每一分钟保存视频并重新录制的方法。当我运行我的代码时,我会捕获它,直到我按下'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()发布于 2021-09-24 13:59:10
你还没有发布你的代码,也不是很明显,你是如何记录的,但是下面的代码可以为你添加一个计时器,它提供了大量的定制,例如在指定的秒、分钟甚至几个小时内记录一次。
from time import sleep
from apscheduler.schedulers.blocking import BlockingScheduler
def RecordVideo():
print("Starting the recording")
#record your content
#close camera/desktop or other resource
print('Recording Completed!')
scheduler = BlockingScheduler()
scheduler.add_job(RecordVideo, 'interval', minutes=1) #once per minute
#scheduler.add_job(RecordVideo, 'interval', seconds=60) for timer in seconds
#scheduler.add_job(RecordVideo, 'interval', seconds=60) for timer in hours
scheduler.start()
while True: #keeps the program running
sleep(0.1)只需将录制功能添加为作业即可
https://stackoverflow.com/questions/69315905
复制相似问题