View an RTSP camera in Unity¶
The RTSPViewer scene displays a live RTSP / IP camera stream with the Media Blocks SDK .NET, rendered into a Unity RawImage. This article assumes you have imported the Unity package and applied the two required project settings — see Using VisioForge in Unity first.
Run the sample¶
- In the Project window open
Assets/Scenes/RTSPViewer.unity(double-click it). - In the Hierarchy select the RawImage GameObject. The
RTSPViewerPlayercomponent is attached to it. - In the Inspector, set Rtsp Url (and Login / Password if the camera requires authentication).
- Press ▶ Play — the stream renders in the Game view.


Inspector fields¶
| Field | Default | Description |
|---|---|---|
| Rtsp Url | rtsp://192.168.1.10:554/stream | RTSP URL of the camera/stream. |
| Login | (empty) | RTSP username — leave empty if the stream needs no auth. |
| Password | (empty) | RTSP password. |
| Auto Play On Start | true | Connect automatically in Start(). |
| Render Audio | true | Render audio through the system default device. |
| Aspect Mode | Letterbox | How the video is fitted into the RawImage: Stretch, Letterbox, or Crop. |
The pipeline¶
RTSPViewerPlayer builds this pipeline:
graph LR;
src[RTSPSourceBlock] -->|video| sink["BufferSinkBlock (RGBA)"];
sink --> view["VisioForgeVideoView (Texture2D)"];
src -->|audio, optional| audio[AudioRendererBlock]; The core of PlayAsync:
_pipeline = new MediaBlocksPipeline();
// readInfo:false skips the media pre-probe (it can fail under the Unity runtime, and
// probing a live stream adds connect latency); the codec is negotiated when playback starts.
var settings = await RTSPSourceSettings.CreateAsync(
new Uri(rtspUrl), login ?? string.Empty, password ?? string.Empty,
audioEnabled: _renderAudio, readInfo: false);
_source = new RTSPSourceBlock(settings);
_videoSink = new BufferSinkBlock(VideoFormatX.RGBA);
_videoSink.OnVideoFrameBuffer += _videoView.OnFrameBuffer;
_pipeline.Connect(_source.VideoOutput, _videoSink.Input);
if (_renderAudio && _source.AudioOutput != null)
{
_audioRenderer = new AudioRendererBlock();
_pipeline.Connect(_source.AudioOutput, _audioRenderer.Input);
}
await _pipeline.StartAsync();
Use it in your own scene¶
Add a Canvas → Raw Image (GameObject → UI → Raw Image), select it, Add Component → RTSPViewerPlayer, set Rtsp Url, and press ▶ Play. The RawImage layout, aspect handling, and vertical flip are handled by the bundled VisioForgeVideoView. For local file playback instead of RTSP, use MediaBlocksPlayer (see Play a media file).
Frequently Asked Questions¶
How do I provide camera credentials?¶
Set the Login and Password fields. Leave them empty for streams that need no authentication; the credentials are sent to the camera, not embedded in the URL.
What URL format should I use?¶
The standard rtsp://host:port/path form your camera exposes, e.g. rtsp://192.168.1.21:554/Streaming/Channels/101 (Hikvision) or rtsp://192.168.1.22:554/cam/realmonitor?channel=1&subtype=0 (Dahua). Check your camera's manual for its exact stream path.
What if the camera has no audio?¶
It works as video-only. The audio branch is connected only when the stream actually carries audio, so a video-only camera needs no changes.
Can I display several cameras at once?¶
Yes. Add a RawImage with its own RTSPViewerPlayer for each camera; each builds an independent pipeline.
See Also¶
- Using VisioForge in Unity — package overview, setup, and how rendering works
- Play a media file in Unity — the file-playback sample
- RTSP streaming guide — RTSP across the VisioForge .NET SDKs
- IP camera brands directory — tested camera URLs and settings
- Media Blocks RTSP player in C# — a non-Unity RTSP example