Saving a Video
In this lesson, we will learn how to record video in OpenCV. This process is very simple for images. Only the cv2.imwrite () function is used. Recording videos is a bit more difficult. Let's create a VideoWriter object for this process. We must determine the name of the file to be saved. Then we have to specify the FourCC code.
Then the number of frames per second and frame size must be selected.
capture = cv2.VideoCapture(0)
# Create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('recorded.avi',fourcc, 20.0, (640,480))
ret, frame = capture.read()
frame = cv2.flip(frame,0)
if cv2.waitKey(1) & 0xFF == ord('e'):