Skip to content

Commit aecd6d4

Browse files
authored
Merge pull request #265 from TaniaMalhotra/screen-record
Added python script to record screen
2 parents 6af8bfa + 395b4a3 commit aecd6d4

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Python/screen-recording/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Screen Recording
2+
- - - - - -
3+
## Aim
4+
The aim of the script is to record the screen using openCV python.
5+
6+
## Requirements
7+
```pip install numpy```</br>
8+
```pip install pyautogui```</br>
9+
```pip install opencv-python```</br>
10+
11+
## To run
12+
- ```python record.py```
13+
- Press ```'q'``` to stop screen recording

Python/screen-recording/record.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pyautogui
2+
import cv2
3+
import numpy as np
4+
# the resolution of screen recording would be (1920,1080)
5+
# Stating the codec of the video i.e. the format in which it wil be stored
6+
codec = cv2.VideoWriter_fourcc(*"XVID")
7+
# Name of the final recorded file
8+
9+
output_file = "Output.avi"
10+
11+
# This is an object which contains all specifications of our video file
12+
video_writer_obj = cv2.VideoWriter(output_file, codec, 60.0, (1920, 1080))
13+
14+
# Making a new empty window and resizing it later
15+
cv2.namedWindow("New_window", cv2.WINDOW_NORMAL)
16+
cv2.resizeWindow("New_video", 480, 270)
17+
18+
while True:
19+
# Take screenshot using PyAutoGUI
20+
img = pyautogui.screenshot()
21+
22+
# Convert the screenshot to a numpy array
23+
frame = np.array(img)
24+
25+
# BGR to RGB
26+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
27+
28+
video_writer_obj.write(frame)
29+
cv2.imshow('New_window', frame)
30+
31+
# Stop recording when we press 'q'
32+
if cv2.waitKey(1) == ord('q'):
33+
break
34+
35+
# Releasing the output object
36+
video_writer_obj.release()
37+
38+
# Destroy all windows
39+
cv2.destroyAllWindows()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
numpy==1.19.0
2+
opencv-python==4.3.0.36
3+
PyAutoGUI==0.9.52

0 commit comments

Comments
 (0)