Streaming basics: RTSP & ONVIF
Getting video out of a camera is usually the first integration step, and almost every China-made IP camera offers two doors: a vendor RTSP path and an ONVIF service. Both reach the same encoder, but they fail in different ways.
This guide is written from the published protocol documents and the vendor URL schemes documented on this site. It is not a bench test.
RTSP is control, not the video
RTSP (RFC 2326) is a session protocol. It opens a session, negotiates where the media should go, and starts or stops it; the pictures travel as RTP (RFC 3550) on a separate channel. That split explains most integration surprises: a client can log in, receive a valid RTSP reply, and still show nothing because the RTP path is blocked.
The control conversation uses five methods, in this order:
- OPTIONS asks what the server supports.
- DESCRIBE returns an SDP description of the stream: codec, resolution, frame rate and payload type.
- SETUP creates a transport for one media track and chooses UDP or interleaved TCP.
- PLAY starts delivery, and TEARDOWN closes the session.
If DESCRIBE and PLAY both succeed but no frames arrive, the problem sits downstream of RTSP: firewall, NAT, multicast, or a codec the decoder will not accept.
Vendor URL shapes
| Vendor | Main stream | Sub stream |
|---|---|---|
| Hikvision | rtsp://u:p@ip:554/Streaming/Channels/101 | .../102 |
| Dahua | rtsp://u:p@ip:554/cam/realmonitor?channel=1&subtype=0 | subtype=1 |
These paths are firmware conventions, not protocol standards. A path copied from a forum post for another model family can return 404 while the camera itself is healthy. When a URL fails, check the model's own manual before changing anything else.
Test the stream with a player, then list the tracks when you need numbers rather than a window:
ffplay "rtsp://admin:[email protected]:554/Streaming/Channels/101"
ffprobe -v error -rtsp_transport tcp \
-show_entries stream=codec_name,width,height,avg_frame_rate \
"rtsp://admin:[email protected]:554/Streaming/Channels/101"
Choose the transport deliberately
RTP over UDP is the default and the lowest-latency choice on a clean LAN. Interleaved TCP carries the media inside the RTSP connection, which survives NAT and packet loss at the cost of head-of-line blocking. When a recorder sits behind a router, or the link is a VPN, force TCP first and compare before blaming the camera.
The sub stream exists for the same reason. A grid of sixteen 4 MP main streams is a bandwidth problem, not a decoding problem; most integrations use the sub stream for tiles and the main stream only for the full-screen view.
ONVIF is the vendor-neutral door
ONVIF wraps the same camera in SOAP services. A client finds devices with WS-Discovery multicast on 239.255.255.250:3702, reads the device capabilities, asks the media service for its profiles, then calls GetStreamUri to receive an RTSP URI. That URI is the same kind of address as the vendor path above, which is why an ONVIF integration can still fail at the streaming step.
Profiles describe what a device claims to support: Profile S for streaming, Profile G for recording and playback, Profile T for the newer streaming feature set, and Profile M for metadata and analytics. The claim is per model, and one vendor ships models with different profile rows. Check the datasheet for the exact model instead of the product family page.
Two practical notes:
- ONVIF credentials are not always the web credentials. Some devices keep a separate ONVIF user list, and creating an entry is a deliberate step.
- GetStreamUri returns the URI the device wants to publish, which may point at a different interface or port than the one used for discovery.
Failure modes worth memorising
| Symptom | Usual cause | Check |
|---|---|---|
| 401 on every request | Digest challenge not answered | Use a client that supports Digest; see the authentication guide |
| 404 on a healthy camera | Wrong path for the model or firmware | Model manual, not another model's URL |
| DESCRIBE works, no video | RTP blocked or UDP dropped | Retry with TCP transport |
| Video only in one player | Codec not supported by the other | Compare the codec reported by ffprobe |
| ONVIF discovery finds nothing | Multicast blocked or wrong subnet | Query the device address directly |
Credentials in a URL end up in shell history, process lists and logs. Use a player that prompts for the password, or keep the URL in an environment variable and pass it to the command.