Skip to content

Issue with Black Screen on First Launch of Stream #326

@rybakov-ks

Description

@rybakov-ks

When using FastRTC and YOLO to process video from an ESP32 camera, the following behavior occurs:

  1. On first launch of the application:
  • A black screen is displayed instead of the video stream
  • A few frames briefly appear before the stream freezes
  • The stream seems to stop, leaving only a black screen
  1. On subsequent launches or page refresh:
    Everything works correctly, video stream displays normally
fastrtc.mp4
import gradio as gr
from fastrtc import Stream
import cv2
from ultralytics import YOLO

model = YOLO("yolo12x.pt")

def process_frame(frame):
    results = model.track(frame, persist=True, conf=0.4)
    if results and results[0].boxes.id is not None:
        return results[0].plot() 
    return frame
    
def generation():
    cap = cv2.VideoCapture("http://192.168.0.100:81/stream")
    while True:
        success, frame = cap.read()
        if not success: break
        processed = process_frame(frame)
        yield processed 
        
with gr.Blocks() as app:
    output = Stream(
                    handler=generation,
                    mode="receive",
                    modality="video"
                    )
                    
if __name__ == '__main__':
    app.launch()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions