Process a Video Stream
Run a Roboflow Workflow against a video file or live RTSP stream.
Path A - Hosted: process a video file
import os
import time
import requests
API_KEY = os.environ["ROBOFLOW_API_KEY"]
WORKSPACE = "my-workspace"
WORKFLOW = "my-detector-workflow"
# 1. Get a signed upload URL.
signed = requests.post(
"https://api.roboflow.com/video_upload_signed_url/",
params={"api_key": API_KEY, "file_name": "input.mp4"},
).json()
# 2. Upload the file.
with open("input.mp4", "rb") as f:
requests.put(signed["signedUrl"], data=f, headers={"Content-Type": "video/mp4"})
# 3. Submit the inference job pointing at the uploaded file.
job = requests.post(
"https://api.roboflow.com/videoinfer/",
json={
"api_key": API_KEY,
"workspace": WORKSPACE,
"workflow": WORKFLOW,
"video_url": signed["fileUrl"],
"fps": 5,
},
).json()
job_id = job["jobId"]
# 4. Poll until the job is done.
while True:
status = requests.get(
f"https://api.roboflow.com/videoinfer?api_key={API_KEY}&jobId={job_id}"
).json()
if status["status"] in ("complete", "failed"):
break
time.sleep(5)
print(status)Path B - Self-hosted: stream frames to local Inference
When to use which
Hosted
Self-hosted
Logging predictions to Vision Events
Last updated
Was this helpful?