IP cameras and network sources
Products: Video Capture SDK .Net
Engines:
VideoCaptureCore
,VideoCaptureCoreX
The SDK supports IP cameras as a source. You can use the following types of IP cameras:
- ONVIF cameras
- RTSP cameras
- HTTP MJPEG cameras
- UDP cameras and streams
- NDI cameras
- SRT servers and cameras
- VNC servers
Universal source for RTSP, RTMP, HTTP and other protocols
- VideoCaptureCore
- VideoCaptureCoreX
// Set source
VideoCapture1.IP_Camera_Source = new IPCameraSourceSettings
{
URL = "url",
Login = "login",
Password = "password",
AudioCapture = true, // true to capture audio, false to ignore audio
Type = VFIPSource.Auto_VLC
};
The type of the source can be set to:
Auto_VLC
- use the VLC engineAuto_FFMPEG
- use the FFMPEG engineAuto_LAV
- use the LAV engine
Custom FFMPEG settings
Using the FFMPEG source, you can set custom parameters using the FFMPEG_CustomOptions property. The avformat_open_input
call will use these parameters in the dictionary when opening a stream.
The sample below shows how to set the rtsp_transport
and timeout
parameters.
VideoCapture1.IP_Camera_Source.FFMPEG_CustomOptions.Add("rtsp_transport", "tcp");
VideoCapture1.IP_Camera_Source.FFMPEG_CustomOptions.Add("timeout", "3000000");
// Add login and password to the address if necessary
var uri = new Uri("some URL");
if (!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(password))
{
uri = new UriBuilder(uri) { UserName = login, Password = password }.Uri;
}
// Create a universal source object. Set renderAudio to true to capture audio, false to ignore audio.
var source = await UniversalSourceSettings.CreateAsync(uri, renderAudio: audio, ignoreMediaInfoReader: true);
// Set the source to the VideoCaptureCoreX object
VideoCapture1.Video_Source = source;
Low-latency MJPEG source
SDK has a special mode for low latency MJPEG streaming. Typically, the latency is less than 100ms.
- VideoCaptureCore
- VideoCaptureCoreX
// Create settings object
var settings = new IPCameraSourceSettings
// Specify URL and credentials
// ...
// Set HTTP MJPEG Low Latency mode
settings.Type = IPSourceEngine.HTTP_MJPEG_LowLatency;
// Set settings to the VideoCaptureCore object
VideoCapture1.IP_Camera_Source = settings;
// Create HTTP MJPEG source settings object
var mjpeg = await HTTPMJPEGSourceSettings.CreateAsync(new Uri(cbIPURL.Text), edIPLogin.Text, edIPPassword.Text);
// Apply settings to the VideoCaptureCoreX object
VideoCapture1.Video_Source = mjpeg;
SRT source
You can play video from SRT server or camera using the SRT source.
- VideoCaptureCoreX
// Create SRT source settings object
var srt = await SRTSourceSettings.CreateAsync("SRT server URL");
// Set the source to the VideoCaptureCoreX object
VideoCapture1.Video_Source = srt;
Network disconnect event
- VideoCaptureCore
The SDK can detect network disconnects and reconnects. To enable this feature, set DisconnectEventInterval
to 5 seconds
or more.
Use the OnNetworkSourceDisconnect
event to handle disconnects.
private void VideoCapture1_OnNetworkSourceDisconnect(object sender, EventArgs e)
{
Invoke((Action)(
async () =>
{
await VideoCapture1.StopAsync();
MessageBox.Show(this, "Network source stopped or disconnected!");
}));
}
VNC source
You can connect to VNC servers and capture video from them.
- VideoCaptureCoreX
// Create VNC source settings object
var vncSettings = new VNCSourceSettings();
// Set the source URL or host and port
if (useHostAndPort)
{
vncSettings.Host = "host";
vncSettings.Port = port;
}
else
{
vncSettings.Uri = "vnc://something";
}
// Set the password
vncSettings.Password = "password";
// Set the source to the VideoCaptureCoreX object
videoCapture.Video_Source = vncSettings;
Visit our GitHub page to get more code samples.