Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created May 1, 2023 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochilab/e9556b138f31420b799da4ae56c36a0d to your computer and use it in GitHub Desktop.
Save ochilab/e9556b138f31420b799da4ae56c36a0d to your computer and use it in GitHub Desktop.
Python: OpenCVでカメラの映像を動画ファイルとして保存する
import cv2
cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# フォーマット指定
fmt = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
writer = cv2.VideoWriter('output.mp4', fmt, 25, (width, height))
while True:
ret, frame = cap.read()
if ret == False:
break
writer.write(frame)
cap.release()
writer.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment