Capture device (Frame grabber)

In order to use capture device as a video source, the following configuration steps should be done:
- Select capture device
- Configure video encoder parameters
- Add video PID to multiplexer
- Start processing

Finding available capture devices

To get a list of existing capture devices, use ScanForVideoCaptureDevices() method:

var captureDevices = m_KlvInjector.ScanForVideoCaptureDevices();

The Scan function will return a list ( List < CaptureDeviceInfo > ) of available devices.

CaptureDeviceInfo
{
    public string Name;
    public string DevicePath;
}

For example:

{    
    Name: "USB Video"  
    DevicePath: "\\\\?\\usb#vid_534d&pid_2109&mi_00#6&ed3caea&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global"
}

This information should be used for capture device selection:

Selecting capture device and configuring video encoder

Use RawVideoFramePropsWr2 for video encoder configuration and capture device selection:

For example, select first capture device (from scan results obtained previously)


  var m_CaptureRawVideoFrameProps = new RawVideoFramePropsWr2();
  m_CaptureRawVideoFrameProps.CaptureInput = captureDevices[0];

Next, let's configure video encoder:


 // Selecting VideoFrameType.NONE will result in highest available format.
 m_CaptureRawVideoFrameProps.RawVideoFrameType = VideoFrameType.YV12;

 // Select resolution (or skip it, to get the native)
 m_CaptureRawVideoFrameProps.Width = 1280;
 m_CaptureRawVideoFrameProps.Height = 720;

 m_CaptureRawVideoFrameProps.EncodingParams = new EncoderConfigParamsWr();
 m_CaptureRawVideoFrameProps.EncodingParams.Profile = ProfileWr.MainProfile;
 m_CaptureRawVideoFrameProps.EncodingParams.FrameRate = 30;

 m_CaptureRawVideoFrameProps.EncodingParams.BitRate = 2000000;

If you set Width and Width to 0, the native resolution will be used.

Adding video PID to multiplexer

The last step is to add the video PID along with the video encoding parameters configuration to the mux:

 m_KlvInjector.Init();
  // Should be called after init, otherwise the internal counters queue will be cleared.
 m_KlvInjector.AddVideoPidToOutput(0x1E1, m_CaptureRawVideoFrameProps);

That's it. KlvInjector is now ready to use a frame grabber as a video source. Let's start processing.


 m_KlvInjector.Start();

Video preview

Just as with stream or file source, KlvInjector can render video on the internally created or on the external window (passed with HWND).


  m_KlvInjector.RenderVideo = true;

Processing frame before encoding.

By default, video frames are passed from a frame grabber to encoder directly, as soon as they arrive. It is possible however to do a preprocessing on the video, before the encoding. You can do any frame processing tasks, like video overlay, picture processing, mix, etc. For this to be done, you should configure KlvInjector for frame delivery, process frames, and push them to the encoder.

RawVideoFramePropsWr2 configuration contains a flag CanEncodeCapturedVideo (set to true by default). Setting it to false, will disable automatic frame transfer. It is the application's responsibility now to provide video frames at the correct rate (and with correct timestamps).

Low Latency mode

If you need to achieve a low latency streaming, please see the guide on how to configure your Injector:

See more info on Low latency configuration