CREATE YOUR OWN SCREEN RECORDER – PYTHON PROJECT

python screen recorder projects codes

In the previous python project we discussed how to make scissor paper rock game using tkinter. If you haven’t checked that project yet then CLICK HERE

We are back with yet another python project series. Today we will create our own screen recorder which captures the screen. We can record screenshot and record the screen as well.

For this you will need opencv and pyscreenshot library in your system. PyScreenshot is used for capturing the frames while OpenCV is used for saving the frames in this tutorial.

Requirement :
  • PyQt5
  • Opencv
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtCore import pyqtSlot
from pyautogui import screenshot
import cv2
import glob
from threading import Thread
import shutil
import os
import time

class App(QWidget, Thread):
    """Inherit the class Thread"""
    def __init__(self):
        """Initialize init"""
        super().__init__()
        self.title = 'Screen Recorder'
        self.left = 10
        self.top = 10
        self.width = 500
        self.height = 50
        self.count = 0
        self.status = True
        Thread.__init__(self)
        self.daemon = Thread(target=self.start_recording, name="start_recording")
        self.daemon.setDaemon(True)
        self.initUI()

    def initUI(self):
        """Initialize UI"""
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        button = QPushButton('Start Desktop Recorder', self)
        button.setToolTip('Click here to start recording')
        button.move(10, 10)
        button.clicked.connect(self.start_threading)
        button = QPushButton('Take Screenshot', self)
        button.setToolTip('Click here to take screenshot')
        button.move(190, 10)
        button.clicked.connect(self.take_screenshot)
        button = QPushButton('Stop Desktop Recording', self)
        button.setToolTip('Click here to stop recording')
        button.move(320, 10)
        button.clicked.connect(self.stop_recording)
        self.show()

    def start_recording(self):
        """Start Recording, take screenshot and store in directory"""
        while self.status:
            self.count += 1
            print("Inside start recording", self.count)
            if not os.path.isdir("screenshots"):
                os.mkdir("screenshots")
            else:
                filename = "screenshots/" + str(self.count) + ".jpg"
                screenshot(filename)

    @pyqtSlot()
    def start_threading(self):
        """Start threading and daemon"""
        print("Inside start threading")
        self.daemon.start()

    @pyqtSlot()
    def stop_recording(self):
        """Stop Recording and create video."""
        print('Stop Button has been pressed')
        try:
            img_array = []
            self.status = False
            for filename in glob.glob('screenshots/*.jpg'):
                img = cv2.imread(filename)
                height, width, layers = img.shape
                size = (width, height)
                img_array.append(img)
            out = cv2.VideoWriter('project.avi', cv2.VideoWriter_fourcc(*'DIVX'), 24, size)
            for i in range(len(img_array)):
                out.write(img_array[i])
            out.release()
            shutil.rmtree('screenshots')
            exit()
        except:
            exit()

    def take_screenshot(self):
        """Take screen shot and store to a directory"""
        if not os.path.isdir("screenshot"):
            os.mkdir("screenshot")
        filename = "screenshot/" + str(time.time()) + ".jpg"
        screenshot(filename)
        img = cv2.imread(filename)
        cv2.imshow("Screenshot", img)
        cv2.waitKey(0)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())
Machine Learning from Scratch
View All
install anaconda Ubuntu 20.04 & windows 11

How To Install the Anaconda Python on Windows 11 & Ubuntu 20.04 Linux

Setting up software requirements (environment) is the first and the most important step in getting started with Machine Learning. It takes a lot of effort to get all of those …

ML projects on Heroku with Flask

DEPLOYING ML PROJECT ON HEROKU WITH FLASK

Diabetes Prediction Using K-Means

k-modes clustering
SVM from scratch python

Support Vector Machine – SVM From Scratch Python

About Diwas Pandey

Highly motivated, strong drive with excellent interpersonal, communication, and team-building skills. Motivated to learn, grow and excel in Data Science, Artificial Intelligence, SEO & Digital Marketing

View all posts by Diwas Pandey →

33 Comments on “CREATE YOUR OWN SCREEN RECORDER – PYTHON PROJECT”

  1. It’s in reality a great and helpful piece of information. I’m glad that you just shared this helpful info with us. Please stay us up to date like this. Thank you for sharing.

  2. I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You have made my day! Thx again

  3. Hmm is anyone else experiencing problems with the images on this blog loading? I’m trying to find out if its a problem on my end or if it’s the blog. Any feedback would be greatly appreciated.

  4. As I web-site possessor I believe the content matter here is rattling excellent , appreciate it for your hard work. You should keep it up forever! Good Luck.

  5. I was wondering if you ever thought of changing the layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 pictures. Maybe you could space it out better?

  6. too many libraries that i’m not familiar even not seen, if you left the comment at every step ,it would be much more helpful

  7. Hmm is anyone else encountering problems with the pictures on this blog loading? I’m trying to determine if its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.

  8. I have been surfing online more than 3 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the net will be much more useful than ever before.

Leave a Reply

Your email address will not be published.