我有兴趣在python中每60秒保存一次实时视频,如果有人可以帮助我如何更新它,谢谢
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(True):
ret, frame = cap.read()
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
答案 0 :(得分:1)
此代码正在执行我的要求
import numpy as np
import cv2
import time
import datetime
cap = cv2.VideoCapture(0) #For Laptop Camera (Change to 1,2,3 if other cams attached)
while(True):
ret, frame = cap.read()
date_string = datetime.datetime.now().strftime("%Y-%m-%d %I.%M.%S%p %A")
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(date_string+'.avi',fourcc, 30.0, (640,480))
out.write(frame)
cv2.imshow('frame',frame)
time.sleep(10) # Change 10 to x to save video file after 'x' sec
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()