Skip to content

Create Screen_rec.py #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Screen_Recorder/Screen_rec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#importin the packages
import cv2
import pyautogui
import numpy as np

#Set the parameters
screen_width, screen_height = pyautogui.size()
resolution = (screen_width, screen_height)
fps = 30
rec_time = 5;
opname = "Sample.mp4"

#Initialise parameters for the VideoWriter class
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
out = cv2.VideoWriter(opname, fourcc, fps, resolution)

#Extract the frames and display them at the specified rate
for _ in range(int(rec_time* fps)):
x = pyautogui.screenshot()
frame = np.array(x)
frame = cv2.cvtColor(frame,cv2.COLOR_RGB2BGR)
out.write(frame)

End the Screen recording and save the video
out.release();