Skip to main content

System video source

SystemVideoSourceBlock is used to access webcams and other video capture devices.

Block info

Name: SystemVideoSourceBlock.

Pin directionMedia typePins count
Output videouncompressed video1

Enumerate available devices

Use the DeviceEnumerator.Shared.VideoSourcesAsync() method to get a list of available devices and their specifications: available resolutions, frame rates, and video formats.

The sample pipeline

Sample code

// create pipeline
var pipeline = new MediaBlocksPipeline(true);

// create video source
VideoCaptureDeviceSourceSettings videoSourceSettings = null;

// select the first device
var device = (await DeviceEnumerator.Shared.VideoSourcesAsync())[0];
if (device != null)
{
// select the first format (maybe not the best, but it is just a sample)
var formatItem = device.VideoFormats[0];
if (formatItem != null)
{
videoSourceSettings = new VideoCaptureDeviceSourceSettings(device)
{
Format = formatItem.ToFormat()
};

// select the first frame rate
videoSourceSettings.Format.FrameRate = formatItem.FrameRateList[0];
}
}

// create video source block using the selected device and format
var videoSource = new SystemVideoSourceBlock(videoSourceSettings);

// create video renderer block
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);

// connect blocks
pipeline.Connect(videoSource.Output, videoRenderer.Input);

// start pipeline
await pipeline.StartAsync();

Remarks

You can specify an API to use when enumerating devices. Windows and Linux platforms have multiple APIs, while Android and iOS platforms have only one API.

Platforms

Windows, macOS, Linux, iOS, Android.