0
我想使用OpenCV和网络摄像头连续录制视频15分钟,然后再次启动该过程,以便获得15分钟的视频。 我已经写了一个脚本,但遇到意想不到的行为。录制工作一段时间,然后该程序只会创建5kb大小的文件,无法播放。Python OpcenCV将录制文件分割为多个文件
有人会知道为什么会发生这种情况吗?
这是代码:
import numpy as np
import cv2
import time
cap = cv2.VideoCapture(0)
#Record the current time
current_time = time.time()
#Specify the path and name of the video file as well as the encoding, fps and resolution
out = cv2.VideoWriter('/mnt/NAS326/cctv/' + str(time.strftime('%d %m %Y - %H %M %S')) + '.avi', cv2.cv.CV_FOURCC('X','V','I','D'), 15, (640,480))
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
out.write(frame)
#If the current time is greater than 'current_time' + seconds specified then release the video, record the time again and start a new recording
if time.time() >= current_time + 900:
out.release()
current_time = time.time()
out = cv2.VideoWriter('/mnt/NAS326/cctv/' + str(time.strftime('%d %m %Y - %H %M %S')) + '.avi', cv2.cv.CV_FOURCC('X','V','I','D'), 15, (640,480))
out.release()
cap.release()
cv2.destroyAllWindows()