Je veux utiliser OpenCV et une webcam pour enregistrer en continu la vidéo de la webcam pendant 15 minutes, puis redémarrer le processus pour avoir 15 minutes de vidéo. J'ai déjà écrit un script, mais j'ai un comportement inattendu. L'enregistrement fonctionne correctement pendant un certain temps, puis le programme crée uniquement des fichiers de taille 5 kb qui ne sont pas lisibles.Python OpcenCV diviser l'enregistrement en plusieurs fichiers
Est-ce que quelqu'un pourrait savoir pourquoi?
Voici le code:
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()