This tutorial plays a file to an output device with MFRenderer: an SDI card, an NDI output or another
supported renderer. It uses the project and the reader from MFormats 1: Playing a file.
Choose the device and the output
private readonly MFRendererClass m_renderer = new MFRendererClass();
private void FillRenderers()
{
m_renderer.DeviceGetCount(eMFDeviceType.eMFDT_Video, out int count);
for (int i = 0; i < count; i++)
{
m_renderer.DeviceGetByIndex(eMFDeviceType.eMFDT_Video, i, out string name, out int busy);
rendererBox.Items.Add(busy != 0 ? name + " (busy)" : name);
}
}
private void RendererBox_SelectedIndexChanged(object sender, EventArgs e)
{
m_renderer.DeviceSet(eMFDeviceType.eMFDT_Video, rendererBox.SelectedIndex, "");
// Output lines of the device, for example the SDI connectors of a card
outputBox.Items.Clear();
m_renderer.PropsOptionGetCount("line-out", out int lines);
for (int i = 0; i < lines; i++)
{
m_renderer.PropsOptionGetByIndex("line-out", i, out string line, out string help);
outputBox.Items.Add(line);
}
}
private void OutputBox_SelectedIndexChanged(object sender, EventArgs e)
{
m_renderer.PropsOptionSetByIndex("line-out", outputBox.SelectedIndex);
}
Give the device frames in its format
An output sends a fixed video format, for example 1080i at 50 fields per second. Ask the reader for frames already
converted to that format with SourceFrameConvertedGet: the reader converts the picture size, the scan and the
frame rate. The renderer takes one frame per frame period of the output, so ReceiverFramePut with
-1 waits for the device and the loop runs at the rate of the output.
private void OutputLoop(CancellationToken token)
{
var format = new M_AV_PROPS();
format.vidProps.eVideoFormat = eMVideoFormat.eMVF_HD1080_50i;
while (!token.IsCancellationRequested)
{
m_reader.SourceFrameConvertedGet(ref format, -1, out MFFrame frame, "");
try
{
m_renderer.ReceiverFramePut(frame, -1, ""); // waits for the output
m_preview.ReceiverFramePut(frame, 0, ""); // optional preview, does not wait
}
finally
{
Marshal.ReleaseComObject(frame);
}
}
}
The same frame can go to several receivers. Give the waiting role to one of them (here the device) and put the frame to
the others with a zero wait, otherwise the loop runs at the slowest clock. When the form closes, stop the loop, call
m_renderer.DeviceClose() and release the objects.
Next steps
- Record what you play or capture: MFormats 4: Recording to a file.
- The SDK sample
Sample Renderersends a file to several devices at once.
Still have questions?
Tell us what didn’t work or what you’d like clarified.