MFormats SDK: simple playout to devices

MFormats SDK supports playout to a range of professional video devices such as Blackmagic Design, DELTACAST. We plan on adding support for AJA, BlueFish444 and other vendors in the nearest future. This post shows how to play out content to a video device.


Implementing playout is similar to video preview: instead of the MFPreview object we will use the MFRendererClass object. This object supports the IMFDevice interface, so we'll enumerate the available devices in the same way as we would have done with MFLiveClass (the object we use for reading from live sources). We will use IMFReceiver interface to send frames to the MFRenderer object.


We can use the MFReader object to use a file as source (playback of files is described in a separate post).


Let's initialize the renderer object:


MFRendererClass m_objRenderer = new MFRendererClass();


Now let's get all the available output devices in the same way as for live sources:


int nCount = 0;
m_objRenderer.DeviceGetCount(eMFDeviceType.eMFDT_Video, out nCount); // get a number of renderers
if (nCount > 0)
{
	for (int y = 0; y < nCount; y++)
	{
	string strName;
	int _pbBusy;
	m_objRenderer.DeviceGetByIndex(eMFDeviceType.eMFDT_Video, y, out strName, out _pbBusy);
	renderersCombobox.Items.Add(strName); // add device to a combobox's list
	}
	// Choose the 1st available renderer
	renderersCombobox.SelectedIndex = 0;
}


To start the selected device we just need to call:


m_objRenderer.DeviceSet(eMFDeviceType.eMFDT_Video, renderersCombobox.SelectedIndex, "");


After this the device is ready to use. All you need is start sending frames. It doesn't matter if you use a timer or a separated thread to get the MFFrame object. Just add this line to that method:


m_objRenderer.ReceiverFramePut(pFrame, -1, ""); // where pFrame is a MFFrame object that you get from your source.


In the most simple case it looks like this:


m_objMFReader.SourceFrameConvertedGetByTime(ref m_avProps, -1, -1, out pFrame, strParams); // get a frame
m_objRenderer.ReceiverFramePut(pFrame, -1, ""); // send the frame to output


It is very easy to send video to an output device, as well as everything in MFormats SDK. Enjoy MFormats SDK!