Error when using Streamlit with OpenCV


I have an issue with accessing the video stream. I get the error as
[ WARN:0@11.019] global cap_msmf.cpp:471 anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): OnReadSample() is called with error status: -1072875772 [ WARN:0@11.064] global cap_msmf.cpp:483 anonymous-namespace’::SourceReaderCB::OnReadSample videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
[ WARN:1@11.108] global cap_msmf.cpp:1759 CvCapture_MSMF::grabFrame videoio(MSMF): can’t grab frame. Error: -1072875772

My camera is working fine as well

Steps to reproduce

Code snippet:

import streamlit as st
import cv2

cap = cv2.VideoCapture(0)

while True:
    ret, frame =

    if not ret:

    st.image(frame, channels="BGR")

    if cv2.waitKey(1) & 0xFF == ord('q'):


If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:
The expected behavior is to create a Streamlit application that accesses the video stream from the default camera using OpenCV (cv2 ) and displays the video feed within the Streamlit app.

Explain what you expect to happen when you run the code above.

Actual behavior:
Nothing is displayed on the screen in streamlit app

Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.

Debug info

  • Streamlit version: (get it with $ streamlit version) 1.24.1
  • Python version: (get it with $ python --version) 3.10.5
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version: windows 11
  • Browser version:

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.


  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

Hey @Lakshmi_Shree_A,

Do you see this same error when you’re only using OpenCV (without Streamlit)?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.