-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_detect.py
53 lines (46 loc) · 1.55 KB
/
multi_detect.py
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
import threading
import subprocess
def run_command(command):
"""
Execute a command in the shell.
"""
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Error executing command: {e}")
def main():
# read source streams
with open("source.streams","r") as f:
sources = f.readlines()
sources = [item.strip("\n") for item in sources]
# define list to store all threads
threads = []
# loop all source
for source in sources:
# command
try:
source = int(source)
command = f"python3 single_detect.py --camera {source}"
except:
if source.endswith('.mp4'):
command = f'python3 single_detect.py --video-file "{source}"'
elif source.startswith('rtsp'):
command = f'python3 single_detect.py --rtsp "{source}"'
elif source.startswith('http://www.youtube.com'):
command = f'python3 single_detect.py --youtube "{source}"'
elif source.rstrip() == '':
print('please prevent empty lines in source.streams')
continue
else:
raise NotImplementedError
# thread
thread = threading.Thread(target=run_command, args=(command,))
threads.append(thread)
# Start all threads
for thread in threads:
thread.start()
# Wait for all threads to finish
for thread in threads:
thread.join()
if __name__ == "__main__":
main()