thinh-huynh-re commited on
Commit
a30caf2
·
1 Parent(s): 8b7ed91

Turn server

Browse files
Files changed (2) hide show
  1. INSTALLATION.md +4 -0
  2. app.py +30 -17
INSTALLATION.md CHANGED
@@ -8,3 +8,7 @@
8
  ## Ubuntu requirements
9
 
10
  - `sudo apt-get install python3.10-dev build-essential ffmpeg`
 
 
 
 
 
8
  ## Ubuntu requirements
9
 
10
  - `sudo apt-get install python3.10-dev build-essential ffmpeg`
11
+
12
+ ## Setup Turn Server
13
+
14
+ - Use [Turn Server](https://www.expressturn.com)
app.py CHANGED
@@ -10,6 +10,7 @@ import threading
10
 
11
  lock = threading.Lock()
12
 
 
13
  class FrameRate:
14
  def __init__(self) -> None:
15
  self.c: int = 0
@@ -33,31 +34,42 @@ class FrameRate:
33
  def show_fps(self, image: np.ndarray) -> np.ndarray:
34
  if self.fps != -1:
35
  return cv2.putText(
36
- image,
37
- f'FPS {self.fps:.0f}',
38
- (50, 50),
39
- cv2.FONT_HERSHEY_SIMPLEX,
40
- fontScale=1,
41
- color=(255, 0, 0),
42
- thickness=2
43
  )
44
  else:
45
  return image
46
 
47
 
48
  rtc_configuration = {
49
- "iceServers": [{"urls": [
50
- "stun:stun1.l.google.com:19302",
51
- "stun:stun2.l.google.com:19302",
52
- "stun:stun3.l.google.com:19302",
53
- "stun:stun4.l.google.com:19302",
54
- ]}],
 
 
 
 
 
 
 
 
 
55
  }
56
 
 
57
  class ImgContainer:
58
- img: np.ndarray = None # raw image
59
  frame_rate: FrameRate = FrameRate()
60
 
 
61
  def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
62
  img = frame.to_ndarray(format="bgr24")
63
  with lock:
@@ -66,10 +78,11 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
66
  img = img_container.frame_rate.show_fps(img)
67
  return av.VideoFrame.from_ndarray(img, format="bgr24")
68
 
 
69
  img_container = ImgContainer()
70
  img_container.frame_rate.reset()
71
  ctx = st.session_state.ctx = webrtc_streamer(
72
- key="snapshot",
73
  video_frame_callback=video_frame_callback,
74
- rtc_configuration=rtc_configuration
75
- )
 
10
 
11
  lock = threading.Lock()
12
 
13
+
14
  class FrameRate:
15
  def __init__(self) -> None:
16
  self.c: int = 0
 
34
  def show_fps(self, image: np.ndarray) -> np.ndarray:
35
  if self.fps != -1:
36
  return cv2.putText(
37
+ image,
38
+ f"FPS {self.fps:.0f}",
39
+ (50, 50),
40
+ cv2.FONT_HERSHEY_SIMPLEX,
41
+ fontScale=1,
42
+ color=(255, 0, 0),
43
+ thickness=2,
44
  )
45
  else:
46
  return image
47
 
48
 
49
  rtc_configuration = {
50
+ "iceServers": [
51
+ {
52
+ "urls": "turn:relay1.expressturn.com:3478",
53
+ "username": "efBRTY571ATWBRMP36",
54
+ "credential": "pGcX1BPH5fMmZJc5",
55
+ },
56
+ # {
57
+ # "urls": [
58
+ # "stun:stun1.l.google.com:19302",
59
+ # "stun:stun2.l.google.com:19302",
60
+ # "stun:stun3.l.google.com:19302",
61
+ # "stun:stun4.l.google.com:19302",
62
+ # ]
63
+ # },
64
+ ],
65
  }
66
 
67
+
68
  class ImgContainer:
69
+ img: np.ndarray = None # raw image
70
  frame_rate: FrameRate = FrameRate()
71
 
72
+
73
  def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
74
  img = frame.to_ndarray(format="bgr24")
75
  with lock:
 
78
  img = img_container.frame_rate.show_fps(img)
79
  return av.VideoFrame.from_ndarray(img, format="bgr24")
80
 
81
+
82
  img_container = ImgContainer()
83
  img_container.frame_rate.reset()
84
  ctx = st.session_state.ctx = webrtc_streamer(
85
+ key="snapshot",
86
  video_frame_callback=video_frame_callback,
87
+ rtc_configuration=rtc_configuration,
88
+ )