ONVIF cameras
Products: Video Capture SDK .Net
Engines:
VideoCaptureCore
,VideoCaptureCoreX
ONVIF is a standard for physical IP cameras. Many cameras and NVRs support the ONVIF protocol. It is a good idea if you need to support many cameras.
How to enumerate ONVIF cameras
Enumerate ONVIF sources and add them to a combo box.
- VideoCaptureCore
- VideoCaptureCoreX
var uris = await VideoCapture1.IP_Camera_ONVIF_ListSourcesAsync(null, null);
foreach (var uri in uris)
{
cbIPCameraURL.Items.Add(uri);
}
var uris = await DeviceEnumerator.Shared.ONVIF_ListSourcesAsync(TimeSpan.FromSeconds(2), null);
foreach (var uri in uris)
{
cbIPCameraURL.Items.Add(uri);
}
How can I get camera capabilities and information?
Create a new camera object and connect it to the camera:
- VideoCaptureCore
- VideoCaptureCoreX
var onvifControl = new ONVIFControl();
var result = await onvifControl.ConnectAsync("http://192.168.1.2/onvif/device_service", "username", "password");
if (!result)
{
onvifControl = null;
Debug.WriteLine("Unable to connect to the ONVIF camera.");
return;
}
var onvifDevice = new ONVIFDevice();
var result = await onvifDevice.ConnectAsync("http://192.168.1.2/onvif/device_service", "username", "password");
if (!result)
{
onvifControl = null;
Debug.WriteLine("Unable to connect to the ONVIF camera.");
return;
}
Get camera information:
- VideoCaptureCore
- VideoCaptureCoreX
var deviceInfo = await onvifControl.GetDeviceInformationAsync();
if (deviceInfo != null)
{
Debug.WriteLine($"Model {deviceInfo.Model}, Firmware {deviceInfo.Firmware}");
}
var deviceInfo = onvifDevice.GetDeviceInformation();
if (deviceInfo != null)
{
Debug.WriteLine($"Model {deviceInfo.Model}, Firmware {deviceInfo.Firmware}");
}
Get profiles:
- VideoCaptureCore
- VideoCaptureCoreX
var profiles = await onvifControl.GetProfilesAsync();
foreach (var profile in profiles)
{
Debug.WriteLine($"{profile.Name}");
}
var profiles = await onvifDevice.Media.GetProfilesAsync();
if (profiles != null)
{
foreach (var profile in profiles)
{
Debug.WriteLine($"Profile {profile.Name}, {profile.token}");
}
}
Get video RTSP URL to connect:
- VideoCaptureCore
- VideoCaptureCoreX
// Get URL using the profile index
var url = await onvifControl.GetVideoURLAsync(0);
// Get endpoints
var endPoints = onvifDevice.MediaEndpoints;
if (endPoints.Length > 0)
{
// Get URL using the profile index
var rtspUri = endPoints[0].Uri.Uri;
if (rtspUri != null)
{
uri = new Uri(rtspUri);
}
}
Retrieve PTZ ranges (optional):
- VideoCaptureCore
- VideoCaptureCoreX
var ranges = await onvifControl.PTZ_GetRangesAsync();
var ranges = onvifDevice.PTZ.GetRanges();
Visit our GitHub page to get more code samples.