Skip to content

Commit 189c30b

Browse files
committed
Python Screen Recorder
1 parent 62f6d7b commit 189c30b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

PYTHON APPS/ScreenRecorder/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Screen Recorder Using Python
2+
3+
Go over the code explanation step by step and then run the code to see the result.
4+
5+
The code explanation is under an article on my [Blog page here](https://sweetcode.io/author/hnyakundi/)
6+
7+
The sample output is as shown below.

PYTHON APPS/ScreenRecorder/output.avi

10.6 MB
Binary file not shown.

PYTHON APPS/ScreenRecorder/screen.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import cv2
2+
import numpy as np
3+
import pyautogui
4+
5+
# Get the size of the screen using pyautogui
6+
SCREEN_SIZE = tuple(pyautogui.size())
7+
8+
# Define the codec and create VideoWriter object
9+
fourcc = cv2.VideoWriter_fourcc(*'XVID')
10+
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (SCREEN_SIZE))
11+
webcam = cv2.VideoCapture(0)
12+
13+
while True:
14+
# Capture the screen
15+
img = pyautogui.screenshot()
16+
17+
# Convert the image into numpy array
18+
img = np.array(img)
19+
20+
# Convert the color space from BGR to RGB
21+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
22+
23+
_, frame = webcam.read()
24+
# Finding the width, height and shape of our webcam image
25+
fr_height, fr_width, _ = frame.shape
26+
# setting the width and height properties
27+
img[0:fr_height, 0: fr_width, :] = frame[0:fr_height, 0: fr_width, :]
28+
29+
cv2.imshow('frame', img)
30+
31+
# Write the frame into the file 'output.avi'
32+
out.write(img)
33+
34+
# Press 'q' to quit
35+
if cv2.waitKey(1) & 0xFF == ord('q'):
36+
print("Recording Stopped")
37+
break
38+
39+
out.release()
40+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)