-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCV_4_MP4_1.py
29 lines (24 loc) · 980 Bytes
/
CV_4_MP4_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'''this is a blog that looks good and is current
https://www.codingforentrepreneurs.com/blog/how-to-record-video-in-opencv-python/
https://joelmasters.medium.com/how-to-record-video-from-a-camera-using-opencv-and-python-on-mac-3f4306aa710b
Adapted from: https://stackoverflow.com/questions/29317262/opencv-video-saving-in-python/45868817
If your videos are being saved as ~6kb files, there is likely a size mismatch between the resolution of the camera and the VideoWriter.
DID not WORK!
'''
import cv2
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (w,h))
while(cap.isOpened()):
ret, frame = cap.read()
if ret:
out.write(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()