How to run a computer vision model on video
Run RF-DETR on a video file in Python, process recorded videos in bulk with Batch Processing, or run a model on a live camera with Cloud Streaming.
Overview
A video is a sequence of images, so running a computer vision model on video means running it on every frame and keeping the results in order. With Roboflow there are three ways to do it, depending on where the video is:
- A video file on your machine: run RF-DETR (opens in a new tab) in Python.
- Many recorded videos: Batch Processing (opens in a new tab) runs a model on all of them in Roboflow's cloud, with no code.
- A live camera: Cloud Streaming runs a model on the stream on Roboflow-managed GPUs.
The two cloud paths run a Workflow, so they work with RF-DETR, a model you trained in Roboflow, or a public model from Roboflow Universe (opens in a new tab). You can also ask a coding agent to do any of the three through the Roboflow MCP server.
Run RF-DETR on a video file in Python
RF-DETR is Roboflow's open source real-time model for object detection and segmentation. Its Nano, Small, Medium and Large checkpoints are licensed under Apache 2.0, so you can use them in commercial products. Install the package with its video extras:
pip install "rfdetr[stream]"RFDETRInference wraps a model so predict() accepts a video and yields one sv.Detections per frame. This script draws each frame's detections and writes an annotated copy of the video:
import supervision as sv
from rfdetr import RFDETRInference, RFDETRSmall
SOURCE = "video.mp4"
TARGET = "video-annotated.mp4"
predictor = RFDETRInference(RFDETRSmall())
box_annotator = sv.BoxAnnotator()
label_annotator = sv.LabelAnnotator()
results = predictor.predict(SOURCE, threshold=0.5, stream=True)
frames = sv.get_video_frames_generator(SOURCE)
video_info = sv.VideoInfo.from_video_path(SOURCE)
with sv.VideoSink(TARGET, video_info) as sink:
try:
for frame, detections in zip(frames, results):
labels = list(detections.data["class_name"])
annotated = box_annotator.annotate(frame.copy(), detections)
annotated = label_annotator.annotate(annotated, detections, labels)
sink.write_frame(annotated)
finally:
results.close()stream=True decodes and predicts frames as you iterate, so a long video never has to fit in memory. RFDETRSmall() is pre-trained on the 80 COCO classes. To detect your own objects, load the checkpoint you fine-tuned with the same size class, for example RFDETRSmall(pretrain_weights="checkpoint_best_total.pth"). How to label data for RF-DETR training and How to Train RF-DETR on a Custom Dataset cover getting there.
The same predict() call also reads a video URL, a webcam index, an RTSP stream or a YouTube link. See Run on videos and streams (opens in a new tab) in the RF-DETR docs.
Process recorded videos with Batch Processing
When you have many videos, or long ones, Batch Processing (opens in a new tab) runs a Workflow on them in Roboflow's cloud. It provisions the machines, runs the model on every video, and returns the results as JSON. There is no code to write and nothing runs on your machine.
- Build a Workflow with your model, for example an Object Detection Model block running RF-DETR.
- In the Roboflow app, open "Deployments", select the "Batch Processing" tab and click "New Batch Job".
- Select the Workflow, upload your videos, and choose CPU or GPU machines.
- Click "Create Batch Job". The job list shows each job's progress as it runs.
Jobs use credits at the CPU and GPU rates on the credits page.
Run a model on a live camera with Cloud Streaming
Cloud Streaming runs a Workflow on a live RTSP, RTMP, IP or USB camera on Roboflow-managed GPUs, so you do not host an inference server. A connector on a computer near your cameras sends the video to Roboflow, and the job returns annotated video, the latest JSON result, and any events your Workflow sends.
- In the Roboflow app, open "Deployments", then "Cloud Streaming", and click "Add Video Source" to connect a camera.
- Select the source and your Workflow, review the estimate, and click "Start Processing".
- Watch the results in the app, or read them as JSON. A deployment keeps processing after you close the browser, until you stop it.
Cloud Streaming bills per GPU-hour, not per frame. Start with the Cloud Streaming quickstart (opens in a new tab).
Run a model on video with a coding agent
The Roboflow MCP server connects a coding agent, such as Claude Code, Cursor or Codex, to your Roboflow workspace. Describe the job and the agent takes the right path: it can write and run the RF-DETR script above, start a Batch Processing job on your videos, or connect a camera and preview a Workflow with Cloud Streaming. For example:
Run RF-DETR on every video in ./videos
with Batch Processing and save the detections as JSON.