【发布时间】:2019-11-14 21:28:05
【问题描述】:
我已成功使用在以下 URL 中找到的代码:
https://www.codeproject.com/Tips/1192709/ONVIF-PTZ-Control-in-Csharp
为了能够使用 ONVIF 协议平移/倾斜 IP 摄像机,如上所示 URL 使用:
地址、命名空间
http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl、OnvifMedia10
http://onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl、 OnvifPTZService
由于这种类型的代码是非常新的,我很乐意帮助我如何从 IP 摄像机获取流。 (我现在正在使用软件查看流)
我还需要能够获取流,以便以后可以录制/拍摄快照。
我已经查看了此链接上的第 7.1 章,我正在尝试实现这一点:
https://www.onvif.org/wp-content/uploads/2016/12/ONVIF_WG-APG-Application_Programmers_Guide-1.pdf
我想出了下面的代码。但奇怪的是这条线似乎把流放到了某种叫做“App”的播放器上。 “应用程序”未编译,想知道如何将此流放入某种播放器或控件?
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;
}
}
【问题讨论】:
标签: c# streaming ip-camera onvif