I am using this sample code from opencvthe OpenCV documentation and what the code is simply doing is capturing a video and when itsit's interrupted it saves it to a folder what.
What I want to do it capture the video for a certain period of time and, quit, and then save it to the folder and I really don't know how to do it I will very much appreciate your help in advance if someone could assist me please am totally new to python and opencv so pardon me cheers.
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(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()