YOLOv8 RTSP stream detection allows an Ultralytics YOLO model to process live video from IP cameras and network video sources. RTSP, or Real-Time Streaming Protocol, is commonly used by surveillance cameras because it provides a direct network video stream that applications can decode frame by frame. Current Ultralytics stream loading supports RTSP together with RTMP, HTTP, and TCP sources, and its LoadStreams loader is designed for both single and multiple simultaneous streams.
A typical YOLOv8 RTSP workflow is:
IP Camera
↓
RTSP Video Stream
↓
Ultralytics Stream Loader
↓
YOLOv8 Inference
↓
Bounding Boxes
Classes
Confidence Scores
↓
Display / Save / Track / Alert
Real-time performance depends on much more than the YOLO model. Camera resolution, network delay, video codec, CPU decoding speed, GPU performance, image size, model size, number of streams, and whether tracking is enabled all affect the final FPS and latency.
Introduction to YOLOv8 RTSP Stream Detection
RTSP stream detection combines live network video with object detection. Instead of reading a static image or local video file, YOLOv8 receives a continuous sequence of frames coming from an IP camera.
This is useful for applications such as:
security monitoring
vehicle detection
people counting
traffic analysis
industrial inspection
warehouse monitoring
retail analytics
The basic idea is simple:
Camera sends frame
↓
YOLOv8 processes frame
↓
Objects are detected
↓
Next frame arrives
Current Ultralytics Predict mode accepts RTSP stream URLs directly as supported prediction sources. A .streams file can also be used when multiple live sources need to be processed together.
For long-running cameras, Python streaming with stream=True is particularly useful because it avoids retaining an ever-growing list of prediction results in memory.
What Is RTSP Stream Detection in YOLOv8?
RTSP stream detection means using an RTSP network video feed as the source for YOLOv8 inference.
A normal image workflow might be:
image.jpg
↓
YOLOv8
↓
one result
RTSP works continuously:
RTSP Stream
↓
Frame 1 → YOLOv8
Frame 2 → YOLOv8
Frame 3 → YOLOv8
Frame 4 → YOLOv8
...
The model does not need a special RTSP architecture. A regular YOLOv8 detection model can process frames from the network stream just as it processes frames from a local video file.
How RTSP Video Streaming Works
RTSP is used to control and access real-time media streams over a network.
The camera typically encodes video using a codec such as H.264 or H.265 and exposes a stream endpoint. The client connects to that endpoint, receives encoded video data, decodes frames, and passes those frames to the detection pipeline.
Conceptually:
Camera Sensor
↓
Video Encoder
↓
RTSP Server on Camera
↓
Network
↓
Video Decoder
↓
YOLOv8 Frames
YOLOv8 itself is not responsible for the entire RTSP networking protocol. Ultralytics relies on its video-loading and decoding stack to obtain frames, then feeds those frames into the model.
Why RTSP Is Used with IP Cameras
RTSP is widely used because many IP cameras expose it as a direct video interface.
Compared with manually downloading snapshots repeatedly, RTSP provides a continuous stream and can often expose:
main high-resolution stream
secondary low-resolution stream
different FPS settings
different codecs
This makes it useful for computer vision because the application can choose a stream appropriate for its hardware.
For example:
Main stream
1920×1080
higher quality
higher bandwidth
higher inference cost
versus:
Sub stream
640×360
lower bandwidth
lower inference cost
potentially higher FPS
The exact stream options depend on the camera model.
Requirements for YOLOv8 RTSP Detection
Before running YOLOv8 on an RTSP camera, three things must work correctly: Ultralytics must be installed, the camera’s RTSP URL must be known, and the machine running YOLO must be able to reach and decode the camera feed.
Testing these components separately makes troubleshooting much easier.
Install Ultralytics YOLOv8
Install the Ultralytics package:
pip install -U ultralytics
Then test the import:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
If this works, the core YOLO Python environment is available.
For GPU inference, your installed PyTorch environment must also support your CUDA setup.
Get the RTSP Camera URL
The RTSP address is normally provided by the camera manufacturer.
A common generic structure is:
rtsp://username:password@camera-ip:port/stream-path
For example:
rtsp://user:password@192.168.1.50:554/stream1
This is only a structural example. Camera vendors use different endpoint paths.
The correct path may appear in:
camera documentation
manufacturer support page
camera configuration interface
NVR configuration
ONVIF tools
Check Network and Camera Access
Before blaming YOLO, verify that the computer can reach the camera.
Check:
camera IP is reachable
RTSP service is enabled
port is accessible
username is correct
password is correct
stream path is correct
codec can be decoded
It is useful to test the feed with a video client first.
If the stream cannot be opened outside YOLO, object detection will not solve the underlying connection problem.
How to Run YOLOv8 on an RTSP Stream
Ultralytics can consume an RTSP URL directly in both CLI and Python Predict mode. RTSP is explicitly supported by the current stream loader.
The Python version is normally better for production because each frame’s result can trigger custom logic.
RTSP Detection Using the YOLO CLI
A basic command is:
yolo detect predict \
model=yolov8n.pt \
source="rtsp://user:password@192.168.1.50:554/stream1"
You can add standard prediction settings:
yolo detect predict \
model=yolov8n.pt \
source="rtsp://user:password@192.168.1.50:554/stream1" \
conf=0.25 \
iou=0.7 \
imgsz=640 \
device=0
This is useful for quickly verifying that the camera and model work together.
RTSP Detection Using Python
A typical Python workflow is:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
rtsp_url = "rtsp://user:password@192.168.1.50:554/stream1"
results = model.predict(
source=rtsp_url,
stream=True,
conf=0.25,
imgsz=640,
device=0
)
for result in results:
print(result.boxes)
With stream=True, results are yielded incrementally rather than accumulated into one large list. Current Ultralytics recommends generator-based streaming for memory-efficient video and stream processing.
Process Live Frames Continuously
You can process every yielded frame:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
source = "rtsp://user:password@192.168.1.50:554/stream1"
for result in model.predict(
source=source,
stream=True
):
if result.boxes is None:
continue
for box in result.boxes:
cls_id = int(box.cls[0])
confidence = float(box.conf[0])
coordinates = box.xyxy[0].tolist()
print(
cls_id,
confidence,
coordinates
)
Custom application logic can then be added:
person detected
→ send alert
vehicle detected
→ increase count
object enters zone
→ save event
Understanding the RTSP Stream URL
RTSP URLs contain connection information that tells the client where the camera is and which video stream to request.
The exact syntax varies by manufacturer, but the main pieces are usually similar.
Username, Password, IP Address, and Port
Generic example:
rtsp://username:password@192.168.1.50:554/stream
Breakdown:
rtsp://
→ protocol
username
→ camera account
password
→ account password
192.168.1.50
→ camera IP
554
→ RTSP port
/stream
→ video endpoint
Port 554 is common for RTSP, but a camera can be configured differently.
Avoid placing real credentials in public code repositories or logs.
RTSP Stream Path
The path identifies which stream should be opened.
Examples can conceptually look like:
/stream1
/live/main
/cam/realmonitor
/h264Preview_01_main
These are only examples of patterns seen across different manufacturers.
You must use the path defined by your specific camera.
A correct host with an incorrect path can still produce:
connection succeeds
but video cannot open
or an immediate stream error.
Main Stream vs Sub Stream
Many IP cameras provide at least two video profiles.
Main stream:
higher resolution
higher bitrate
better small-object detail
more GPU load
more network traffic
Sub stream:
lower resolution
lower bitrate
lower latency potential
less GPU load
higher throughput
For a live monitoring system, the sub stream can be useful when small-object detail is not critical.
For tasks such as distant-person or license-plate detection, the main stream may preserve necessary detail.
YOLOv8 RTSP Detection Output
RTSP prediction results use the same Ultralytics Results structures as other prediction sources.
For detection, the most important properties are:
result.boxes.xyxy
result.boxes.cls
result.boxes.conf
Bounding Boxes and Class Labels
Example:
for result in results:
if result.boxes is None:
continue
print(result.boxes.xyxy)
print(result.boxes.cls)
You can map class IDs to names:
for result in results:
print(result.names)
A detection might conceptually contain:
class = person
box = [120, 80, 370, 600]
Confidence Scores
Confidence values are available through:
result.boxes.conf
Example:
for box in result.boxes:
class_id = int(box.cls[0])
confidence = float(box.conf[0])
print(class_id, confidence)
The prediction confidence threshold can be controlled with:
conf=0.25
Increasing it usually removes weaker detections, while decreasing it allows more low-confidence boxes to remain.
Real-Time Frame Predictions
Every iteration from a streaming generator corresponds to current processed output.
Conceptually:
Frame 1
→ 3 detections
Frame 2
→ 4 detections
Frame 3
→ 2 detections
You can maintain your own frame counter:
frame_id = 0
for result in results:
frame_id += 1
count = 0 if result.boxes is None else len(result.boxes)
print(
"Frame:",
frame_id,
"Objects:",
count
)
Improve YOLOv8 RTSP Detection Speed
Low RTSP FPS is often caused by a combination of network, decoding, preprocessing, inference, and output overhead.
The entire pipeline should therefore be measured.
A simplified latency breakdown is:
Network delay
+
video decoding
+
image preprocessing
+
YOLO inference
+
post-processing
+
drawing/saving
=
total delay
Reduce Input Resolution
Set a smaller model input size:
results = model.predict(
source=rtsp_url,
stream=True,
imgsz=640
)
If you were previously using:
imgsz=1280
moving to:
imgsz=640
can substantially reduce model computation.
However, this can hurt small-object detection.
If the camera already offers a lower-resolution sub stream, using that can reduce both network and decoding load.
Use GPU Acceleration
Specify:
device=0
Example:
results = model.predict(
source=rtsp_url,
stream=True,
device=0
)
CLI:
yolo detect predict \
model=yolov8n.pt \
source="rtsp://camera-stream" \
device=0
GPU acceleration is often essential when multiple HD cameras need to be processed simultaneously.
Choose a Smaller YOLOv8 Model
YOLOv8 model sizes include:
yolov8n
yolov8s
yolov8m
yolov8l
yolov8x
For live RTSP systems, start with:
yolov8n
or:
yolov8s
and move to a larger model only if accuracy requirements justify the additional latency.
A smaller model can also make it possible to run more camera streams on the same GPU.
Reduce Stream Latency
Model inference is only one part of RTSP latency.
Potential sources of delay include:
camera encoder buffering
network congestion
RTSP transport buffering
video decoder queue
slow inference
slow video output
Current Ultralytics LoadStreams exposes a buffer argument, and its stream loader maintains threaded frame acquisition. The loader defaults to buffer=False, which favors accessing more current frames rather than building a large buffered queue.
For latency-sensitive systems, also consider:
lower camera bitrate
lower camera resolution
lower camera FPS
wired Ethernet
shorter GOP where camera supports it
faster model
faster decoder
These settings are camera and deployment dependent.
YOLOv8 RTSP Detection with Object Tracking
Detection independently identifies objects on each frame.
Tracking adds temporal association so the same object can retain an ID across frames.
Current Ultralytics tracking supports multiple tracker configurations including BoT-SORT and ByteTrack.
Track Objects Across Frames
Python example:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
results = model.track(
source=rtsp_url,
stream=True,
persist=True
)
for result in results:
print(result.boxes)
The tracker associates current detections with previous tracks.
Conceptually:
Frame 1:
Person → ID 4
Frame 2:
Person → ID 4
Frame 3:
Person → ID 4
No tracker can guarantee perfect identity persistence in every crowd or occlusion scenario, but tracking enables much richer video analytics than frame-independent detection.
Maintain Unique Tracking IDs
Tracking IDs can be accessed when present:
for result in results:
if (
result.boxes is not None
and result.boxes.id is not None
):
ids = (
result.boxes.id
.int()
.cpu()
.tolist()
)
print(ids)
These IDs can be used for:
people counting
vehicle counting
trajectory analysis
entry/exit logic
dwell-time analysis
Use BoT-SORT or ByteTrack
BoT-SORT:
results = model.track(
source=rtsp_url,
stream=True,
tracker="botsort.yaml"
)
ByteTrack:
results = model.track(
source=rtsp_url,
stream=True,
tracker="bytetrack.yaml"
)
Current Ultralytics documents BoT-SORT as the default tracker and ByteTrack as another built-in option. It also supports additional tracker configurations in recent releases.
Run Multiple RTSP Streams with YOLOv8
Current Ultralytics supports multiple simultaneous video streams through a .streams source file. If the file contains eight stream URLs, Predict mode documents that they are processed with batch size 8.
This makes multi-camera inference possible without manually creating a separate process for every source.
Connect Multiple IP Cameras
Create:
cameras.streams
with one URL per line:
rtsp://camera1/stream
rtsp://camera2/stream
rtsp://camera3/stream
rtsp://camera4/stream
Then run:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
results = model.predict(
source="cameras.streams",
stream=True
)
for result in results:
print(result.path)
Ultralytics documents .streams files specifically for multi-stream prediction.
Manage GPU and Memory Usage
Multiple streams increase:
video decoding load
GPU input batch size
VRAM usage
CPU usage
network bandwidth
post-processing workload
For example:
1 × 1080p stream
may be easy for a GPU, while:
16 × 1080p streams
may require a smaller model or lower resolution.
Useful controls include:
smaller YOLOv8 model
smaller imgsz
sub streams
lower camera FPS
FP16 on compatible GPU
fewer concurrent streams
You should benchmark the complete multi-camera pipeline rather than extrapolating from one camera.
Process Multiple Streams Efficiently
Current LoadStreams uses threading to load multiple video streams and returns batches containing frames from the active streams.
Conceptually:
Camera 1 ─┐
Camera 2 ─┤
Camera 3 ─┼→ LoadStreams → Batch → YOLO
Camera 4 ─┘
For tracking across multiple independent cameras, each camera should generally maintain its own tracker state unless you are implementing a separate cross-camera identity system.
Ultralytics also documents multithreaded tracking patterns for running tracking on several video inputs simultaneously.
Saving RTSP Detection Results
You may need to save annotated video, text labels, event records, or only selected evidence frames.
For continuous cameras, saving everything can consume significant disk space.
Save Annotated Video
CLI:
yolo detect predict \
model=best.pt \
source="rtsp://camera-stream" \
save=True
Python:
model.predict(
source=rtsp_url,
save=True
)
For continuous 24/7 streams, consider whether full recording is actually necessary.
A more efficient system might only save frames around important detections.
Save Detection Labels
Example:
model.predict(
source=rtsp_url,
save_txt=True,
save_conf=True
)
This can save detection information containing class and box data and optionally confidence values, depending on the active result type.
For long-running systems, text output can still grow significantly, so retention policies are useful.
Store Detection Events and Frames
For production analytics, it is often better to create structured events.
Example:
import time
from ultralytics import YOLO
model = YOLO("best.pt")
for result in model.predict(
source=rtsp_url,
stream=True
):
if result.boxes is None:
continue
for box in result.boxes:
event = {
"timestamp": time.time(),
"class_id": int(box.cls[0]),
"confidence": float(box.conf[0]),
"box": box.xyxy[0].tolist(),
}
print(event)
This structure can be sent to:
database
message queue
REST API
analytics service
alerting system
without storing every video frame.
Common YOLOv8 RTSP Stream Problems
RTSP issues are often caused outside the neural network.
The best debugging approach is to separate:
camera/network problem
decoder problem
YOLO inference problem
tracking problem
rather than treating all failures as one issue.
RTSP Connection Failed
Check:
IP address
port
username
password
stream path
RTSP enabled
firewall
network routing
Also verify the camera feed with another RTSP-capable client.
If the stream cannot be decoded there, fix the camera or network before changing YOLO settings.
Stream Keeps Disconnecting
Possible causes include:
Wi-Fi instability
camera reboot
network congestion
RTSP timeout
NVR overload
decoder errors
Current Ultralytics LoadStreams uses background threads to continuously update stream frames.
However, production systems may still need their own:
reconnect loop
health checks
exception logging
camera timeout detection
around the inference process.
High Latency and Delayed Detection
A common problem is that frames arrive faster than they are processed.
Example:
Camera:
30 FPS
YOLO pipeline:
8 FPS
If every frame is buffered, delay can accumulate.
Use a faster pipeline:
smaller model
lower resolution
GPU
sub stream
lower FPS
fewer cameras
less output rendering
Current LoadStreams defaults to buffer=False, which is useful for live analysis because it avoids intentionally accumulating a large frame buffer.
Low FPS During Inference
Possible bottlenecks include:
large model
high imgsz
CPU inference
H.265 decoding
too many cameras
slow network
tracking
saving video
drawing overlays
Measure each stage.
For example:
decode = 12 ms
YOLO = 20 ms
tracking = 3 ms
drawing = 5 ms
total ≈ 40 ms
which corresponds to a theoretical processing rate near:
25 FPS
before additional queueing or network delays.
FAQs About YOLOv8 RTSP Stream Detection
Can YOLOv8 detect objects from an RTSP stream?
Yes.
Current Ultralytics Predict mode explicitly supports RTSP as a stream source.
Example:
model.predict(
source="rtsp://camera-stream",
stream=True
)
How do I connect an IP camera to YOLOv8?
Obtain the camera’s RTSP URL and pass it as the prediction source.
For example:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.predict(
source="rtsp://user:password@camera/stream",
stream=True
)
The exact URL must come from the camera configuration or manufacturer documentation.
What RTSP URL format does YOLOv8 use?
YOLOv8 accepts a normal RTSP media URL.
A generic structure is:
rtsp://username:password@ip-address:port/stream-path
The stream path is vendor-specific.
Ultralytics itself does not require one particular camera-brand URL structure; the important point is that the source resolves to a decodable RTSP stream.
Can YOLOv8 process multiple RTSP cameras?
Yes.
A .streams text file can contain one stream URL per line.
Current Ultralytics documentation states that multiple streams are run as a batch corresponding to the number of listed streams.
For example:
camera1
camera2
camera3
camera4
results in four simultaneous input streams.
How can I reduce RTSP detection latency?
Common approaches include:
use wired Ethernet
lower camera resolution
use camera sub stream
reduce imgsz
use YOLOv8n or YOLOv8s
use a GPU
avoid unnecessary buffering
reduce saving/drawing overhead
lower source FPS
Current LoadStreams supports buffer=False, which is its default behavior.
Can YOLOv8 track objects in an RTSP stream?
Yes.
Use:
model.track(
source=rtsp_url,
stream=True,
persist=True
)
Ultralytics currently supports trackers including BoT-SORT and ByteTrack.
How do I save YOLOv8 RTSP detection results?
Annotated results:
model.predict(
source=rtsp_url,
save=True
)
Detection text output:
model.predict(
source=rtsp_url,
save_txt=True,
save_conf=True
)
For long-running systems, custom event storage is usually more manageable than saving every frame continuously.
Conclusion
YOLOv8 RTSP stream detection provides a practical way to connect Ultralytics models to live IP cameras for continuous object detection.
Current Ultralytics stream loading supports:
RTSP
RTMP
HTTP
TCP
and its LoadStreams class can load multiple video streams simultaneously using threaded frame acquisition.
A basic Python RTSP detector looks like:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
rtsp_url = "rtsp://user:password@camera/stream"
for result in model.predict(
source=rtsp_url,
stream=True,
conf=0.25,
imgsz=640,
device=0
):
if result.boxes is None:
continue
for box in result.boxes:
print(
int(box.cls[0]),
float(box.conf[0]),
box.xyxy[0].tolist()
)
For tracking:
results = model.track(
source=rtsp_url,
stream=True,
persist=True,
tracker="botsort.yaml"
)
Current Ultralytics supports BoT-SORT and ByteTrack together with additional tracking algorithms in recent releases.
For several cameras, create a .streams file:
rtsp://camera1/stream
rtsp://camera2/stream
rtsp://camera3/stream
and pass that file as the prediction source. Ultralytics documents multi-stream inference as batching one frame from each listed stream together.
A practical deployment workflow is:
Verify Camera RTSP URL
↓
Test Network and Decoder
↓
Run YOLOv8 on One Camera
↓
Measure FPS and Latency
↓
Tune imgsz and Model Size
↓
Move to GPU if Needed
↓
Add Tracking
↓
Add Event Storage
↓
Add More Cameras
↓
Monitor Reconnects and Resource Usage
For low-latency live systems, prioritize current frames rather than simply buffering every frame. For multi-camera systems, monitor GPU memory, decoding load, network bandwidth, and per-camera latency together. The best RTSP configuration is the one that maintains acceptable detection quality while keeping the stream sufficiently current for the application’s real-time requirements.
I’m Jane Austen, a skilled content writer with the ability to simplify any complex topic. I focus on delivering valuable tips and strategies throughout my articles.