Play out a stream using NDI
Playing out a stream using NDI is similar to sending a stream to any other renderer. Just use "NDI Renderer" in your devices list.
MPlatform SDK
// Create a renderer object
MRendererClass m_objRenderer = new MRendererClass();
// Set the NDI Renderer device
m_objRenderer.DeviceSet("renderer", "NDI Renderer", "");
// Start renderer.
// It receives a stream from m_objPlaylist (MPlaylist) and outputs it to NDI.
m_objRenderer.ObjectStart(m_objPlaylist);MFormats SDK
// Create a renderer object
MFRendererClass m_objRenderer = new MFRendererClass();
// Set the NDI Renderer device.
// This example assumes NDI Renderer is device 0.
// If you have multiple renderers, enumerate them with DeviceGetCount
// and DeviceGetByIndex first to get the NDI renderer index.
m_objRenderer.DeviceSet(eMFDeviceType.eMFDT_Video, 0, "");
// Run frame processing on a separate worker thread.
MFFrame pFrame;
mySource.SourceFrameGet(-1, out pFrame, "");
// Send frames to the renderer in your processing loop.
m_objRenderer.ReceiverFramePut(pFrame, -1, "");By default, an output stream name has the following structure:
[Source_Machine_Name] (Stream_Name)
For example, "MyPC (MFormats NDI)".
Source_Machine_Name is the name of the source PC, and Stream_Name is the actual name of the stream. By default, Stream_Name = MFormats NDI. To change this, set an output line for the renderer object.
MPlatform SDK
m_objRenderer.DeviceSet("renderer::line-out", "My Custom Name", "");MFormats SDK
m_objRenderer.PropsSet("line-out", "My Custom Name");Receiving an NDI stream
To receive an NDI source stream, use a live source object and initialize the "NDI Receiver" device just like any other capture card. The available NDI sources in your LAN are represented as input lines of the device.
NDI sources take some time to register on the network. You may need to refresh the input lines list several times before the required source appears.
MPlatform SDK
// Create an MLive instance.
MLiveClass m_objMLive = new MLiveClass();
// Select the NDI Receiver live source.
m_objMLive.DeviceSet("video", "NDI Receiver", "");
// Input lines represent NDI sources available on the network.
int lCount = 0;
m_objMLive.DeviceGetCount(0, "video::line-in", out lCount);
// Enumerate the sources. Refresh this list if your source has not appeared.
if (lCount > 0)
{
for (int i = 0; i < lCount; i++)
{
string strName;
string strDesc;
m_objMLive.DeviceGetByIndex(0, "video::line-in", i,
out strName, out strDesc);
}
}
// Replace this placeholder with the required strName returned above.
string selectedSourceName = "SOURCE NAME FROM ENUMERATION";
m_objMLive.DeviceSet("video::line-in", selectedSourceName, "");
// Start the live source.
m_objMLive.ObjectStart(null);MFormats SDK
// Create an MFLive instance.
MFLiveClass m_objLive = new MFLiveClass();
// Select the NDI Receiver device.
// This example assumes NDI Receiver is device 0.
// If you have multiple live sources, enumerate them with DeviceGetCount
// and DeviceGetByIndex first to get the NDI receiver index.
m_objLive.DeviceSet(eMFDeviceType.eMFDT_Video, 0, "");
// Input lines represent NDI sources available on the network.
int lCount;
m_objLive.PropsOptionGetCount("line-in", out lCount);
// Enumerate sources. Refresh this list if your source has not appeared.
if (lCount > 0)
{
for (int i = 0; i < lCount; i++)
{
string sourceName;
string sourceHelp;
m_objLive.PropsOptionGetByIndex("line-in", i,
out sourceName, out sourceHelp);
}
}
// Select the required source. This example selects the first source.
// Call this only after enumeration has returned at least one source.
m_objLive.PropsOptionSetByIndex("line-in", 0);
// Run frame processing on a separate worker thread.
// Get frames from the live source in your processing loop.
MFFrame pFrame;
m_objLive.SourceFrameGet(-1, out pFrame, "");Audio format across an NDI connection
The audio format supplied to an NDI renderer does not determine the sample representation returned by an NDI receiver. The SDK converts outgoing audio to the floating-point format used by the NDI audio interface. By default, the SDK receiver returns interleaved 32-bit floating-point audio.
For example, a source can supply 16-bit integer audio to the renderer while the receiving MLive or MFLive object exposes 32-bit floating-point audio. This is an expected format conversion. It does not mean that the original recording has gained additional precision.
In M_AUD_PROPS.nBitsPerSample, -32 means 32-bit floating point, while 32 means 32-bit integer. Check this field before interpreting an audio buffer; bit depth alone does not identify the sample representation.
Reading the received audio format
With MFormats, call MFAVPropsGet on a received frame and inspect M_AV_PROPS.audProps. With MPlatform, use FormatAudioGet on the live object with eMFT_Input to inspect its input audio format. If your application also applies conversion, inspect the resulting frame to determine the format passed to the next processing stage.
The following table covers all four fields of M_AUD_PROPS. Values returned by a format query describe the audio; editing a local copy does not convert existing samples. Configure conversion through the SDK conversion methods.
| Public field | Type / units | Meaning | Use |
|---|---|---|---|
nChannels |
Integer; channel count | Number of audio channels. In a format request, -1 means no audio and 0 means default audio; the other audio fields are ignored for those two values. | Read from received properties. Set a positive count when requesting a specific conversion format. |
nSamplesPerSec |
Integer; samples per second (Hz) | Audio sample rate, for example 48000. | Read from received properties or specify the required sample rate in a conversion request. |
nBitsPerSample |
Integer; bits and sample representation | The general SDK format contract defines 16, 20, 24 and 32 for integer samples, and -32 for 32-bit float. The NDI receiver's native audio selection is 16-bit integer or 32-bit float. | Read to interpret received samples. Select the NDI receiver representation with ndi_audio_16bit, or request a supported format through SDK conversion. |
nTrackSplitBits |
Integer; bit mask | SDK track-boundary information. Bit n marks channel n as the last channel of a track, using zero-based channel numbering. Zero means no track-boundary information. | Read as audio-layout metadata. This field does not select NDI sample depth. |
Receiving 16-bit integer audio
Set the configurable Boolean receiver property ndi_audio_16bit to true when your downstream processing requires 16-bit integer samples. Its default is false, which selects 32-bit float. Apply the setting to the live receiver after selecting the NDI Receiver device and before starting frame reception. This controls the SDK receiver's audio output representation; it does not change the sender's NDI stream.
The examples below use the live objects configured in the receiving examples above. In MPlatform, insert the setting before ObjectStart; in MFormats, insert it before the first frame retrieval.
MPlatform SDK
// The NDI Receiver device has already been selected.
m_objMLive.PropsSet("device::ndi_audio_16bit", "true");
string configuredValue;
m_objMLive.PropsGet("device::ndi_audio_16bit", out configuredValue);
// After selecting the input line:
m_objMLive.ObjectStart(null);
// Query after reception has established the input format.
M_AUD_PROPS audio;
int formatIndex;
string formatName;
m_objMLive.FormatAudioGet(eMFormatType.eMFT_Input,
out audio, out formatIndex, out formatName);MFormats SDK
// The NDI Receiver device and input line have already been selected.
m_objLive.PropsSet("ndi_audio_16bit", "true");
string configuredValue;
m_objLive.PropsGet("ndi_audio_16bit", out configuredValue);
MFFrame receivedFrame = null;
try
{
// Wait up to one second; SDK wait values use 100-nanosecond units.
m_objLive.SourceFrameGet(10000000, out receivedFrame, "");
if (receivedFrame != null)
{
M_AV_PROPS actual;
int audioSamples;
receivedFrame.MFAVPropsGet(out actual, out audioSamples);
System.Console.WriteLine(
"Channels={0}, Rate={1} Hz, Bits={2}, Samples/channel={3}",
actual.audProps.nChannels,
actual.audProps.nSamplesPerSec,
actual.audProps.nBitsPerSample,
audioSamples);
// Process this frame while it is still owned by this scope.
}
}
finally
{
if (receivedFrame != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(receivedFrame);
}Check the format of a frame containing audio, rather than relying only on property readback. If additional conversion is applied, that conversion can change the final format. Handle frame-retrieval errors and timeouts in your application's worker loop, and release every received frame after processing.
Audio levels and other receiver settings
ndi_reference_level is a configurable audio reference level in integer dB, with a default of 0. It specifies the headroom above the NDI reference level (+4 dBu) represented by full-scale integer audio. On float reception, the SDK applies the corresponding level adjustment. Converting an NDI signal with levels above the integer range to 16-bit audio can cause clipping; changing this setting also changes the resulting signal level.
ndi_audio_thread is a configurable Boolean setting, disabled by default, for processing audio on a separate thread during audio/video reception. It does not select the sample representation. See the existing input settings table in NDI properties for these and other NDI controls.
To request a different sample rate, channel count, or downstream sample representation, use SourceFrameConvertedGet in MFormats or FormatAudioSet with eMFT_Convert in MPlatform. See Converting source video and audio formats for conversion examples. Such conversion changes the SDK output supplied to your application; the NDI renderer still prepares floating-point audio for transmission.
Important note: In the Video SDKs it is not possible to configure or control the NDI decoder behavior.
This is because newer versions of NDI and NDI-HX manage decoding automatically. The system decides how to decode the stream on its own, based on the use case and available hardware. External settings or registry keys can no longer change this behavior.
In modern NDI and NDI-HX versions, hardware acceleration is usually enabled automatically when it is beneficial, so manual control is not available anymore.
Still have questions?
Tell us what didn’t work or what you’d like clarified.