LVC video input
The LVCVideoInput
class is used to add video sources to the LVC pipeline. The class allows you to set the video parameters and the rectangle of the video source.
You can use any block that has a video output pad. For example, you can use VirtualVideoSourceBlock
to create a virtual video source or SystemVideoSourceBlock
to capture video from the webcam.
Usage
When creating an LVCVideoInput
object, you must specify the MediaBlock to be used as the video data source.
Sample code
Virtual video source
The sample code below shows how to create an LVCVideoInput
object with a VirtualVideoSourceBlock
as the video source.
var rect = new Rect(0, 0, 640, 480);
var name = "Video source [Virtual]";
var settings = new VirtualVideoSourceSettings();
var info = new VideoFrameInfoX(settings.Width, settings.Height, settings.FrameRate);
var src = new LVCVideoInput(name, _compositor, new VirtualVideoSourceBlock(settings), info, rect, true);
if (await _compositor.Input_AddAsync(src))
{
// added successfully
}
else
{
src.Dispose();
}
Screen source
For Desktop platforms, we can capture the screen. The sample code below shows how to create an LVCVideoInput
object with a ScreenSourceBlock
as the video source.
var settings = new ScreenCaptureDX9SourceSettings();
settings.CaptureCursor = true;
settings.Monitor = 0;
settings.FrameRate = new VideoFrameRate(30);
settings.Rectangle = new Rectangle(0, 0, 1920, 1080);
var rect = new Rect(0, 0, 640, 480);
var name = $"Screen source";
var info = new VideoFrameInfoX(settings.Rectangle.Width, settings.Rectangle.Height, settings.FrameRate);
var src = new LVCVideoInput(name, _compositor, new ScreenSourceBlock(settings), info, rect, true);
if (await _compositor.Input_AddAsync(src))
{
// added successfully
}
else
{
src.Dispose();
}
System video source (webcam)
The sample code below shows how to create an LVCVideoInput
object with a SystemVideoSourceBlock
as the video source.
We use the DeviceEnumerator
class to get the video source devices. The first video device will be used as the video source. The first video format of the device will be used as the video format.
VideoCaptureDeviceSourceSettings settings = null;
var device = (await DeviceEnumerator.Shared.VideoSourcesAsync())[0];
if (device != null)
{
var formatItem = device.VideoFormats[0];
if (formatItem != null)
{
settings = new VideoCaptureDeviceSourceSettings(device)
{
Format = formatItem.ToFormat()
};
settings.Format.FrameRate = dlg.FrameRate;
}
}
if (settings == null)
{
MessageBox.Show(this, "Unable to configure video capture device.");
return;
}
var name = $"Camera source [{device.Name}]";
var rect = new Rect(0, 0, 1280, 720);
var videoInfo = new VideoFrameInfoX(settings.Format.Width, settings.Format.Height, settings.Format.FrameRate);
var src = new LVCVideoInput(name, _compositor, new SystemVideoSourceBlock(settings), videoInfo, rect, true);
if (await _compositor.Input_AddAsync(src))
{
// added successfully
}
else
{
src.Dispose();
}