Screen recorder

# importing packages

import pyautogui

import cv2

import numpy as np

#resolution

resolution = (1920, 1080)

codec = cv2.VideoWriter_fourcc(*"XVID")

#Output file

filename = "Recordings.avi"

#frames rate

fps = 60.0

# Create a VideoWriter object

out = cv2.VideoWriter(filename, codec, fps, resolution)

# Creating an Empty window

cv2.namedWindow("Live", cv2.WINDOW_NORMAL)

# Resize this window

cv2.resizeWindow("Live", 480, 270)

while True:

# Take screenshot using PyAutoGUI

img = pyautogui.screenshot()

# Convert the screenshot to a numpy array

frame = np.array(img)

# Convert it from BGR(Blue, Green, Red) to

# RGB(Red, Green, Blue)

frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

# Write output file

out.write(frame)

#Display the recording screen

cv2.imshow('Live', frame)

# Stop recording when we press 'q'

if cv2.waitKey(1) == ord('q'):

break

# Release the Video writer

out.release()

# Destroy windows

cv2.destroyAllWindows()


No comments: