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()