Skip to content

Commit c00acfe

Browse files
committed
added screen recorder tutorial
1 parent 092db32 commit c00acfe

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

general/screen-recorder/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# [How to Make a Screen Recorder in Python](https://www.thepythoncode.com/article/make-screen-recorder-python)
2+
To run this:
3+
- `pip3 install -r requirements.txt`
4+
- `python3 screen_recorder.py`
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
numpy
2+
opencv-python
3+
pyautogui
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import cv2
2+
import numpy as np
3+
import pyautogui
4+
5+
# display screen resolution, get it from your OS settings
6+
SCREEN_SIZE = (1920, 1080)
7+
# define the codec
8+
fourcc = cv2.VideoWriter_fourcc(*"XVID")
9+
# create the video write object
10+
out = cv2.VideoWriter("output.avi", fourcc, 20.0, (SCREEN_SIZE))
11+
12+
while True:
13+
# make a screenshot
14+
img = pyautogui.screenshot()
15+
# convert these pixels to a proper numpy array to work with OpenCV
16+
frame = np.array(img)
17+
# convert colors from BGR to RGB
18+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
19+
# write the frame
20+
out.write(frame)
21+
# show the frame
22+
cv2.imshow("screenshot", frame)
23+
# if the user clicks q, it exits
24+
if cv2.waitKey(1) == ord("q"):
25+
break
26+
27+
# make sure everything is closed when exited
28+
cv2.destroyAllWindows()
29+
out.release()
30+

0 commit comments

Comments
 (0)