-
Notifications
You must be signed in to change notification settings - Fork 18
/
multip_thread_rtsp.py
100 lines (84 loc) · 3.57 KB
/
multip_thread_rtsp.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
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
#!/usr/bin/env python3.6
import os
import time
import threading
import cv2
import numpy as np
import pyapi.gst_rtsp_client_api as rtspclient
from multiprocessing import Lock, Process, Condition, Queue
# def callback_frame(a,b):
# print("callback")
# pass
# functype = CFUNCTYPE(c_int,c_int)
# c_calback_python = functype(callback_frame)
# client.register_py_to_c(c_calback_python)
def func_rtspdisplay(index,url, usr, pwd):
width = 1920
height = 1080
resize_width = 0
resize_height = 0
rtspclient.createRtspClient(index,url)
time.sleep(0.5)
while(1) :
ret1 = rtspclient.isConnect(index)
print("id %d ret = %d",index, ret1)
# time.sleep(0.1)
if (ret1 == 1):
# print("id %d mread",index)
# status, img, img_resize = rtspclient.mread_rga(index,width,height,resize_width,resize_height)
status, img, img_resize = rtspclient.mread_opencv(index)
if status == 1:
print(type(img))
# print(img.shape)
# print("success %d, %d",index,ret1)
# time.sleep(1)
# cv2.imwrite('a' + str(index) +'.jpg',img)
pass
else:
print("python mread_rga disconnect")
del status, img, img_resize
# status, img, img_size = rtspclient.mread_opencv(index)
# if status == 1:
# img = cv2.UMat.get(img)
# # cv2.imwrite('a' + str(index) +'.jpg',img)
# else:
# print("python mread_opencv disconnect")
# del status, img, img_size
else:
time.sleep(3)
rtspclient.reConnect(index)
print("status %d, %d",index,ret1)
print('# End of Thread %d' % (index))
if __name__ == '__main__':
os.system('iptables -F') # Disable Firewall
#gl = toy.output.createGLDrmDisplay(toy.DisplayPort.HDMI_A)
#idx0 = gl.add_view(0, 180, 640, 360)
# idx1 = gl.add_view(640, 180, 640, 360)
# idx2 = gl.add_view(1280, 180, 640, 360)
# idx3 = gl.add_view(0, 540, 640, 360)
# idx4 = gl.add_view(640, 540, 640, 360)
# idx5 = gl.add_view(1280, 540, 640, 360)
t0 = threading.Thread(target=func_rtspdisplay, args = (1,"rtsp://admin:qwer1234@192.168.2.51:554/Streaming/Channels/1", "admin", "shangqu2020"))
t1 = threading.Thread(target=func_rtspdisplay, args = (2,"rtsp://admin:qwer1234@192.168.2.52:554/Streaming/Channels/1", "admin", "shangqu2020"))
t2 = threading.Thread(target=func_rtspdisplay, args = (3,"rtsp://admin:qwer1234@192.168.2.55:554/Streaming/Channels/1", "admin", "shangqu2020"))
t3 = threading.Thread(target=func_rtspdisplay, args = (4,'rtsp://admin:qwer1234@192.168.2.54:554/Streaming/Channels/1', "admin", "shangqu2020"))
t4 = threading.Thread(target=func_rtspdisplay, args = (5,"rtsp://admin:qwer1234@192.168.2.55:554/Streaming/Channels/1", "admin", "shangqu2020"))
t5 = threading.Thread(target=func_rtspdisplay, args = (6, "rtsp://admin:qwer1234@192.168.2.54:554/Streaming/Channels/1", "admin", "shangqu2020"))
t6 = threading.Thread(target=func_rtspdisplay, args = (7, "rtsp://admin:qwer1234@192.168.2.51:554/Streaming/Channels/1", "admin", "shangqu2020"))
t7 = threading.Thread(target=func_rtspdisplay, args = (8, "rtsp://admin:qwer1234@192.168.2.52:554/Streaming/Channels/1", "admin", "shangqu2020"))
t0.start()
t1.start()
t2.start()
t3.start()
t4.start()
t5.start()
t6.start()
t7.start()
t0.join()
t1.join()
t2.join()
t3.join()
t4.join()
t5.join()
t6.join()
t7.join()