OpenCV : VideoWritter()

This is the Function used to write the video in permanent memory 

Arguments,

1.  FileName with Extension 

2. fourCC code from VideoWriter_fourcc() function which takes fourcc codes like XVID,DVIX etc

3. the FPS or frame per second

4. tuple of the Dimension recommended to use predefined dimensions wisely otherwise u can face errors

5. Color which takes an boolean value and decides the color of video if 1 then coloured other wise grayscale

code :


import cv2 as cv

cap  = cv.VideoCapture(0)

fourcc = cv.VideoWriter_fourcc(*'XVID')
output  = cv.VideoWriter("./output/myvideo.avi",fourcc,20.0,(640,480))

while cap.isOpened():

    ret, frame = cap.read()
    print(frame)
    if not ret:
        break
    # frame  = cv.flip(frame,0)
    cv.imshow("Video Capturing",frame)
    output.write(frame)
    if cv.waitKey(20) & 0xFF == ord('x'):
        print('Video saved Successfully in current Directory')
        break

#Now most important part releasing all the resourses to prevent the conflict between the resourses
output.release()
cap.release()
cv.destroyAllWindows()

Comments

Pageviews