Streamlit Camera Input Live
Streamlit Camera Input Live is an alternative version of Streamlit's built-in `st.camera_input` component. Unlike the standard version, it returns webcam images live without requiring a button press, making it suitable for real-time preview applications. The current version is 0.2.0, with an infrequent release cadence, having last been updated in September 2022.
Common errors
-
Camera works extremely slow. Sometimes it doesn't work at all (it freezes).
cause The component's default update rate (`debounce=1000ms`) is set for simplicity. High network latency or browser issues can also contribute to freezing.fixIncrease the update frequency by setting the `debounce` parameter to a lower value, e.g., `camera_input_live(debounce=100)`. For very demanding real-time scenarios, `streamlit-webrtc` might be a better fit. -
How to switch to the back camera on mobile devices?
cause The `streamlit-camera-input-live` component currently does not offer a direct parameter to specify which camera (front or back) to use.fixThis feature is not available out-of-the-box. Developers needing this functionality may need to explore browser-specific camera selection APIs via custom Streamlit components or use more comprehensive real-time video libraries like `streamlit-webrtc` which might provide more control.
Warnings
- breaking Version 0.2.0 standardized argument casing, which may break older code relying on different case conventions for parameters. For example, `show_controls` might have been `showControls` in prior versions.
- gotcha This component prioritizes simplicity over raw performance and may be noticeably slower for high-frame-rate, real-time video processing compared to alternatives like `streamlit-webrtc`.
- gotcha The component does not natively support selecting the back camera on mobile devices, defaulting to the front camera.
Install
-
pip install streamlit-camera-input-live
Imports
- camera_input_live
from streamlit_camera_input_live import camera_input_live
Quickstart
import streamlit as st
from streamlit_camera_input_live import camera_input_live
st.set_page_config(layout="centered")
st.title("Streamlit Live Camera Input Demo")
st.write("### See a new image every second")
controls = st.checkbox("Show camera controls", value=True)
image = camera_input_live(show_controls=controls, key="my_camera_input")
if image is not None:
st.image(image, caption="Live Camera Feed", use_column_width=True)
st.success("Image received live!")
else:
st.info("Waiting for camera input...")