-
Notifications
You must be signed in to change notification settings - Fork 0
/
Recorder.py
38 lines (29 loc) 路 968 Bytes
/
Recorder.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
33
34
35
36
37
38
import pyautogui
import cv2
import numpy as np
import random
resolution = tuple(pyautogui.size())
fps = 12.0
codec = cv2.VideoWriter_fourcc(*"MJPG")
filename = "screen_recording"+str(random.randint(0, 1000))+".avi"
# Creating a VideoWriter object
writer = cv2.VideoWriter(str(filename), codec, fps, resolution)
# Creating an Empty window
cv2.namedWindow("Screen Recorder", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Screen Recorder", 480, 270)
while True:
img = pyautogui.screenshot()
# Convert the screenshot to a numpy array
frame = np.array(img)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) #BGR to RGB
# Writing it to the output file
writer.write(frame)
# Displaying the recording screen
cv2.imshow('Screen Recorder', frame)
# Stop recording when we press 'q'
if cv2.waitKey(1) == ord('q'):
print("Recording Stopped")
break
print("Recordings saved as: "+filename)
writer.release()
cv2.destroyAllWindows()