Medialooks Knowledge Base Support Center

Contact Us

Overlay frames

You can overlay frames with other frames to make a digital signature, channel logo or picture-in-picture. To make overlay you need at least 2 MFFrames object: one as a base frame and another as an overlay. You also can implement mask for overlay frame with MFormats SDK. The overlay is implemented to base MFFrame object with MFOverlay or MFOverlayRect methods.

When both frames (base and overlay) contains audio the resulting audio is mixed. By default, the audio gain is calculated based on overlay size and transparency of overlay frame. You can specify audio gain with "audio_gain" additional property (e.g. "audio_gain=-10"). The value is in decibels.

Source frame and frame for overlay in this article are:

// grab frame from source
MFFrame sourceFrame;
mySource.SourceFrameGet(-1, out sourceFrame, "");
// create a frame from file
MFFactory frameFactory = new MFFactory();
string pathToLocalFile = @"c:\channelLogo.png";
MFFrame frameToOverlay;
frameFactory.MFFrameCreateFromFile(pathToLocalFile, out frameToOverlay, "");

You can get mask frame from another source or create it from a file the similar way.

Overlay with MFOverlay method

MFOverlay method contains these parameters:

For example, to overlay source frame with logo and place the image at (30, 20) point and make it slightly transparent:

// set parameters for overlay
int overlayX = 30;
int overlayY = 20;
double overlayTransparency = 0.9;
// make overlay
sourceFrame.MFOverlay(frameToOverlay, null, overlayX, overlayY, overlayTransparency, "", "");

Mask frame is not implemented in this example so null is used instead.

MFOverlay method uses the full size of frameToOverlay, so if it is large enough it may overlay too large part of the base frame. To avoid this effect you can resize a new frame with the MFResize method.

Overlay with MFOverlayRect method

You can place overlay to the required rectangle with the MFOverlayRect method. This method contains the following parameters:

For example, to overlay source frame with logo and place the image into the rectangle with width = 160 pixels, height = 120 pixels in point (30, 20):

MF_RECT overlayRect = new MF_RECT();
overlayRect.dblHeight = 120;
overlayRect.dblWidth = 160;
overlayRect.dblPosX = 30;
overlayRect.dblPosY = 20;
overlayRect.eRectType = eMFRectType.eMFRT_Absolute;
double overlayTransparency = 0.9;
eMFOverlayFlags overlayFlags = eMFOverlayFlags.eMFOF_Crop;
pFrame.MFOverlayRect(frameToOverlay, null, ref overlayRect, overlayFlags, overlayTransparency , "", "");

Mask frame is not implemented in this example so null is used instead.

With this method, you can use frames of any size to overlay. The overlay frame is scaled to fill target rectangle according to overlay flags (eMFOverlayFlags enumeration).