From 07b453ea34fd5406dcaa61a6c24a026eee8d3b46 Mon Sep 17 00:00:00 2001 From: jindalpriyanshu101 Date: Fri, 17 May 2024 10:56:39 +0530 Subject: [PATCH 1/6] Added screen recorder --- .../Python/Screen_Recorder/README.md | 36 ++++++ .../Python/Screen_Recorder/recorder.py | 117 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 Desktop Application/Intermediate/Python/Screen_Recorder/README.md create mode 100644 Desktop Application/Intermediate/Python/Screen_Recorder/recorder.py diff --git a/Desktop Application/Intermediate/Python/Screen_Recorder/README.md b/Desktop Application/Intermediate/Python/Screen_Recorder/README.md new file mode 100644 index 000000000..f92dce7d7 --- /dev/null +++ b/Desktop Application/Intermediate/Python/Screen_Recorder/README.md @@ -0,0 +1,36 @@ +![](https://img.shields.io/badge/Programming_Language-Python-blue.svg) +![](https://img.shields.io/badge/Main_Tool_Used-OpenCV-gold.svg) +![](https://img.shields.io/badge/Supporting_Tools_Used-Pillow,_CustomTkinter-orange.svg) +![](https://img.shields.io/badge/Application-Screen_Recorder-yellow.svg) +![](https://img.shields.io/badge/Minimum_Python_Version-3.7-blue.svg) +![](https://img.shields.io/badge/Status-Complete-darklime.svg) + + + +### Python Screen Recorder with GUI + +This project demonstrates how to create a screen recording application using Python. The application features a graphical user interface (GUI) built with `customtkinter`, which allows users to start and stop screen recordings easily. The recorded video is saved in the specified format, making this tool useful for creating tutorials, capturing gameplay, or recording presentations. + +### Key Features: +1. **User-Friendly Interface**: The GUI provides an intuitive way for users to input the output file name and specify a custom key to stop the recording. +2. **Real-Time Screen Capture**: Utilizes the `Pillow` library for capturing screen frames and `cv2` (OpenCV) for video encoding. +3. **Threaded Recording**: Implements threading to ensure that the GUI remains responsive while the recording is in progress. +4. **Customizable Settings**: Users can specify the output file name and an optional custom key to stop recording, enhancing usability and flexibility. + +### Components: +- **Screen Capture**: Captures the screen content at a specified frame rate. +- **Video Encoding**: Encodes the captured frames into an MP4 video file. +- **GUI**: Built with `customtkinter` for an attractive and responsive user interface. +- **Concurrency**: Ensures smooth operation and responsiveness through threading. + +This project is suitable for those looking to enhance their Python skills by working on an intermediate-level project that integrates multiple libraries and concepts. + +--- + +### Example Usage: +1. **Enter File Name**: Specify the output file name in the provided entry box. +2. **Custom Stop Key**: Optionally, enter a custom key to stop the recording (defaults to 'q' if left empty). +3. **Start Recording**: Click the "Start Recording" button to begin capturing the screen. +4. **Stop Recording**: Use the specified key or the default 'q' to stop recording. The status label will update to indicate the recording has stopped. + +This project combines practical Python programming with useful real-world application, making it a valuable addition to any developer's portfolio. \ No newline at end of file diff --git a/Desktop Application/Intermediate/Python/Screen_Recorder/recorder.py b/Desktop Application/Intermediate/Python/Screen_Recorder/recorder.py new file mode 100644 index 000000000..d7ed0c0cf --- /dev/null +++ b/Desktop Application/Intermediate/Python/Screen_Recorder/recorder.py @@ -0,0 +1,117 @@ +import customtkinter as ctk +import numpy as np +import cv2 +from PIL import ImageGrab +from win32api import GetSystemMetrics +import threading +import time + +# Initialize customtkinter +ctk.set_appearance_mode("dark") +ctk.set_default_color_theme("blue") + +# Function to start screen recording +def start_recording(): + global recording, output, key + file_name = file_name_entry.get().strip() + + if not file_name: + status_label.configure(text="Please enter a valid file name.", text_color="red") + return + + key = custom_key_entry.get().strip() or 'q' # Default to 'q' if no key is entered + + # Video writer setup + screen_width = GetSystemMetrics(0) + screen_height = GetSystemMetrics(1) + resolution = (screen_width, screen_height) + fourcc = cv2.VideoWriter_fourcc(*'mp4v') + output = cv2.VideoWriter(file_name, fourcc, 20.0, resolution) # Adjusted frame rate to 20 FPS + + recording = True + record_button.configure(state=ctk.DISABLED) + stop_button.configure(state=ctk.NORMAL) + status_label.configure(text="Recording...", text_color="white") + + def record(): + prev_time = time.time() + while recording: + # Capture the screen + img = ImageGrab.grab(bbox=(0, 0, screen_width, screen_height)) + img_np = np.array(img) + img_final = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB) + + # Write the frame to the video file + output.write(img_final) + + # Show the recording window + cv2.imshow('RecorderX - Screen Recorder', img_final) + + # Wait for the stop key or 10 milliseconds + if cv2.waitKey(10) == ord(key): + break + + # Ensure the loop runs at the correct frame rate + time_elapsed = time.time() - prev_time + sleep_time = max(1./20. - time_elapsed, 0) # Adjusted for 20 FPS + time.sleep(sleep_time) + prev_time = time.time() + + cv2.destroyAllWindows() + output.release() + status_label.configure(text="Recording stopped", text_color="white") + record_button.configure(state=ctk.NORMAL) + stop_button.configure(state=ctk.DISABLED) + + threading.Thread(target=record).start() + +# Function to stop screen recording +def stop_recording(): + global recording + recording = False + +# Main application window +app = ctk.CTk() +app.title("Screen Recorder") +app.geometry("512x512") # Set window size to 512x512 pixels + +# Style configuration +padding = 10 +font_large = ("Helvetica", 16, "bold") +font_small = ("Helvetica", 12) +button_color = "#1f6aa5" +text_color = "#f0f0f0" + +# File name entry +file_name_label = ctk.CTkLabel(app, text="Output file name (with extension):", font=font_small, text_color=text_color) +file_name_label.pack(pady=padding) +file_name_entry = ctk.CTkEntry(app, width=300) +file_name_entry.pack(pady=padding) + +# Custom key entry +custom_key_label = ctk.CTkLabel(app, text="Custom stop key (optional, default is 'q'):", font=font_small, text_color=text_color) +custom_key_label.pack(pady=padding) +custom_key_entry = ctk.CTkEntry(app, width=300) +custom_key_entry.pack(pady=padding) + +# Start and Stop buttons +button_frame = ctk.CTkFrame(app) +button_frame.pack(pady=padding) + +record_button = ctk.CTkButton(button_frame, text="Start Recording", command=start_recording, fg_color=button_color, font=font_large) +record_button.grid(row=0, column=0, padx=padding) + +stop_button = ctk.CTkButton(button_frame, text="Stop Recording", command=stop_recording, state=ctk.DISABLED, fg_color=button_color, font=font_large) +stop_button.grid(row=0, column=1, padx=padding) + +# Status label +status_label = ctk.CTkLabel(app, text="Ready to record", font=font_small, text_color=text_color) +status_label.pack(pady=padding) + +# Initialize recording state and output variable +recording = False +output = None +key = 'q' + +# Run the application +app.mainloop() From 684150ed4cc0918acd2ee9622dc517da7607ef0d Mon Sep 17 00:00:00 2001 From: Priyanshu Jindal <52918255+jindalpriyanshu101@users.noreply.github.com> Date: Fri, 17 May 2024 11:04:30 +0530 Subject: [PATCH 2/6] Updated README.md --- .../Python/Screen_Recorder/README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Desktop Application/Intermediate/Python/Screen_Recorder/README.md b/Desktop Application/Intermediate/Python/Screen_Recorder/README.md index f92dce7d7..ec79dfa48 100644 --- a/Desktop Application/Intermediate/Python/Screen_Recorder/README.md +++ b/Desktop Application/Intermediate/Python/Screen_Recorder/README.md @@ -7,7 +7,7 @@ -### Python Screen Recorder with GUI +## Python Screen Recorder with GUI This project demonstrates how to create a screen recording application using Python. The application features a graphical user interface (GUI) built with `customtkinter`, which allows users to start and stop screen recordings easily. The recorded video is saved in the specified format, making this tool useful for creating tutorials, capturing gameplay, or recording presentations. @@ -29,8 +29,16 @@ This project is suitable for those looking to enhance their Python skills by wor ### Example Usage: 1. **Enter File Name**: Specify the output file name in the provided entry box. -2. **Custom Stop Key**: Optionally, enter a custom key to stop the recording (defaults to 'q' if left empty). -3. **Start Recording**: Click the "Start Recording" button to begin capturing the screen. -4. **Stop Recording**: Use the specified key or the default 'q' to stop recording. The status label will update to indicate the recording has stopped. + ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/cc8fca2f-53e3-4ccc-a806-d90339f75a4a) -This project combines practical Python programming with useful real-world application, making it a valuable addition to any developer's portfolio. \ No newline at end of file +2. **Custom Stop Key**: `Optionally`, enter a custom key to stop the recording (defaults to 'q' if left empty). + ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/bfef4f1f-7a68-4f53-af95-bc6564887e43) + +4. **Start Recording**: Click the "Start Recording" button to begin capturing the screen. + ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/5fb72a7b-db8f-4259-ba0f-33844d2cf49f) + +5. **Stop Recording**: Use the specified key or the default 'q' ON the output screen to stop recording `or` click on button provided. The status label will update to indicate the recording has stopped. + ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/8029d7f2-2fd5-4733-b60a-e03169db0953) + + +This project combines practical Python programming with useful real-world application, making it a valuable addition to any developer's portfolio. From 75f2e80f908eedcabccf3dd95e4e8408b851bfd4 Mon Sep 17 00:00:00 2001 From: jindalpriyanshu101 Date: Fri, 17 May 2024 11:05:54 +0530 Subject: [PATCH 3/6] added requirements.txt --- .../Intermediate/Python/Screen_Recorder/requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Desktop Application/Intermediate/Python/Screen_Recorder/requirements.txt diff --git a/Desktop Application/Intermediate/Python/Screen_Recorder/requirements.txt b/Desktop Application/Intermediate/Python/Screen_Recorder/requirements.txt new file mode 100644 index 000000000..3ccb3eef3 --- /dev/null +++ b/Desktop Application/Intermediate/Python/Screen_Recorder/requirements.txt @@ -0,0 +1,4 @@ +opencv-python +pillow +numpy +customtkinter \ No newline at end of file From de4cd8fc9afd6c088b2b6c459ee25e4946238bdb Mon Sep 17 00:00:00 2001 From: jindalpriyanshu101 Date: Wed, 22 May 2024 14:46:01 +0530 Subject: [PATCH 4/6] Updated directory --- .../{Intermediate => Basic}/Python/Screen_Recorder/README.md | 0 .../{Intermediate => Basic}/Python/Screen_Recorder/recorder.py | 0 .../Python/Screen_Recorder/requirements.txt | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Desktop Application/{Intermediate => Basic}/Python/Screen_Recorder/README.md (100%) rename Desktop Application/{Intermediate => Basic}/Python/Screen_Recorder/recorder.py (100%) rename Desktop Application/{Intermediate => Basic}/Python/Screen_Recorder/requirements.txt (100%) diff --git a/Desktop Application/Intermediate/Python/Screen_Recorder/README.md b/Desktop Application/Basic/Python/Screen_Recorder/README.md similarity index 100% rename from Desktop Application/Intermediate/Python/Screen_Recorder/README.md rename to Desktop Application/Basic/Python/Screen_Recorder/README.md diff --git a/Desktop Application/Intermediate/Python/Screen_Recorder/recorder.py b/Desktop Application/Basic/Python/Screen_Recorder/recorder.py similarity index 100% rename from Desktop Application/Intermediate/Python/Screen_Recorder/recorder.py rename to Desktop Application/Basic/Python/Screen_Recorder/recorder.py diff --git a/Desktop Application/Intermediate/Python/Screen_Recorder/requirements.txt b/Desktop Application/Basic/Python/Screen_Recorder/requirements.txt similarity index 100% rename from Desktop Application/Intermediate/Python/Screen_Recorder/requirements.txt rename to Desktop Application/Basic/Python/Screen_Recorder/requirements.txt From 4a87a683603b704694261c65752a77f567be525a Mon Sep 17 00:00:00 2001 From: jindalpriyanshu101 Date: Wed, 22 May 2024 14:46:10 +0530 Subject: [PATCH 5/6] Added project to list --- Desktop Application/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Desktop Application/README.md b/Desktop Application/README.md index 78e11872b..7a4be5963 100644 --- a/Desktop Application/README.md +++ b/Desktop Application/README.md @@ -70,6 +70,8 @@ | 26. | [Image Request](https://github.com/Kushal997-das/Project-Guidance/tree/main/Desktop%20Application/Basic/Python/Image%20Request) | | 27. | [Internet Speed Meter](https://github.com/Kushal997-das/Project-Guidance/tree/main/Desktop%20Application/Basic/Python/Internet%20Speed%20Meter) | | 28. | [Live News App](https://github.com/Kushal997-das/Project-Guidance/tree/main/Desktop%20Application/Basic/Python/Live%20News%20App) | +| 29. | [Screen Recorder](https://github.com/Kushal997-das/Project-Guidance/tree/main/Desktop%20Application/Basic/Python/Screen-Recorder) | +
## Java 🚀 From 3dd73b4b554c846040930388ac5ecad6770f3c22 Mon Sep 17 00:00:00 2001 From: Priyanshu Jindal <52918255+jindalpriyanshu101@users.noreply.github.com> Date: Wed, 22 May 2024 14:53:27 +0530 Subject: [PATCH 6/6] Updated README.md --- .../Basic/Python/Screen_Recorder/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Desktop Application/Basic/Python/Screen_Recorder/README.md b/Desktop Application/Basic/Python/Screen_Recorder/README.md index ec79dfa48..603dc11b0 100644 --- a/Desktop Application/Basic/Python/Screen_Recorder/README.md +++ b/Desktop Application/Basic/Python/Screen_Recorder/README.md @@ -29,16 +29,19 @@ This project is suitable for those looking to enhance their Python skills by wor ### Example Usage: 1. **Enter File Name**: Specify the output file name in the provided entry box. - ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/cc8fca2f-53e3-4ccc-a806-d90339f75a4a) + ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/b6da3508-078f-467b-b328-5242be6993a6) 2. **Custom Stop Key**: `Optionally`, enter a custom key to stop the recording (defaults to 'q' if left empty). - ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/bfef4f1f-7a68-4f53-af95-bc6564887e43) + ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/c5888912-77f3-48af-84fe-e9fbfc8adbf6) + 4. **Start Recording**: Click the "Start Recording" button to begin capturing the screen. - ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/5fb72a7b-db8f-4259-ba0f-33844d2cf49f) + ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/45b026b2-d2bb-4870-bd3d-17121980e2cf) + 5. **Stop Recording**: Use the specified key or the default 'q' ON the output screen to stop recording `or` click on button provided. The status label will update to indicate the recording has stopped. - ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/8029d7f2-2fd5-4733-b60a-e03169db0953) + ![image](https://github.com/jindalpriyanshu101/Project-Guidance/assets/52918255/2e28954b-62fd-4dae-8342-2badccd56114) + This project combines practical Python programming with useful real-world application, making it a valuable addition to any developer's portfolio.