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
Mastering Image Classification with SIFT and KNN on CIFAR-10

Mastering Image Classification with SIFT and KNN on CIFAR-10

“CIFAR-10, a renowned benchmark dataset in the field of computer vision, presents a diverse set of challenges for image classification. SIFT and KNN on CIFAR-10

About Diwas

🚀 I'm Diwas Pandey, a Computer Engineer with an unyielding passion for Artificial Intelligence, currently pursuing a Master's in Computer Science at Washington State University, USA. As a dedicated blogger at AIHUBPROJECTS.COM, I share insights into the cutting-edge developments in AI, and as a Freelancer, I leverage my technical expertise to craft innovative solutions. Join me in bridging the gap between technology and healthcare as we shape a brighter future together! 🌍🤖🔬

View all posts by Diwas →

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. Required fields are marked *