How to connect to an RTSP camera and display the picture in C#

On this webpage you will find detailed information on how to connect to an RTSP camera device with your Windows Forms/WPF Application written in C#. To implement this example, you need to have OZEKI Camera SDK installed, and a reference to OzekiSDK.dll should be added to your Visual Studio project.

How to connect to an RTSP camera device using C#?

Windows Form WPF  

In order to connect to your camera device with the OZEKI Camera SDK you need to use the classes of the SDK whose objects have been declared at the beginning of the Form1 class. After this you should initialize these objects in the constructor of the form ( it is possible within the declaration statements as well). The final steps are to call the method named SetVideoViewer() and to add your VideoViewerFM object to the control collection of the panel that you can see on the GUI. Important: you should study this article in order to find out how to setup your Windows Forms Application correctly.

Getting started

To get started it is recomended to Download and Install the latest version of Ozeki Camera SDK. After installation you can find the example code discussed in this page with full source code in the following location on your harddisk:

Download Ozeki Camera SDK:
Windows forms version: C:\Program Files\Ozeki\Ozeki SDK\\Examples\Other\

To compile this example you will need Microsoft Visual Studio installed on your computer.

The following Method calls which can react to the "Connect button pushed" event:

_camera = IPCameraFactory.GetCamera("rtsp://", "root", "pass"): this method initializes the camera device that has been declared as a private member of the class. The used arguments are the following: The first component is the adress of the camera. It must be an RTSP (Real Time Streaming Protocol) camera which is marked by the, rtsp:// opening and followed by the URI (Uniform Resource Identifier) containing the IP address of the device, then its port number and stream identifier. The second component is the username and the third is the password for the camera.

_connector.Connect(_camera.VideoChannel, _imageProvider): This method establishes the connection between the image that we recive from our RTSP camera and the image provider object which is used for displaying the image of the camera on the Graphical User Interface.

_camera.Start(): you should use this method in order to receive image from the camera.

_videoViewerWF1.Start(): by using this method the image on the GUI will be displayed.

RTSP camera connection example in C#


using System;
using System.Windows.Forms;
using Ozeki.Media;
using Ozeki.Camera;

namespace VideoCameraViewer02
    public partial class Form1 : Form
        private IIPCamera _camera;
        private DrawingImageProvider _imageProvider = new DrawingImageProvider();
        private MediaConnector _connector = new MediaConnector();
        private VideoViewerWF _videoViewerWF1;

        public Form1()

            // Create video viewer UI control
            _videoViewerWF1 = new VideoViewerWF();
            _videoViewerWF1.Name = "videoViewerWF1";
            _videoViewerWF1.Size = panel1.Size;

            // Bind the camera image to the UI control

        // Connect camera video channel to image provider and start
        private void connectBtn_Click(object sender, EventArgs e)
            _camera = IPCameraFactory.GetCamera("rtsp://", "root", "pass");
            _connector.Connect(_camera.VideoChannel, _imageProvider);

Code 1 - IP camera connection example in C#

Please note that none of the cancel and disconnect methods are included in the example because of the demonstrating intent and briefness of the article.


The Graphical User Interface of the RTSP camera viewer
Figure 1 - The graphical user interface of your application

After the successful implementation of the functions and the GUI elements, the application will work properly. By pressing the connect button the image of the RTSP camera will be loaded in.

Below you can find the code that belongs to the interface of the previously presented application. With the help of this section your Windows Forms Application will be able to work properly.


	namespace VideoCameraViewer02
    partial class Form1
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
            if (disposing && (components != null))

        private void InitializeComponent()
            this.connectBtn = new System.Windows.Forms.Button();
            this.panel1 = new System.Windows.Forms.Panel();
            // connectBtn
            this.connectBtn.Location = new System.Drawing.Point(10, 230);
            this.connectBtn.Name = "connectBtn";
            this.connectBtn.Size = new System.Drawing.Size(75, 23);
            this.connectBtn.TabIndex = 2;
            this.connectBtn.Text = "Connect";
            this.connectBtn.UseVisualStyleBackColor = true;
            this.connectBtn.Click += new System.EventHandler(this.connectBtn_Click);
            // panel1
            this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.panel1.Location = new System.Drawing.Point(10, 10);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(250, 210);
            this.panel1.TabIndex = 3;
            // Form1
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(274, 264);
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "RTSP Camera\'s Live Image";


        private System.Windows.Forms.Button connectBtn;
        private System.Windows.Forms.Panel panel1;

Code 2 - GUI example in C#

DISCLAIMER: Please note that the following features will only work if your IP camera supports the given function. You should check the user manual of your IP camera to make sure it supports the feature that you wish to implement in C#.

Related Pages


Below you can find the answers for the most frequently asked questions related to this topic:

  1. How can I get the URL of the camera?

    You can get the URL from the producer of the camera. (In the 10th tutorial you can find information on how to create an own IP camera discoverer program.)

  2. I have not managed to build the solution. How to solve it?

    • Please set the Target framework property of the project to .NET 4.0.
    • You should add the OzekiSDK.dll and System.Drawing.dll to the references of the solution.
    • Please import the missing classes.
  3. What's the difference among USB camera, RTSP camera and ONVIF camera?

    In the case of USB camera we do not need camera url and some functions(like moving, zooming, etc.) are not available. In the case of RTSP camera and ONVIF camera there are more available functions. The difference between the RTSP camera and the ONVIF camera is while the RTSP camera can have only one stream at a time, the ONVIF camera can have multiple.

Ozeki Camera Recorder

If you are not a developer, but you need a great software to view or record your camera, we recommend you to use Ozeki Camera Recorder. This is a great end user product, that allows you to control your cameras from a webbrowser. It's easy and great. You can download it from the following link: Download Ozeki Camera Recorder.

Download link:
Download Ozeki Camera Recorder for Windows

Copyright © 2000- - Ozeki Ltd |
Home > Online manual > IP video camera viewer > Connect to RTSP camera
Legal | Privacy | Terms of use | 6536 | | Login