> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/workflows/deploy/video-processing.md).

# Video processing with Workflows

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

<table data-search="false"><thead><tr><th>Runtime</th><th>API URL</th><th>Use it when</th></tr></thead><tbody><tr><td>Self-hosted Inference Server</td><td><code>http://localhost:9001</code></td><td>You want video to stay on your hardware or network.</td></tr><tr><td>Serverless Video Streaming API</td><td><code>https://serverless.roboflow.com</code></td><td>You want Roboflow to manage the compute.</td></tr></tbody></table>

For self-hosting, start the [Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server) before running the client. For hosted limits, regions, and GPU plans, see [Serverless Video Streaming](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api/serverless-video-streaming-api).

## Install the SDK

```bash
pip install "inference-sdk[webrtc]"
```

## Stream a Workflow

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

```python
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](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#stream-a-workflow) for a complete example.

## Choose a video source

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

<table data-search="false"><thead><tr><th>Source</th><th>Use it when</th></tr></thead><tbody><tr><td><code>WebcamSource()</code></td><td>The camera is connected to the client machine.</td></tr><tr><td><code>RTSPSource("rtsp://...")</code></td><td>The Inference Server can reach the RTSP camera.</td></tr><tr><td><code>LocalStreamSource("rtsp://...")</code></td><td>Only the client can reach the RTSP or RTMP stream.</td></tr><tr><td><code>VideoFileSource("video.mp4")</code></td><td>You want to process a stored video file.</td></tr><tr><td><code>ManualSource()</code></td><td>Your application provides individual frames.</td></tr></tbody></table>

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](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#video-sources) for source configuration and [consuming results](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#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`:

```python
session = client.webrtc.stream(
    source=WebcamSource(),
    model_id="rfdetr-nano",
)
```

See [Stream a model](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#stream-a-model) for prediction handling by task type.

## Next steps

* Configure frame and data outputs in the [WebRTC Streaming reference](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc).
* Start and configure a [self-hosted Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server).
* Review hosted regions, plans, and limits in [Serverless Video Streaming](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api/serverless-video-streaming-api).
