File size: 1,052 Bytes
09ef9a4
a2c3c48
 
4485e0a
 
93cb276
4485e0a
 
 
 
 
 
 
 
 
 
 
a2c3c48
4485e0a
a2c3c48
4485e0a
 
a2c3c48
 
 
 
 
 
 
 
4485e0a
 
a2c3c48
 
 
 
4485e0a
a2c3c48
 
09ef9a4
 
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
import streamlit as st
from streamlit_webrtc import webrtc_streamer
import av
import os
from twilio.rest import Client

os.environ["TWILIO_ACCOUNT_SID"] = 223e5388402c66735407ff8d
os.environ["TWILIO_AUTH_TOKEN"] = eb4673a2020af7d412359956fd1a2e2de594


def get_ice_servers()
    try:
        account_sid = os.environ["TWILIO_ACCOUNT_SID"]
        auth_token = os.environ["TWILIO_AUTH_TOKEN"]
    except KeyError:
        logger.warning("TURN credentials are not set. Fallback to a free STUN server from Google.")
        return [{"urls": ["stun:stun.l.google.com:19302"]}]

    client = Client(account_sid, auth_token)

    token = client.tokens.create()
    
def video_frame_callback(frame):
    img = frame.to_ndarray(format="bgr24")

    flipped = img[::-1,:,:] if flip else img

    return av.VideoFrame.from_ndarray(flipped, format="bgr24")


flip = st.checkbox("Flip")

webrtc_streamer(
    key="example",
    video_frame_callback=video_frame_callback,
    rtc_configuration={  # Add this config
        "iceServers": get_ice_servers()
    }
)