Common Information
MFormats and MPlatform SDKs support SDI board-powered Internal and External keying functionality. For internal keying mode, our SDKs overlay the graphics over an incoming signal. In external keying mode, our SDKs generate both fill and key signals and the keying is made by an external keyer.
By overlaying or splitting graphics using SDI card hardware, you can save a huge amount of computing resources on your system. This process itself is not complicated, but it's needed to know a couple of specific things.
The following articles contain the tables with the SDI cards that support keying:
In this article, we will take a closer look at how to work with keying using a Blackmagic DeckLink Duo 2 SDI card as an example.
Firstly, for both the keying modes is needed to create a string registry key which is named "keying.premultiply_fill" and set it as "true":
Computer\HKEY_CURRENT_USER\SOFTWARE\Medialooks\MFormats\MFRenderer\BMD → keying.premultiply_fill = "true"Secondly, it's needed to map the Blackmagic DeckLink Duo 2 connectors in the following way:
When these preparations are done, connecting SDI inputs, outputs of the board and adding some code are left. We have in-built samples for MFormats and MPlatform SDKs which can be used for quick check the keying functionality. They are located here:
Sample Renderer for MFormats SDK → "C:\Program Files (x86)\Medialooks\MFormats SDK\Samples\C#\Sample Renderer\bin\x64\Debug\Sample Renderer.exe"
Keying Sample for MPlatform SDK → "C:\Program Files (x86)\Medialooks\MPlatform SDK\Samples Basic\C#\Keying Sample\bin\x64\Debug\Keying Sample.exe"
To successfully overlay or split by channels a video or image with transparency using an SDI board, the video, or image itself must contain transparency and the pixel format MUST be set to ARGB32.
MFormats SDK:
M_AV_PROPS m_AV_PROPS = new M_AV_PROPS();
m_AV_PROPS.vidProps.eVideoFormat = eMVideoFormat.eMVF_Custom;
m_AV_PROPS.vidProps.fccType = eMFCC.eMFCC_ARGB32;
// ...
m_objReader.SourceFrameConvertedGet(ref m_AV_PROPS, 0, out MFFrame pFrame, "");MPlatform SDK:
M_VID_PROPS m_VID_PROPS = new M_VID_PROPS();
m_VID_PROPS.eVideoFormat = eMVideoFormat.eMVF_Custom;
m_VID_PROPS.fccType = eMFCC.eMFCC_ARGB32;
m_objFile.FormatVideoSet(eMFormatType.eMFT_Convert, ref m_VID_PROPS);Internal Keying
Internal keying allows you to overlay the graphics over an incoming signal (to overlay video with an alpha channel on top of another video received by an SDI card). And as stated earlier, since graphics overlay performs at the hardware level by the SDI card, no additional computing resources of your system are consumed.
The following image demonstrates how internal keying works:
MFormats SDK:
// Create and initialize a new MFRendererClass instance:
MFRendererClass m_objRenderer = new MFRendererClass();
//Configure the new MFRendererClass instance and set it to the 1st available:
m_objRenderer.DeviceSet(eMFDeviceType.eMFDT_Video, 0, "");
// Get amount of keying options for the device:
m_objRenderer.PropsOptionGetCount("keying", out Int32 nCount);
for (Int32 i = 0; i < nCount; i++)
{
try
{
m_objRenderer.PropsOptionGetByIndex("keying", i, out String strNameKeying, out _);
if (strNameKeying == "internal")
{
m_objRenderer.PropsOptionSetByIndex("keying", i);
break;
}
}
catch {}
}
// Output the frame to the device:
m_objRenderer.ReceiverFramePut(frame, -1, "");MPlatform SDK:
// Create and initialize a new MRendererClass instance:
MRendererClass m_objRenderer = new MRendererClass();
// Set required device name for rendering:
m_objRenderer.DeviceSet("renderer", "DeckLink Duo 2", "");
// Set internal keying feature:
m_objRendererer.DeviceSet("renderer::keying", "internal", "");
// Start output:
m_objRendererer.ObjectStart(m_objFile);External Keying
External keying is a technique for compositing an image (fill) over a background video using an external key signal (key), which defines the transparency of each pixel in the fill image. It's important to understand that external keying receives pre-generated fill and key signals from external sources. It does not generate the key (alpha channel) internally. It uses the external key signal as a mask to overlay the fill image on the background.
Key Components:
- Fill: The color image (e.g., logo, animation) you want to overlay.
- Key: A mask (alpha channel) that determines the transparency for each pixel in the fill image, typically in grayscale.
- Background: The base video on which the fill image will be overlaid.
How It Works:
-
One MLive or two MFLives receives 2 input signals:
One input for the fill signal (RGB color image).
Another input for the key signal (alpha mask).
The key signal is used as a transparency mask.
The fill image is composited over the background video, following the transparency defined by the key.
The result is outputted as the composite video.
It means that in this setup, the graphics are not generated inside the application and they are provided externally. It is called external keying because both the fill and key signals come from an external source, while the SDI card itself handles the compositing.
The codes below demonstrates how to generate fill and key signals for further external keying on the receiver side:
MFormats SDK:
// Create and initialize a new MFRendererClass instance:
MFRendererClass m_objRenderer = new MFRendererClass();
//Configure the new MFRendererClass instance and set it to the 1st available:
m_objRenderer.DeviceSet(eMFDeviceType.eMFDT_Video, 0, "");
// Get amount of keying options for the device:
m_objRenderer.PropsOptionGetCount("keying", out Int32 nCount);
for (Int32 i = 0; i < nCount; i++)
{
try
{
m_objRenderer.PropsOptionGetByIndex("keying", i, out String strNameKeying, out _);
if (strNameKeying == "external")
{
m_objRenderer.PropsOptionSetByIndex("keying", i);
break;
}
}
catch {}
}
// Output the frame to the device:
m_objRenderer.ReceiverFramePut(frame, -1, "");MPlatform SDK:
// Create and initialize a new MRendererClass instance:
MRendererClass m_objRenderer = new MRendererClass();
// Set required device name for rendering:
m_objRenderer.DeviceSet("renderer", "DeckLink Duo 2", "");
// Set internal keying feature:
m_objRendererer.DeviceSet("renderer::keying", "external", "");
// Start output:
m_objRendererer.ObjectStart(m_objFile);How to combine the fill and key signals back into a video with an alpha channel and overlay it onto the background is described in detail in this article.