forked from makelove/OpenCV-Python-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.VideoWriter.py
More file actions
executable file
·40 lines (30 loc) · 847 Bytes
/
Copy path5.VideoWriter.py
File metadata and controls
executable file
·40 lines (30 loc) · 847 Bytes
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
33
34
35
36
37
38
39
40
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
width = 640
ret = cap.set(3, width)
height = 480
ret = cap.set(4, height)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID') # opencv 3.0
# Error: 'module' object has no attribute 'VideoWriter_fourcc'
# fourcc=cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')
#jpeg,h263,'m', 'p', '4', 'v'
#
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (width, height))
while cap.isOpened():
ret, frame = cap.read()
if ret is True:
frame = cv2.resize(frame, (640, 480))
# write the flipped frame
out.write(frame)
cv2.imshow('frame', frame)
else:
break
key = cv2.waitKey(1)
if key == ord("q"):
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()