From 3e2117aa6af738074b761b51df1f0d0afe28a444 Mon Sep 17 00:00:00 2001 From: Srinjoy Pati Date: Thu, 6 Oct 2022 18:04:42 +0530 Subject: [PATCH] screen recorder --- scripts/Screen-recorder/README.md | 39 +++++++++++++++++++++++++++++++ scripts/Screen-recorder/main.py | 23 ++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 scripts/Screen-recorder/README.md create mode 100644 scripts/Screen-recorder/main.py diff --git a/scripts/Screen-recorder/README.md b/scripts/Screen-recorder/README.md new file mode 100644 index 0000000..2737677 --- /dev/null +++ b/scripts/Screen-recorder/README.md @@ -0,0 +1,39 @@ +# Screen-recorder + +## Introduction + +This project , records the screen , whatever you are doing and to stop recording you need to press 'Q'. It saves the video in mp4 format with the file name of date and time when it is being recorded. + +## Tech stack + +The project is made using python. + +## Demonstration video - here is a view of the project + + + +## Install dependencies + +- install Python 3.8.3 or above +- Further install these packages using terminal: + +```bash + pip install Pillow numpy opencv-contrib-python pywin32 +``` + +## Quick start (how to run locally) + +- Clone this repository: + +```bash +git clone https://github.com/metafy-social/daily-python-scripts.git +``` + +- Change directory: + +```bash +cd daily-python-scripts +cd Screen-recorder +``` + +- Find main.py and run it. diff --git a/scripts/Screen-recorder/main.py b/scripts/Screen-recorder/main.py new file mode 100644 index 0000000..1bcbcae --- /dev/null +++ b/scripts/Screen-recorder/main.py @@ -0,0 +1,23 @@ +import datetime + +import cv2 +from PIL import ImageGrab +import numpy as np +from win32api import GetSystemMetrics + +width = GetSystemMetrics(0) +height = GetSystemMetrics(1) + +time_stamp = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S') +file_name = f'{time_stamp}.mp4' +fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') +captured_video = cv2.VideoWriter(file_name, fourcc, 20.0, (width, height)) + +while True: + img = ImageGrab.grab(bbox=(0, 0, width, height)) + img_np = np.array(img) + img_final = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB) + cv2.imshow('Screen Recorder', img_final) + captured_video.write(img_final) + if cv2.waitKey(10) == ord('q'): + break