Streamlit-WebRTC
Build a complete real-time audio and video web app. Using only Python.
Add live camera and microphone input to a Streamlit app, process it in Python, and return video, audio, text, or other results. Everything lives in one Python script, with no frontend code. Streamlit-WebRTC supplies the browser component and handles WebRTC transport.
A live video filter in one callback
import av
import cv2
import streamlit as st
from streamlit_webrtc import webrtc_streamer
effect = st.selectbox(
"Effect", ["Edges", "Mirror"]
)
def process(frame: av.VideoFrame):
image = frame.to_ndarray(format="bgr24")
if effect == "Edges":
image = cv2.Canny(image, 100, 200)
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
else:
image = cv2.flip(image, 1)
return av.VideoFrame.from_ndarray(
image, format="bgr24"
)
webrtc_streamer(
key="demo", video_frame_callback=process
)How Python reaches the browser in real time
Turn Python models into user-facing apps without adding a second language
or implementing WebRTC.
- 1Camera + micThe browser captures media with permission.
- 2WebRTC transportAudio and video travel as real-time tracks.
- 3Python callbackInspect, transform, recognize, mix, or generate.
- 4Returned outputThe processed track appears in the Streamlit app.
One callback is only the beginning
Loop back
Return the incoming track unchanged.
App: camera and microphone diagnostics
return frameFilter or recognize
Run OpenCV, MediaPipe, transcription, or your own model.
App: object detection or live captions
video_frame_callback=processReplace the source
Send generated or prerecorded media instead of device input.
App: generated presenter or scheduled playback
create_video_source_track(…)Route peers
Deliver Client A’s input to Client B and return B to A.
App: one-to-one video chat
source_video_track=peer_trackMix streams
Combine participants into one shared audio or video output.
App: group call or monitoring wall
create_mix_track(…)Compose independently
Process audio and video with separate callbacks and paths.
App: translated call with separate media effects
audio_frame_callback=listenApplications built with live media in Python
Live transcription
Stream microphone audio into Python and update a transcript as speech arrives.
Remote inspection
Run a camera feed through a server-side vision pipeline while an operator watches.
Interactive media generation
Publish Python-generated audio or video as a live track inside the Streamlit app.