-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec6c653
commit eea9d17
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# importing the required packages | ||
import pyautogui | ||
import cv2 | ||
import numpy as np | ||
#install the packages using pip | ||
|
||
# Specify resolution | ||
resolution = (1920, 1080) | ||
|
||
# Specify video codec | ||
codec = cv2.VideoWriter_fourcc(*"XVID") | ||
|
||
# Specify name of Output file | ||
filename = "Recording.avi" | ||
|
||
# Specify frames rate. We can choose | ||
# any value and experiment with it | ||
fps = 60.0 | ||
|
||
# Creating a VideoWriter object | ||
out = cv2.VideoWriter(filename, codec, fps, resolution) | ||
|
||
# Create 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 it to the output file | ||
out.write(frame) | ||
|
||
# Optional: 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 all windows | ||
cv2.destroyAllWindows() |