Tuesday, November 17
Trending
- Microsoft 365 Outage: Outlook, Teams and Copilot Down. What We Know
- Diwali Online Shopping Scams 2026: 10 Ways to Stay Safe
- 10 Best DDoS Protection Services for 2027
- 12 Best Web Application Firewalls (WAF) for 2027
- Best Ethical Hacking Tools in 2027: Free & Paid Picks
- Software supply chain attacks 2026: Timeline and developer checklist
- Binance Hack: $6.3 Billion Drained in the Largest Crypto Theft Ever. What We Know So Far
- This Site Uses XSLT Chrome Warning Explained: How to Fix It
In this tutorial, we will learn how to create a screen recorder using the OpenCV and PyAutoGUI libraries.
PyAutoGUI is a cross-platform GUI automation module in Python used to programmatically control the mouse & keyboard.
Installing the modules
To install the OpenCV and PyAutoGUI module and some other associated dependencies, we can use the pip command:
pip install opencv-python pip install PyAutoGUI pip install numpy
Source code
import pyautogui
import cv2
import numpy as np
from datetime import datetime
resolution = pyautogui.size()
now = datetime.now()
timestamp = datetime.timestamp(now)
codec = cv2.VideoWriter_fourcc(*"XVID")
filename = str(int(timestamp))+".avi"
fps = 60.0
out = cv2.VideoWriter(filename, codec, fps, resolution)
cv2.namedWindow("Live", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Live", 480, 270)
while True:
img = pyautogui.screenshot()
frame = np.array(img)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
out.write(frame)
cv2.imshow("Live", frame)
if cv2.waitKey(1) == ord('q'):
break
out.release()
cv2.destroyAllWindows()


