Videos

Learn how to run real-time inference on video streams using predict_stream. This page covers video files, webcams, and RTSP sources—all with minimal setup.

Estimated read time: 2 minutes

The easiest way to run video inference is with degirum_tools.predict_stream.

predict_stream is a convenience wrapper around predict_batch. It opens the video source (file, webcam, or RTSP), reads frames, runs inference, and yields overlay frames (NumPy BGR) you can display or save.

Common setup (used in all cases)

import degirum_tools
from degirum_tools import ModelSpec, Display, remote_assets

# Configure & load once
model_spec = ModelSpec(
    model_name="yolov8n_coco--640x640_quant_axelera_metis_1",
    zoo_url="degirum/axelera",
    inference_host_address="@local",
    model_properties={"device_type": ["AXELERA/METIS"]},
)
model = model_spec.load_model()

Video file

video_source = "path/to/video.mp4"  # or use a built-in sample:
# video_source = remote_assets.traffic

with Display("AI Camera — File") as disp:
    for result in degirum_tools.predict_stream(model, video_source):
        disp.show(result.image_overlay)

Webcam

video_source = 0  # 0=default webcam; use 1,2,... for additional cameras

with Display("AI Camera — Webcam") as disp:
    for result in degirum_tools.predict_stream(model, video_source):
        disp.show(result.image_overlay)

RTSP stream

video_source = "rtsp://user:[email protected]:554/stream1"

with Display("AI Camera — RTSP") as disp:
    for result in degirum_tools.predict_stream(model, video_source):
        disp.show(result.image_overlay)
  • Under the hood: predict_stream uses predict_batch—you don’t need to manage capture loops or cleanup.

  • Colorspace: Frames are returned in OpenCV BGR; no conversion needed.

  • Performance: For real-time results, use lighter models or lower input sizes. Choose the right device_type for your hardware.

  • Custom pipelines: Need buffering, retries, or other custom logic? Build your own frame iterator and pass it to model.predict_batch(...) instead of using predict_stream.

Last updated

Was this helpful?