OpenCV python : cv.VideoWriter_fourcc(*argu)

 Introduction

This is the function to generate the fourcc code for video compression or video saving system it returns an integer value that will pass to VideoWritter function as an argument so it will  save the video according to the fourcc opted,

code:

fourcc = cv.VideoWriter_fourcc(*'XVID')


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