Python is a widely used general-purpose language. It allows performing a variety of tasks. One of them can be recording a video. It provides a module named pyautogui which can be used for the same. This module along with NumPy and OpenCV provides the way to manipulate and save the images (screenshot in this case)
- Numpy: To install Numpy type the below command in the terminal.
pip install numpy
- pyautogui: To install pyautogui type the below command in the terminal.
pip install pyautogui
- OpenCV: To install OpenCV type the below command in the terminal.
pip install opencv-python
Below is the implementation.
First, import all the required packages.
Now, before recording the screen, we have to create a VideoWriter object. Also, we have to specify the output file name, Video codec, FPS, and video resolution. In video codec, we have to specify a 4-byte code (such as XVID, MJPG, X264, etc.). We’ll be using XVID here.
Optional: To display the recording in real-time, we have to create an Empty window and resize it.
Now, let’s start recording our screen. We will be running an infinite loop and in each iteration of the loop, we will take a screenshot and write it to the output file with the help of the video writer.
After everything is done, we will release the writer and destroy all windows opened by OpenCV.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Create a Voice Recorder using Python
- Build a Voice Recorder GUI using Python
- How to create a Splash Screen using Tkinter?
- Getting screen's height and width using Tkinter | Python
- Replace Green Screen using OpenCV- Python
- Build an Application for Screen Rotation Using Python
- How to Control Laptop Screen Brightness using Python?
- How to show a timer on screen using arcade in Python3?
- wxPython - Create Radio Button using Create() function
- wxPython - Create Static Box using Create() method
- How to clear screen in python?
- Python | Multiple Sliders widgets Controlling Background Screen or WindowColor in Kivy
- Python PIL | ImageChops.screen() and ImageChops.offset() method
- Python | How to download windows lock-screen wallpapers
- How to Get Coordinate Of Screen in Python Turtle ?
- Python Tweepy - Getting the screen name of a user
- turtle.Screen().bgcolor() function in Python
- Python - turtle.Screen().setup() method
- turtle.Screen().turtles() function in Python
- Python VLC MediaPlayer - Toggling Full Screen
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.