Skip to main content

Posts

Showing posts with the label saving video

Saving a Video OpenCV Python

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. import cv2 capture = cv2.VideoCapture( 0 ) # Create VideoWriter object fourcc = cv2.VideoWriter_fourcc(* 'XVID' ) out = cv2.VideoWriter( 'recorded.avi' , fourcc , 20.0 , ( 640 , 480 )) while (capture.isOpened()):  ret , frame = capture.read()   if ret== True :   frame = cv2.flip(frame , 0 )   out.write(frame)   cv2.imshow( 'frame' , frame)   if cv2.waitKey( 1 ) & 0xFF == ord ( 'e' ):    break   else :    break capture.release() out.release() cv2.destroyAllWindows()