GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing thepythoncode.com — How to Record your Screen in Python - The Python Code Ready to take Python coding to a new level? Explore our Python Code Generator. The perfect tool to get your code up and running in no time. Start now! Screen recording enables you to create demonstration videos, record gaming achievements, and create videos that can be shared online on social media. Many industrial software exist out there that can help you do that very easily, though. In this tutorial, you will learn how to make your own simple screen recorder in Python that you can further extend to your own needs. This tutorial is about recording your whole screen. If you want to record a specific window, then check this tutorial, as it's exactly what you need. Related: How to Use Steganography to Hide Secret Data in Images in Python. Let's get started, first, install the required dependencies for this tutorial:
The process of this tutorial is as follows:
Importing necessary modules:
Let's initialize the format we gonna use to write our video file ( named "output.avi" ):
We're getting the screen resolution from the fourcc is the video codec library that OpenCV will use to write the video file, we specified XVID here. We also set the FPS to The Now we need to keep capturing screenshots and writing to the file in a loop until the seconds are passed or the user clicks the "q" button, here is the main loop for that:
First, we use the screenshot() function, which returns an image object, so we need to convert it to a proper numpy array. After that, we need to convert that frame into RGB, that's because OpenCV uses BGR by default. The loop will finish once the seconds are passed or if you hit the "q" button. Note that if you increase the FPS, you may see the video is a bit sped up because your CPU can't handle that speed. If you don't want to see your record in real time, simply comment out the As mentioned in the pyautogui's official documentation, you can also record only regions of your screen by passing the
After you are done with recording, just click "q", it will destroy the window and finish writing to the file, try it out! Alright, there are endless ideas you can use to extend this. For example, you can combine this with an audio recorder, and you'll come up with a Python tool that records your screen and voice simultaneously; you will need to use a thread that records audio and another for the screen recorder. Or you can add an audio file to your video recording. You can also create keyboard shortcuts that start, pause, and stop the recording, this tutorial can help you. Learn also: How to Extract Frames from Video in Python Happy Coding ♥ Loved the article? You'll love our Code Converter even more! It's your secret weapon for effortless coding. Give it a whirl!
Sharing is caring!
Read also
How to Extract Frames from Video in PythonMaking two different methods to extract frames from videos with the timestamp with OpenCV or MoviePy libraries in Python.
How to Generate and Read QR Code in PythonLearning how you can generate and read QR Code in Python using qrcode and OpenCV libraries. How to Play and Record Audio in PythonLearn how to play and record sound files using different libraries such as playsound, Pydub and PyAudio in Python. CommentsGot a coding query or need some guidance before you comment? Check out this Python Code Assistant for expert advice and handy tips. It's like having a coding tutor right in your fingertips! |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |