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.38k stars 184 forks source link

Webcam Stream not showing up #1254

Closed Martlgap closed 1 year ago

Martlgap commented 1 year ago

First of all, thank you very much for your really great work and contribution!!!

I currently need help accessing some of your demos and running my own App on the Streamlit Cloud.

When accessing the demos and starting the webcam (after granting access) it looks like this :

image

or

image

I have written a short sample app:

import streamlit as st
from streamlit_webrtc import webrtc_streamer, WebRtcMode

# Streamlit app
st.title("DEMO APP")

# Instantiate WebRTC (and show start button)
ctx = webrtc_streamer(
    key="FaceIDAppDemo",
    mode=WebRtcMode.SENDONLY,
    media_stream_constraints={"video": True, "audio": False},
    rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
    video_receiver_size=1,
    async_processing=True,
)

# Live Stream Display
image_loc = st.empty()

if ctx.video_receiver:
    while True:
        try:
            frame = ctx.video_receiver.get_frame(timeout=1)
            img = frame.to_ndarray(format="rgb24")
        except:
            continue

        # Display Live Frame
        image_loc.image(img)

, which is running fine locally. But on Streamlit Cloud, after I press start, it seems to get a connection to the webcam (the text turns to "Stop", but after a few seconds the text turns back to "Start". In the logs, my app got stuck at "Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False."

Do you have any suggestions, on what I could have done wrong here? Or where the error is?

Thank you, Cheers, Martlgap

Martlgap commented 1 year ago

Found the error:

In https://github.com/whitphx/streamlit-webrtc/blob/64885865cf076bd78a0ed8f0af99426f71402276/sample_utils/turn.py

is written:

""" Use Twilio's TURN server because Streamlit Community Cloud has changed its infrastructure and WebRTC connection cannot be established without TURN server now. """

So I guess the former solution with a free STUN server from google is not working anymore.

Using a twilio TURN server, my app is working now.

takan1 commented 5 months ago

@Martlgap Same issue for me. Could you provide me with the twilio TURN server code part?