[참고]

 

[code]

import cv2

capture = cv2.VideoCapture(0)
frame_width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height= int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
print('Frame width:', frame_width)
print('Frame height: ', frame_height)

video = cv2.VideoWriter('captured_video.avi', cv2.VideoWriter_fourcc(*'XVID'), 25, (frame_width, frame_height))

while True:
    has_frame, frame = capture.read()
    if not has_frame:
        print('Can\'t get frame')
        break
    
    video.write(frame)

    cv2.imshow('frame', frame)
    key = cv2.waitKey(3)
    if key == 27:
        print('Pressed ESC')
        break

capture.release()
video.release()
cv2.destroyAllWindows()

 

  • 비디오 쓰기는 cv2.VideoWriter 클래스를 사용해 수행됨
  • 생성자는 출력 비디오 경로, 비디오 코드, 프레임 속도 및 프레임 크기를 지정하는 4개의 문자 코드(FOURCC)를 받음
  • 코덱 코드 : MPEG-1의 경우 P,I,M,1이 포함 /모션-JPEG은 M,J,P,G / XVID MPEG-4에는 X,V,I,D / H.264는 H,2,6,4 포함

+ Recent posts