whitphx / streamlit-webrtc

Real-time video and audio processing on Streamlit
https://discuss.streamlit.io/t/new-component-streamlit-webrtc-a-new-way-to-deal-with-real-time-media-streams/8669
MIT License
1.36k stars 182 forks source link

Sendrecv streamer serves only one request at a time on a remote server #131

Closed martinezpl closed 3 years ago

martinezpl commented 3 years ago

I have a streamer in sendrecv mode deployed on Google's App Engine. The issue I'm facing is that when a visitor starts the stream it kinda clogs the instance, and the consequence is that only one visitor at a time can use the streamer. What is the reason, and is there a work-around? Thank you.

Implementation

WEBRTC_CLIENT_SETTINGS = ClientSettings(
    rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
    media_stream_constraints={"video": True, "audio": False},
)
def app_mask_detection():

    class OpenCVVideoTransformer(VideoTransformerBase):
        def __init__(self) -> None:
            self.assembly = ModelAssembly()    

        def transform(self, frame: av.VideoFrame) -> av.VideoFrame:
            img = frame.to_ndarray(format="bgr24")

            return self.assembly.forwardFrame(img)

    webrtc_ctx = webrtc_streamer(
        key="opencv-filter",
        mode=WebRtcMode.SENDRECV,
        client_settings=WEBRTC_CLIENT_SETTINGS,
        video_transformer_factory=OpenCVVideoTransformer,
        async_transform=True,
    )
whitphx commented 3 years ago

https://discuss.streamlit.io/t/two-people-on-same-session-state/3211

whitphx commented 3 years ago

I reproduced this problem in my local environment and will try to investigate it.

whitphx commented 3 years ago

I think this problem is caused primarily by the streamlit-webrtc's bug fixed in #139 , however, perhaps there will still be the issue even after the fix is merged if you run the app behind reverse proxies as described in https://discuss.streamlit.io/t/two-people-on-same-session-state/3211, and GAE setup may be the case.

martinezpl commented 3 years ago

Thank you kindly! Looking forward to the merging.

whitphx commented 3 years ago

I released this fix in the next version, 0.9.0. Please check out it. https://pypi.org/project/streamlit-webrtc/