This article is about how to process playback of files in MPlatform SDK in a way of MFormats SDK. Frame by frame.
The MFormats-like approach is based on a separated thread where you get a frame from a source, process it, and send the frame to an output device or a preview.
In MPlatform SDK, you should configure source and output objects as usual. The main difference here is that you should create a new thread to process frames.
Thread body = new Thread(FrameProcessing);
body.Start();
Where the FrameProcessing method looks like:
private void FrameProcessing()
{
while (isThread) // isThread is a flag that is true when playback is running
{
try
{
MFrame sourceFrame;
// get frame from source object
m_objFile.SourceFrameGetEx(ref cookies, -1, out sourceFrame, 0);
try
{
// send result frame to preview
m_objPreview.ReceiverPutFrame("", sourceFrame);
}
catch {}
if (chbOutput.Checked)
{
// send result frame to an output device
try
{
m_objRenderer.ReceiverPutFrame("", sourceFrame);
}
catch {}
}
Marshal.ReleaseComObject(sourceFrame);
}
catch (Exception)
{
cookies = 0;
continue;
}
}
}
Between the SourceFrameGetEx and ReceiverPutFrame methods, you can process the received frame with plugins or other methods available for frames - frame overlay, text overlay, etc.
For example, an overlay:
if (m_overlayFrame != null)
{
// Need clone because input frames can have reference to previous frame (e.g. convert 25p -> 30p);
// cloned frame will be clear without previous overlay.
MFrame cloneFrame;
sourceFrame.FrameClone(out cloneFrame, eMFrameClone.eMFC_Full, eMFCC.eMFCC_Default);
// overlay frame with image
cloneFrame.FrameOverlay(m_overlayFrame, 50, 50, 0.5, "");
// Release source frame and replace it cloned frame
Marshal.ReleaseComObject(sourceFrame);
sourceFrame = cloneFrame;
}