SoFunction
Updated on 2024-12-12

Example of screen recording in python

The installation command for PIL, or follow, is as follows:

pip install pillow

where cv2 is installed with the following command

pip install opencv-python

Code Implementation:

# coding: utf-8
from PIL import ImageGrab
import numpy as np
import cv2
 
fps = 20
start = 3 # Time-lapse recording
end = 15 # Automatic end time
 
curScreen = () # Get the screen object
height, width = 
 
video = ('', cv2.VideoWriter_fourcc(*'XVID'), fps, (height, width))
 
imageNum = 0
while True:
 imageNum += 1
 captureImage = () # Grab the screen
 frame = ((captureImage), cv2.COLOR_RGB2BGR)
 
 # Show windows without images
 ('capturing', ((1, 255), np.uint8))
 
 # Control window display location for easy exit by keystroke
 ('capturing', height - 100, width - 100) 
 if imageNum > fps * start:
  (frame)
 # Exit conditions
 if (50) == ord('q') or imageNum > fps * end:
  break
()
()

Above this python implementation of screen recording example is all that I have shared with you, I hope to give you a reference, and I hope you support me more.