Skip to main content

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:

Universal source for RTSP, RTMP, HTTP and other protocols

// 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 engine
  • Auto_FFMPEG - use the FFMPEG engine
  • Auto_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");

Low-latency MJPEG source

SDK has a special mode for low latency MJPEG streaming. Typically, the latency is less than 100ms.

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

SRT source

You can play video from SRT server or camera using the SRT source.

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

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.


// 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.