For the complete documentation index, see llms.txt. This page is also available as Markdown.

Video processing with Workflows

Stream webcams, camera feeds, and video files through a Workflow with the Inference SDK WebRTC client.

Use the Inference SDK WebRTC client to stream video through a Workflow. The same client works with a self-hosted Inference Server and the Serverless Video Streaming API.

WebRTC keeps one session open while the Workflow processes frames. This supports stateful blocks such as trackers, counters, and buffers. It also avoids sending each frame as a separate HTTP request.

Choose a runtime

Runtime
API URL
Use it when

Self-hosted Inference Server

http://localhost:9001

You want video to stay on your hardware or network.

Serverless Video Streaming API

https://serverless.roboflow.com

You want Roboflow to manage the compute.

For self-hosting, start the Inference Server before running the client. For hosted limits, regions, and GPU plans, see Serverless Video Streaming.

Install the SDK

pip install "inference-sdk[webrtc]"

Stream a Workflow

This example captures video from a webcam and prints the predictions output from a saved Workflow:

from inference_sdk import InferenceHTTPClient
from inference_sdk.webrtc import StreamConfig, WebcamSource

client = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY",
)

session = client.webrtc.stream(
    source=WebcamSource(),
    workflow="workflow-id",
    workspace="workspace-name",
    config=StreamConfig(data_output=["predictions"]),
)

@session.on_data("predictions")
def handle_predictions(predictions, metadata):
    print(f"Frame {metadata.frame_id}: {predictions}")

session.run()

Replace workflow-id, workspace-name, and ROBOFLOW_API_KEY with your values. To run on Serverless, change api_url to https://serverless.roboflow.com.

The names in data_output must match outputs defined by your Workflow. To receive an image output as video, add it to stream_output and register an on_frame handler. See the WebRTC Streaming reference for a complete example.

Choose a video source

Change the source passed to client.webrtc.stream() based on where the video comes from:

Source
Use it when

WebcamSource()

The camera is connected to the client machine.

RTSPSource("rtsp://...")

The Inference Server can reach the RTSP camera.

LocalStreamSource("rtsp://...")

Only the client can reach the RTSP or RTMP stream.

VideoFileSource("video.mp4")

You want to process a stored video file.

ManualSource()

Your application provides individual frames.

When you use RTSPSource with Serverless, the camera URL must be reachable from the public internet. Use LocalStreamSource when the camera is available only on the client's network.

See WebRTC video sources for source configuration and consuming results for callbacks, iterators, and session cleanup.

Stream one model

You do not need to build a Workflow when you only need one model. Pass model_id instead of workflow and workspace:

See Stream a model for prediction handling by task type.

Next steps

Last updated

Was this helpful?