└── Main /Main: -------------------------------------------------------------------------------- 1 | import cv2 2 | import pyautogui 3 | import numpy as np 4 | 5 | def record_screen(filename="screen_record.avi", duration=10, fps=10): 6 | screen_size = pyautogui.size() 7 | fourcc = cv2.VideoWriter_fourcc(*"XVID") 8 | out = cv2.VideoWriter(filename, fourcc, fps, screen_size) 9 | 10 | for _ in range(duration * fps): 11 | img = pyautogui.screenshot() 12 | frame = np.array(img) 13 | frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) 14 | out.write(frame) 15 | 16 | out.release() 17 | print("Recording saved as", filename) 18 | 19 | if __name__ == "__main__": 20 | record_screen() 21 | --------------------------------------------------------------------------------