Webcam-Livestream goes black after some minutes (randomly without any Error)

Hi,
I have an external USB webcam (“EVOCAM II” from VisionEng. Video output is directshow) for a livestream with overlays that changes when hitting a keybutton.

Problem:
My livestream goes black after a few minutes (without performing any action). Once it is black it stays black without an error message.
I first thought it had something to do with inactivity but sometimes it goes black after 2 minutes or even after 15 minutes. I even replaced the camera and USB cable and the problem still occurs

Anyone have any idea what the problem is or how I can get the picture back without stopping the livestream? Is there something like a query (if black then do…)

# Start Button Action    
def pushbutton_left_Callback(self):        
    # Initialization
    ...
    self.cap = cv2.VideoCapture(1,cv2.CAP_DSHOW)
    ...
def cap_img(self, cap):
    ret, img = cap.read()
    if not ret:
        print("No Frame. Livestream close")
        return None

    img = cv2.flip(img,1)#flip cam
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    height, width, channel = img.shape
    step = channel * width        
    
    img = QImage(img.data, width, height, step, QImage.Format_RGB888)  

    if height != HEIGHT and width != WIDTH:
        img = img.scaled(WIDTH, HEIGHT)
    
    return img
def snap_img(self, cap):
    ret, img = cap.read()
    if not ret:
        print("No Frame. Livestream close")
        return None

    img = cv2.flip(img,1)#flip cam
    self.snap_cv = img.copy()        

    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    height, width, channel = img.shape
    step = channel * width        
        
    self.snap = QImage(img.data, width, height, step, QImage.Format_RGB888)
    if height != HEIGHT and width != WIDTH:
        self.snap = self.snap.scaled(WIDTH, HEIGHT)

does the camera feed eventually go blank if you simply monitor it with VLC, OBS Studio, or the windows built-in camera app?

can you prepare a MRE that does not rely on Qt?

I need Qt for a GUI. The code is too large because of many things happen in background (not part of Livestream…)
When I use the build in windows app there is no black screen problem! IS there a way to restart the stream?

For restarting the stream, the first thing to try is obviously to detect the situation in code, reopen VideoCapture, and hope that it will restart the camera.

1 Like

ok but i need to check when its black. So just taking a snapshot every time to check if its black or is there a other way?

MRE is required. we can’t debug your entire application. that is your job. if you want help, you need to prepare a MRE that boils the issue down to its essentials.

if you can’t pin down the bug, you can’t fix it. then you’ll be left with kludges, workarounds.

Since the problem persists, it might be worth looking into your software settings or checking for any updates. You could also consider reaching out to the manufacturer for support or seeking advice from online forums or communities specializing in livestreaming setups.

Also, if you haven’t already, it might be helpful to test your webcam using https://webcammictest.io/ to ensure it’s functioning correctly.