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 AllMastering 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
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.
I wanted to thanks to your time for this excellent learn!!
I’d without a doubt donate to this fantastic blog! Chat soon!
I’m not sure where you’re getting your information, but great topic.
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
A lot of thanks for all of the efforts on this site.
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.
I have been reading out a few of your posts and i can claim clever stuff. I will surely bookmark your website.
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.
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?
I am not sure where you are getting your info, but great topic.
I needs to spend some time learning more or understanding more.
Thanks for wonderful info I was looking for this info for my mission. adreamoftrains web hosting reviews
Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.
can i use tkinter to create this screen recorder ?
yeah you can
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
which libraries you haven’t been used to before?
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.
we will take a look at it sir. Thank you so much
edit : Now the problem is solved. Please take a look
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.
giveaways