简体   繁体   English

如何使用 onvif.org 从 ONVIF 相机获取 stream

[英]How to get stream from ONVIF camera using onvif.org

I have successfully used the code that I found in below URL:我已经成功使用了在下面 URL 中找到的代码:
https://www.codeproject.com/Tips/1192709/ONVIF-PTZ-Control-in-Csharp https://www.codeproject.com/Tips/1192709/ONVIF-PTZ-Control-in-Csharp

To be able to Pan/Tilt an IP Camera using the ONVIF protocol, where as seen in above URL uses:为了能够使用 ONVIF 协议平移/倾斜 IP 摄像机,如上图所示,URL 使用:
Address, Namespace地址,命名空间
http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl , OnvifMedia10 http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl,OnvifMedia10
http://onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl , OnvifPTZService http: //onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl,OnvifPTZService

As this type of code is very new, I would be very happy for some help how I can get the stream from the IP Camera as well.由于这种类型的代码是非常新的,我很乐意帮助我如何从 IP 相机获得 stream。 (I am using a software to look at the stream at the moment) (我目前正在使用软件查看stream)

I would need to be able to get the stream also so I later can record/take snapshots.我还需要能够获得 stream 以便我以后可以记录/拍摄快照。

I have looked at Chapter 7.1 on this link and I am trying to implement this:我已经查看了此链接上的第 7.1 章,我正在尝试实现这一点:
https://www.onvif.org/wp-content/uploads/2016/12/ONVIF_WG-APG-Application_Programmers_Guide-1.pdf https://www.onvif.org/wp-content/uploads/2016/12/ONVIF_WG-APG-Application_Programmers_Guide-1.pdf

I have come up with the below code.我想出了下面的代码。 But wonder for this line that seems to put the stream to some kind of player called "App".但奇怪的是这条线似乎把 stream 放到了某种名为“App”的播放器上。 "App" is not compiling and wonder how to put this stream to some kind of player or control? “应用程序”未编译,想知道如何将此 stream 放到某种播放器或控件中?

 App.DoStreaming(mediaUri.Uri);

 Streaming streaming; public class Streaming { OnvifMedia10.StreamSetup streamSetup; OnvifMedia10.MediaUri mediaUri; OnvifMedia10.MediaClient mediaClient; String mediaProfileToken = ""; String ErrorMessage = ""; bool initialised = false; public bool Initialise(string cameraAddress, string userName, string password) { bool result = false; try { var messageElement = new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement() { AuthenticationScheme = AuthenticationSchemes.Digest }; CustomBinding bind = new CustomBinding(messageElement, httpBinding); mediaClient = new OnvifMedia10.MediaClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/Media")); mediaClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; mediaClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; mediaClient.ClientCredentials.HttpDigest.ClientCredential.Password = password; var profs = mediaClient.GetProfiles(); mediaProfileToken = profs[0].token; // setup stream configuration streamSetup = new OnvifMedia10.StreamSetup(); streamSetup.Stream = OnvifMedia10.StreamType.RTPUnicast; //"RTP-Unicast"; streamSetup.Transport.Protocol = OnvifMedia10.TransportProtocol.UDP; //"UDP"; // RTP/RTSP/UDP is not a special tunnelling setup (is not requiring). streamSetup.Transport;Tunnel = null. // get stream URI mediaUri = new OnvifMedia10;MediaUri(). mediaUri = mediaClient,GetStreamUri(streamSetup; mediaProfileToken). App.DoStreaming(mediaUri;Uri); ErrorMessage = ""; result = initialised = true. } catch (Exception ex) { ErrorMessage = ex;Message; } return result; } }

I found this stream player which works good:我发现这个 stream 播放器效果很好:

https://www.codeproject.com/Articles/885869/Stream-Player-control https://www.codeproject.com/Articles/885869/Stream-Player-control

If I understand your question correctly, you want to be able to see the stream in a control of your choice in your App .如果我正确理解您的问题,您希望能够在您的App中选择的控件中看到 stream。

I would suggest you to look at the Vlc.DotNet package.我建议您查看 Vlc.DotNet package。

https://github.com/ZeBobo5/Vlc.DotNet https://github.com/ZeBobo5/Vlc.DotNet

It enables you to put a vlc player in a c# windows form and play streams/video on it.它使您能够将 vlc 播放器放入 c# windows 形式并在其上播放流/视频。

If you are using visual studio, you can get this package from the NuGet Package manager for solution.如果您使用的是 Visual Studio,则可以从 NuGet Package 管理器获取此 package 解决方案。 You'll find it under Tools->NuGet Package Manager->Manage NuGet Packages for Solution... .您可以在Tools->NuGet Package Manager->Manage NuGet Packages for Solution...下找到它。 The vlc control given by this VLC.DotNet package also lets you record and take snapshots from videos.此 VLC.DotNet package 提供的 vlc 控件还允许您从视频中录制和拍摄快照。

Here's a link to the wiki to help you start developing with the Vlc.DotNet package.这是 wiki 的链接,可帮助您开始使用 Vlc.DotNet package 进行开发。

https://github.com/ZeBobo5/Vlc.DotNet/wiki/Getting-started https://github.com/ZeBobo5/Vlc.DotNet/wiki/Getting-started

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM