Spaces:
Runtime error
Runtime error
File size: 1,323 Bytes
b47bdbb 68f1278 b47bdbb 68f1278 b47bdbb 68f1278 b47bdbb 68f1278 b47bdbb |
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 |
from streamlit_webrtc import webrtc_streamer
import numpy as np
import streamlit as st
import numpy as np
import av
import threading
from utils.frame_rate import FrameRate
lock = threading.Lock()
rtc_configuration = {
"iceServers": [
{
"urls": "turn:relay1.expressturn.com:3478",
"username": "efBRTY571ATWBRMP36",
"credential": "pGcX1BPH5fMmZJc5",
},
# {
# "urls": [
# "stun:stun1.l.google.com:19302",
# "stun:stun2.l.google.com:19302",
# "stun:stun3.l.google.com:19302",
# "stun:stun4.l.google.com:19302",
# ]
# },
],
}
class ImgContainer:
img: np.ndarray = None # raw image
frame_rate: FrameRate = FrameRate()
def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
img = frame.to_ndarray(format="bgr24")
with lock:
img_container.img = img
img_container.frame_rate.count()
img = img_container.frame_rate.show_fps(img)
return av.VideoFrame.from_ndarray(img, format="bgr24")
img_container = ImgContainer()
img_container.frame_rate.reset()
ctx = st.session_state.ctx = webrtc_streamer(
key="snapshot",
video_frame_callback=video_frame_callback,
rtc_configuration=rtc_configuration,
)
|