代码之家  ›  专栏  ›  技术社区  ›  Ehsan Akbar

在c中将onvif流转换为rtsp地址#

  •  0
  • Ehsan Akbar  · 技术社区  · 7 年前

    我正在用c语言开发一个项目。在我的项目中,我应该获得相机流。所以我使用onvif来获取流,但我遇到了一个问题。我的一些相机不支持onvif,它们支持RTSP,我必须在我的项目中使用RTSP来:

    以下是我的onvif代码,用于获取摄像机流:

              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;
                //}
            }
    

    如何将onvif url转换为rtsp url?有什么解决方案吗?或者我应该更改代码的所有部分?

    我是新的摄像机流编码。

    1 回复  |  直到 7 年前
        1
  •  -2
  •   Ehsan Akbar    7 年前

    我下载了 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();
    }
    

    作为另一种解决方案,我最终使用了Accord。net库来捕获rtsp流。