-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·171 lines (137 loc) · 5.88 KB
/
app.py
File metadata and controls
executable file
·171 lines (137 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Screen recording app
# This is a simple which let you record screen and save
# In this project we are using opencv, numpy, pyautogui and time module.
# Author Details
# Name : Er. Amar kumar
# Email : amarkumar9685079691@gmail.com
# Start of a source code
import numpy as np
import pyautogui as pt
from tkinter import *
import datetime
import time
import threading
import cv2
class ScreenRecorder:
_screen_width = None
_screen_height = None
_hours = 0
_minutes = 0
_seconds = 0
_videoObj = None
_fps = 20
_filename = None
_recording = False
_window = None
_frame = None
_label = None
_time_label = None
_target = 'screen'
_TimeCounter_Label = None
_frame_message = None
_record_button_start = None
_record_button_stop = None
def __init__(self):
self._screen_width, self._screen_height = pt.size()
self._fps = 20
self._window = Tk()
self._window.title("Screen Recorder APP")
self._window.geometry("600x400") # Adjusted window size for better layout
self._window.resizable(width=False, height=False)
self._window.configure(bg='#0288d1') # Green background for a fresh look
# Frame for the main content
self._frame = Frame(self._window, bg='#0288d1', bd=10, relief=RAISED)
self._frame.pack(padx=20, pady=20, fill=BOTH, expand=True)
# Add padding for the main content inside the frame
self._frame.grid_propagate(False)
def _getDisplayTime(self):
if self._recording:
if self._seconds == 60:
self._minutes += 1
self._seconds = 0
if self._minutes == 60:
self._hours += 1
self._minutes = 0
self._TimeCounter_Label.config(text=f'Recording Duration: {self._hours:02}:{self._minutes:02}:{self._seconds:02}')
self._seconds += 1
self._TimeCounter_Label.after(1000, self._getDisplayTime)
def _resetDisplayTime(self):
self._hours = 0
self._minutes = 0
self._seconds = 0
def _startRecording(self):
self._recording = True
self._resetDisplayTime()
Button_Rec_thread = threading.Thread(target=self._recordingProcess)
Thread_Counter = threading.Thread(target=self._getDisplayTime)
Thread_Screen = threading.Thread(target=self._recordScreen)
if self._recording:
Button_Rec_thread.start()
Thread_Counter.start()
if self._target == 'screen':
Thread_Screen.start()
def _stopRecording(self):
self._recording = False
self._clearObjects()
exit(0)
def _recordingProcess(self):
if self._recording:
self._record_button_start['state'] = DISABLED
self._label['text'] = 'Press q to quit and save recording'
self._record_button_stop['state'] = NORMAL
else:
self._record_button_start['state'] = NORMAL
def _clearObjects(self):
self._videoObj.release()
cv2.destroyAllWindows()
def _recordScreen(self):
current_time = datetime.datetime.now().strftime("%H%M%S")
file_format = 'avi'
self._filename = f'recording_{current_time}.{file_format}'
prev_time = time.time()
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
self._videoObj = cv2.VideoWriter(self._filename, fourcc, self._fps, (self._screen_width, self._screen_height))
print("Recording Started......")
print("Please type q or ctrl + c to stop recording!")
try:
while self._recording:
image = pt.screenshot()
rec_frame = np.array(image)
rec_frame = cv2.cvtColor(rec_frame, cv2.COLOR_RGB2BGR)
self._videoObj.write(rec_frame)
cv2.imshow('screen recording', rec_frame)
current_time = time.time()
if current_time - prev_time < 1.0 / self._fps:
continue
prev_time = current_time
if cv2.waitKey(1) & 0xFF == ord("q"):
self._recording = False
break
except Exception as e:
print(f"Program exit: Error code {e}")
except KeyboardInterrupt:
self._clearObjects()
finally:
self._clearObjects()
def startup(self):
# Time counter label
self._TimeCounter_Label = Label(self._frame, text=f'Record Duration: {self._hours:02}:{self._minutes:02}:{self._seconds:02}', font=('Arial', 20, 'bold'), bg="#303F9F", fg="white", width=32)
self._TimeCounter_Label.grid(row=0, column=0, padx=20, pady=20)
# Record button style
self._record_button_start = Button(self._frame, text="Start Recording", command=self._startRecording, font=('Arial', 16, 'bold'), bg="#FF9800", fg="white", activebackground="#E65100", relief=RAISED, width=20, height=2)
self._record_button_start.grid(row=1, column=0, padx=10, pady=10)
# Stop button style
self._record_button_stop = Button(self._frame, text="Stop Recording", command=self._stopRecording, font=('Arial', 16, 'bold'), bg="#FF9800", fg="white", activebackground="#E65100", relief=RAISED, width=20, height=2)
self._record_button_stop.grid(row=2, column=0, padx=10, pady=10)
# Initially disable the stop button
self._record_button_stop['state'] = DISABLED
# Frame for message
self._frame_message = Frame(self._window, bg="#0288d1")
self._frame_message.pack(fill=X)
# Message label with updated style
self._label = Label(self._frame_message, text="Lets Record Your screen. Developed By Er. Amar kumar", font=('Arial', 14, 'italic'), bg="#0288d1", fg="white")
self._label.pack(padx=20, pady=10)
self._window.mainloop()
if __name__ == '__main__':
app = ScreenRecorder()
app.startup()