forked from samwestby/OpenCV-Python-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_video.py
32 lines (25 loc) · 952 Bytes
/
4_video.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
30
31
32
import cv2 # See video 1 for installation
# Replace "0" with a file path to work with a saved video
stream = cv2.VideoCapture(0)
if not stream.isOpened():
print("No stream :(")
exit()
fps = stream.get(cv2.CAP_PROP_FPS)
width = int(stream.get(3))
height = int(stream.get(4))
# list of FourCC video codes: https://softron.zendesk.com/hc/en-us/articles/207695697-List-of-FourCC-codes-for-video-codecs
output = cv2.VideoWriter("assets/4_stream.mp4",
cv2.VideoWriter_fourcc('m', 'p', '4', 'v'),
fps=fps, frameSize=(width, height))
while True:
ret, frame = stream.read()
if not ret: # if no frames are returned
print("No more stream :(")
break
frame = cv2.resize(frame, (width, height))
output.write(frame)
cv2.imshow("Webcam!", frame)
if cv2.waitKey(1) == ord('q'): # press "q" to quit
break
stream.release()
cv2.destroyAllWindows() #!