Search code examples
c#cameravideo-streamingrtsponvif

Convert onvif stream to rtsp address in c#


I am developing a project using c#.in my project i should get the camera stream .So i use onvif to get the stream but i faced a problem .some of my camera can't support onvif and they support RTSP,and i have to use rtsp in my project to :

Here is my onvif code to get the camera stream :

          async void StartCameraAfterLogin()
                {
                    //Dooooorbin
                    await ProcessConnect("http://172.16.0.52/onvif/device_service"
            , Properties.Settings.Default.CameraUserName, Properties.Settings.Default.CameraPassword);
                }
      async Task ProcessConnect(string addr, string name, string pass)
            {
                //Release();

                //ctrlInfo.Content = new ProgressControl();

                var account = new System.Net.NetworkCredential(name, pass);

                NvtSessionFactory factory = new NvtSessionFactory(account);

                ////This is syncronouse ui blokking call
                //var session = factory.CreateSession(new Uri(addr);

                try
                {
                    var session = factory.CreateSession(new Uri(addr));
                    ss = session;

                    await FillInfoArea(session);
                }
                catch (Exception err)
                {
                    Algoa.Utilities.Logger.ToDebug(err);
                    //ctrlInfo.Content = new ErrorControl(err);
                }
            }
            string profie;

            private async Task FillInfoArea(INvtSession session)
            {
                var profInfo = new ProfieInfoControl();
                try
                {
                    var streamData = await profInfo.Init(session);

                    //sp.Children.Add(profInfo);
                    profie = profInfo.valueToken.Text;
                    InitVideoControl(streamData.Item1, streamData.Item4, session.credentials);

                    //InitPtzControl(session, streamData.Item2, streamData.Item3);
                }
                catch (Exception err)
                {
                    Algoa.Utilities.Logger.ToDebug(err);
                }

                //ctrlInfo.Content = sp;
            }
 private void InitVideoControl(string suri, System.Windows.Size size, System.Net.NetworkCredential networkCredential)
        {
            InitPlayer(suri, networkCredential, size);
        }
        public void InitPlayer(string videoUri, NetworkCredential account, System.Windows.Size sz = default(System.Windows.Size))
        {
            player = new HostedPlayer();
            playerDisposable.Add(player);

            if (sz != default(System.Windows.Size))
                videoBuff = new VideoBuffer((int)sz.Width, (int)sz.Height);
            else
            {
                videoBuff = new VideoBuffer(720, 576);
            }
            player.SetVideoBuffer(videoBuff);

            MediaStreamInfo.Transport transp = MediaStreamInfo.Transport.Udp;
            MediaStreamInfo mstrInfo = null;
            if (account != null)
            {
                mstrInfo = new MediaStreamInfo(videoUri, transp, new UserNameToken(account.UserName, account.Password));//, transp, null);
            }
            else
            {
                mstrInfo = new MediaStreamInfo(videoUri, transp);
            }

            playerDisposable.Add(
                player.Play(mstrInfo, this)
            );
            InitPlayback(videoBuff, true);

            //{ // playing controls
            //    btnPause.Click += play;
            //    btnResume.Click += play;
            //}
        }

How can i convert my onvif url to rtsp url ?Is there any solution or i should change all part of my code?

I am new in camera stream coding .


Solution

  • I downloaded the OZEKI-SDK

    private IIPCamera _camera;
    private DrawingImageProvider _imageProvider = new DrawingImageProvider();
    private MediaConnector _connector = new MediaConnector();
    private VideoViewerWF _videoViewerWF1;
    
    public Form1()
    {
        InitializeComponent();
    
        // Create video viewer UI control
        _videoViewerWF1 = new VideoViewerWF();
        _videoViewerWF1.Name = "videoViewerWF1";
        _videoViewerWF1.Size = panel1.Size;
        panel1.Controls.Add(_videoViewerWF1);
    
        // Bind the camera image to the UI control
        _videoViewerWF1.SetImageProvider(_imageProvider);
    }
    
    // Connect camera video channel to image provider and start
    private void connectBtn_Click(object sender, EventArgs e)
    {
        _camera = IPCameraFactory.GetCamera("rtsp://192.168.113.150:554/ufirststream", "root", "pass");
        _connector.Connect(_camera.VideoChannel, _imageProvider);
        _camera.Start();
        _videoViewerWF1.Start();
    }
    

    As a another solution i finally used Accord.net library to capture rtsp stream.