Ozeki Camera Recorder Stat

How to connect to media file stream, broadcasted by VLC media player in C#

In this description you will find detailed information about how to connect to media file stream using VLC Media Player. With OZEKI Camera SDK you can connect to an RTSP camera and you can also connect to streams by VLC media player. To connect to a VLC server make sure your VLC server is playing and streaming media over the network.

What is VLC media player?

VLC Media Player (commonly known as VLC) is a portable, free and open-source, cross-platform media player and streaming media server written by the VideoLAN project.VLC media player supports many audio and video compression methods and file formats, including DVD-Video, video CD and streaming protocols. It is able to stream media over computer networks and to transcode multimedia files.

Connecting to Ozeki Camera SDK RTSP stream with VLC media player

In the following part you will find information about how to tune into the RTSP stream using VLC media player. Firstly,to connect to a stream click the Media menu and select Open Network Stream. Assuming you used HTTP, enter the other system's IP address.If you specified a custom path for your HTTP stream in the Path box, you'll need to specify the custom path here. Finally, click the Play button.After clicking Play, the stream should start playing. To control playback remotely, try setting up VLC's web interface. If you encounter an error, make sure VLC isn't being blocked by a firewall on the streaming system.

Why is it good for us?

For example, if there are security cameras in your shop you can easily connect to the RTSP stream with VLC media player and you are able to see what happens in the shop.

Conclusion

By reading through this tutorial you will be able to connect to RTSP stream with VLC Media Player. On this webpage you can find helpful documentations to help the understanding.

C# code example

Windows Form  

MainForm.cs

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

namespace RtspStreamer_WF
{
    public partial class MainForm : Form
    {
        private string  _ip;
        private int _port;

        private CameraServer _server;
        private OzekiCamera _camera;
        private MediaConnector _clientConnector;
        private MediaConnector _connector;
        private CameraURLBuilderWF _myCameraUrlBuilder;
        private DrawingImageProvider _imageProvider;

        public MainForm()
        {
            InitializeComponent();

            _imageProvider = new DrawingImageProvider();
            _connector = new MediaConnector();
            _myCameraUrlBuilder = new CameraURLBuilderWF();
            _server = new CameraServer();
            _server.ServerStateChanged += _server_ServerStateChanged;
            _server.ClientConnected += _server_ClientConnected;
            _server.ClientDisconnected += _server_ClientDisconnected;
            _server.Stopped += _server_Stopped;

            OriginalViewer.SetImageProvider(_imageProvider);

            _ip = Ozeki.Network.NetworkAddressHelper.GetLocalIP().ToString();
            _port = 554;
        }

        void _server_Stopped(object sender, EventArgs e)
        {
            _clientConnector.Dispose();
        }

        void _server_ClientDisconnected(object sender, Ozeki.Camera.IPCamera.Server.Events.CameraServerArgs e)
        {
            _clientConnector.Disconnect(_camera.AudioChannel, e.Client.AudioChannel);
            _clientConnector.Disconnect(_camera.VideoChannel, e.Client.VideoChannel);

            InvokeGuiThread(() =>
            {
                foreach (var client in _server.ConnectedClients)
                {
                    tb_client.Text += client.TransportInfo.RemoteEndPoint;
                }

            });
        }

        void _server_ClientConnected(object sender, Ozeki.Camera.IPCamera.Server.Events.CameraServerArgs e)
        {
            _clientConnector.Connect(_camera.AudioChannel, e.Client.AudioChannel);
            _clientConnector.Connect(_camera.VideoChannel, e.Client.VideoChannel);

            InvokeGuiThread(() =>
            {
                foreach (var client in _server.ConnectedClients)
                {
                    tb_client.Text += client.TransportInfo.RemoteEndPoint +"\n";
                }

            });

        }

        void _server_ServerStateChanged(object sender, Ozeki.Camera.IPCamera.Server.Events.CameraServerStateChangedArgs e)
        {
            label_state.Text = e.State.ToString();
        }

        void InvokeGuiThread(Action action)
        {
            BeginInvoke(action);
        }

        void Start()
        {
            OriginalViewer.Start();
            _camera.Start();
        }

        private void button_Compose_Click(object sender, EventArgs e)
        {
            var result = _myCameraUrlBuilder.ShowDialog();

            if (result != DialogResult.OK) return;

            textBox1.Text = _myCameraUrlBuilder.CameraURL;

            button_Connect.Enabled = true;
        }

        private void button_Connect_Click(object sender, EventArgs e)
        {
            if (_camera != null)
            {
                _camera.CameraStateChanged -= _camera_CameraStateChanged;
                _camera.Disconnect();
                _connector.Disconnect(_camera.VideoChannel, _imageProvider);
                _camera = null;
            }

            _camera = new OzekiCamera(_myCameraUrlBuilder.CameraURL);
            _camera.CameraStateChanged += _camera_CameraStateChanged;
            _connector.Connect(_camera.VideoChannel, _imageProvider);

            button_Connect.Enabled = false;
            btn_start.Enabled = true;

            tb_url.Text = String.Format("rtsp://{0}:{1}", _ip, _port);

            Start();
        }

        private void _camera_CameraStateChanged(object sender, CameraStateEventArgs e)
        {
            InvokeGuiThread(() =>
            {
                if (e.State == CameraState.Connecting)
                    button_Connect.Enabled = false;
                if (e.State == CameraState.Streaming)
                    button_Disconnect.Enabled = true;
                if (e.State == CameraState.Disconnected)
                {
                    button_Disconnect.Enabled = false;
                    button_Connect.Enabled = true;
                }
            });

            InvokeGuiThread(() =>
            {
                Lb_state.Text = e.State.ToString();
            });
        }

        private void button_Disconnect_Click(object sender, EventArgs e)
        {
            _camera.Disconnect();
            _connector.Disconnect(_camera.VideoChannel, _imageProvider);
            _camera = null;
        }

        private void btn_start_Click(object sender, EventArgs e)
        {
            btn_start.Enabled = false;
            btn_stop.Enabled = true;
            _clientConnector = new MediaConnector();
            _server.Start();
            _server.SetListenAddress(_ip, _port);
        }

        private void btn_stop_Click(object sender, EventArgs e)
        {
            btn_start.Enabled = true;
            btn_stop.Enabled = false;
            _server.Stop();
            tb_client.Clear();
        }

    }
}


Code 1 - Connecting to stream example code in C#

GUI

The Graphical User Interface of an application for connect to stream in C#
Figure 1 - The graphical user interface of your application

After you have downloaded the Ozeki Camera SDK software you can find the GUI code in the Example folder.

MainForm.Designer.cs

namespace RtspStreamer_WF
{
    partial class MainForm
    {

        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button_Compose = new System.Windows.Forms.Button();
            this.button_Connect = new System.Windows.Forms.Button();
            this.button_Disconnect = new System.Windows.Forms.Button();
            this.stateLabel = new System.Windows.Forms.Label();
            this.colorDialog1 = new System.Windows.Forms.ColorDialog();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.labelState = new System.Windows.Forms.Label();
            this.Lb_state = new System.Windows.Forms.Label();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.btn_start = new System.Windows.Forms.Button();
            this.label_state = new System.Windows.Forms.Label();
            this.label_s = new System.Windows.Forms.Label();
            this.tb_url = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.btn_stop = new System.Windows.Forms.Button();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.tb_client = new System.Windows.Forms.RichTextBox();
            this.OriginalViewer = new Ozeki.Media.VideoViewerWF();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(6, 20);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(71, 13);
            this.label1.TabIndex = 1;
            this.label1.Text = "Camera URL:";
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(83, 17);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(180, 20);
            this.textBox1.TabIndex = 2;
            // 
            // button_Compose
            // 
            this.button_Compose.Location = new System.Drawing.Point(284, 14);
            this.button_Compose.Name = "button_Compose";
            this.button_Compose.Size = new System.Drawing.Size(75, 23);
            this.button_Compose.TabIndex = 3;
            this.button_Compose.Text = "Compose";
            this.button_Compose.UseVisualStyleBackColor = true;
            this.button_Compose.Click += new System.EventHandler(this.button_Compose_Click);
            // 
            // button_Connect
            // 
            this.button_Connect.Enabled = false;
            this.button_Connect.Location = new System.Drawing.Point(77, 43);
            this.button_Connect.Name = "button_Connect";
            this.button_Connect.Size = new System.Drawing.Size(75, 23);
            this.button_Connect.TabIndex = 4;
            this.button_Connect.Text = "Connect";
            this.button_Connect.UseVisualStyleBackColor = true;
            this.button_Connect.Click += new System.EventHandler(this.button_Connect_Click);
            // 
            // button_Disconnect
            // 
            this.button_Disconnect.Enabled = false;
            this.button_Disconnect.Location = new System.Drawing.Point(188, 43);
            this.button_Disconnect.Name = "button_Disconnect";
            this.button_Disconnect.Size = new System.Drawing.Size(75, 23);
            this.button_Disconnect.TabIndex = 6;
            this.button_Disconnect.Text = "Disconnect";
            this.button_Disconnect.UseVisualStyleBackColor = true;
            this.button_Disconnect.Click += new System.EventHandler(this.button_Disconnect_Click);
            // 
            // stateLabel
            // 
            this.stateLabel.AutoSize = true;
            this.stateLabel.Location = new System.Drawing.Point(12, 85);
            this.stateLabel.Name = "stateLabel";
            this.stateLabel.Size = new System.Drawing.Size(0, 13);
            this.stateLabel.TabIndex = 7;
            // 
            // colorDialog1
            // 
            this.colorDialog1.AnyColor = true;
            this.colorDialog1.FullOpen = true;
            this.colorDialog1.ShowHelp = true;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.labelState);
            this.groupBox1.Controls.Add(this.Lb_state);
            this.groupBox1.Controls.Add(this.button_Compose);
            this.groupBox1.Controls.Add(this.button_Disconnect);
            this.groupBox1.Controls.Add(this.textBox1);
            this.groupBox1.Controls.Add(this.button_Connect);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(12, 7);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(365, 100);
            this.groupBox1.TabIndex = 26;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Connection";
            // 
            // labelState
            // 
            this.labelState.AutoSize = true;
            this.labelState.Location = new System.Drawing.Point(15, 78);
            this.labelState.Name = "labelState";
            this.labelState.Size = new System.Drawing.Size(35, 13);
            this.labelState.TabIndex = 7;
            this.labelState.Text = "State:";
            // 
            // Lb_state
            // 
            this.Lb_state.AutoSize = true;
            this.Lb_state.Location = new System.Drawing.Point(64, 78);
            this.Lb_state.Name = "Lb_state";
            this.Lb_state.Size = new System.Drawing.Size(0, 13);
            this.Lb_state.TabIndex = 27;
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.btn_start);
            this.groupBox2.Controls.Add(this.label_state);
            this.groupBox2.Controls.Add(this.label_s);
            this.groupBox2.Controls.Add(this.tb_url);
            this.groupBox2.Controls.Add(this.label2);
            this.groupBox2.Controls.Add(this.btn_stop);
            this.groupBox2.Location = new System.Drawing.Point(12, 113);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(365, 102);
            this.groupBox2.TabIndex = 28;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Camera Server Information";
            // 
            // btn_start
            // 
            this.btn_start.Enabled = false;
            this.btn_start.Location = new System.Drawing.Point(188, 70);
            this.btn_start.Name = "btn_start";
            this.btn_start.Size = new System.Drawing.Size(75, 23);
            this.btn_start.TabIndex = 38;
            this.btn_start.Text = "Start";
            this.btn_start.UseVisualStyleBackColor = true;
            this.btn_start.Click += new System.EventHandler(this.btn_start_Click);
            // 
            // label_state
            // 
            this.label_state.AutoSize = true;
            this.label_state.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label_state.Location = new System.Drawing.Point(79, 74);
            this.label_state.Name = "label_state";
            this.label_state.Size = new System.Drawing.Size(0, 13);
            this.label_state.TabIndex = 37;
            // 
            // label_s
            // 
            this.label_s.AutoSize = true;
            this.label_s.Location = new System.Drawing.Point(7, 75);
            this.label_s.Name = "label_s";
            this.label_s.Size = new System.Drawing.Size(35, 13);
            this.label_s.TabIndex = 36;
            this.label_s.Text = "State:";
            // 
            // tb_url
            // 
            this.tb_url.Location = new System.Drawing.Point(124, 26);
            this.tb_url.Name = "tb_url";
            this.tb_url.Size = new System.Drawing.Size(235, 20);
            this.tb_url.TabIndex = 35;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(6, 29);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(112, 13);
            this.label2.TabIndex = 34;
            this.label2.Text = "VideoLAN - VLC URL:";
            // 
            // btn_stop
            // 
            this.btn_stop.Enabled = false;
            this.btn_stop.Location = new System.Drawing.Point(284, 69);
            this.btn_stop.Name = "btn_stop";
            this.btn_stop.Size = new System.Drawing.Size(75, 23);
            this.btn_stop.TabIndex = 29;
            this.btn_stop.Text = "Stop";
            this.btn_stop.UseVisualStyleBackColor = true;
            this.btn_stop.Click += new System.EventHandler(this.btn_stop_Click);
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.tb_client);
            this.groupBox3.Location = new System.Drawing.Point(12, 472);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(365, 87);
            this.groupBox3.TabIndex = 29;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Connected Clients";
            // 
            // tb_client
            // 
            this.tb_client.Location = new System.Drawing.Point(3, 19);
            this.tb_client.Name = "tb_client";
            this.tb_client.Size = new System.Drawing.Size(356, 62);
            this.tb_client.TabIndex = 0;
            this.tb_client.Text = "";
            // 
            // OriginalViewer
            // 
            this.OriginalViewer.BackColor = System.Drawing.Color.Black;
            this.OriginalViewer.FlipMode = Ozeki.Media.FlipMode.None;
            this.OriginalViewer.FrameStretch = Ozeki.Media.FrameStretch.Uniform;
            this.OriginalViewer.FullScreenEnabled = true;
            this.OriginalViewer.Location = new System.Drawing.Point(12, 221);
            this.OriginalViewer.Name = "OriginalViewer";
            this.OriginalViewer.RotateAngle = 0;
            this.OriginalViewer.Size = new System.Drawing.Size(365, 244);
            this.OriginalViewer.TabIndex = 0;
            this.OriginalViewer.Text = "videoViewerWF1";
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(389, 564);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.stateLabel);
            this.Controls.Add(this.OriginalViewer);
            this.Name = "MainForm";
            this.Text = "Rtsp Streamer";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.groupBox3.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private Ozeki.Media.VideoViewerWF OriginalViewer;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button_Compose;
        private System.Windows.Forms.Button button_Connect;
        private System.Windows.Forms.Button button_Disconnect;
        private System.Windows.Forms.Label stateLabel;
        private System.Windows.Forms.ColorDialog colorDialog1;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Label Lb_state;
        private System.Windows.Forms.Label labelState;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.Button btn_stop;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Button btn_start;
        private System.Windows.Forms.Label label_state;
        private System.Windows.Forms.Label label_s;
        private System.Windows.Forms.TextBox tb_url;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.RichTextBox tb_client;
    }
}


	

Code 2 - GUI example in C#

Related Pages

FAQ

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

  1. 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 to the references of the solution.
    • Please import the missing classes.
  2. Can I connect to more than one stream at the same time?

    If you'd like to connect to more than one stream, you have to open VLC as many times as you want to connect.However, if you use Onvif IP Camera Manager you can easily connect to more than one stream at the same time.