Created
May 1, 2023 07:43
-
-
Save ochilab/e9556b138f31420b799da4ae56c36a0d to your computer and use it in GitHub Desktop.
Python: OpenCVでカメラの映像を動画ファイルとして保存する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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