Using NewTek's NDI with MPlatform and MFormats SDK

NDI (Network Device Interface) is an open standard developed by NewTek that allows transmitting video streams via LAN instead of SDI. The protocol aims to connect video applications in the production and post-production areas.


Using NDI from MFormats SDK is very easy. NDI appears as new devices in your renderers and live sources lists similar to Blackmagic, AJA, Stream Labs or any other. Just use it like virtual capture or playout device and have fun.


Play out a stream using NDI


Playing out a stream using NDI is as simple as sending stream to any other renderer. Just use "NDI Renderer" in your devices list.


1. In MPlatform SDK


Check the MRenderer usage article for more details and try Playlist sample application to evaluate NDI without any coding. 




Here is a small code sample demonstrating the logic: 


// Create a renderer object   
MRendererClass m_objRenderer = new MRendererClass(); 

// Set the NDI Renderer device   
m_objRenderer.DeviceSet("renderer", "NDI Renderer", ""); 

// Start renderer.  
// It will receive stream form m_objPlaylist and out put to NDI               
m_objRenderer.ObjectStart(m_objPlaylist);


2. In MFormats SDK


Check the Common MRenderer usage article for more details and try File Playback sample application to evaluate NDI without any coding. 




Here is a small code sample demonstrating the logic:


// Create a renderer object   
MFRendererClass m_objRenderer = new MFRendererClass();   

// Set the NDI Renderer device   
// Please note that I am setting a 0 device assuming that NDI Renderer is the only device in a system.   
// 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, "");   


//... make a separate thread that you will use to process your frames  

// Start feeding your frames to the renderer in a loop                   
m_objRenderer.ReceiverFramePut(pFrame, -1, "");


Receiving an NDI stream

To receive an NDI source stream you should use live source object and initialize the "NDI Receiver" device just like any other capture card. The available NDI sources in your LAN will be represented as input lines of "NDI Receiver" device. Please note that it takes some time for NDI devices to register in network. So you might require refreshing the input lines list few times to get the proper NDI sources list. 

1. In MPlatform SDK

Check MLive Advanced object usage article to get more details and try Writer sample application  to evaluate NDI without any coding. 



Here is a small code sample: 

// Create MFLive Class instance  
MLiveClass m_objMLive = new MLiveClass();  

// Set the NDI Renderer live source   
m_objLive.DeviceSet("video", "NDI Receiver", "");  

// Get Input lines number.   
// The input lines for NDI device represents NDI stream sources available in a network  
int lCount = 0; 
m_objLive.DeviceGetCount(0, "video::line-in", out lCount);  

// Get available NDI stream sources by input lines enumeratng.   
// Please note that NDI requires some time to register the device in a network,  
// so you might heed to refresh the devices list several times until you will see your source    
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);                          
    }  
}  

// Specify required stream source by seting the input line property.   
m_objMLive.DeviceSet("video::line-in", "NIL (MFormats NDI) NDI Source at 192.168.0.3:23545 IP", ""); 

// Start live source object 
 m_objMLive.ObjectStart(null);

2. In MFormats SDK

Check this article to get more details for MFLive object usage and try File Writing C# sample application to evaluate NDI without any coding.



Here is a small code sample demonstrating the logic:

// Create MFLive Class instance 
MFLiveClass m_objLive = new MFLiveClass(); 

// Set the NDI Renderer live source  
// Please note that I am setting a 0 device assuming that NDI Renderer is the first device in a system.  
// If you have multiple live sources, enumerate them with DeviceGetCount and DeviceGetByIndex first to get the NDI live source index  
m_objLive.DeviceSet(eMFDeviceType.eMFDT_Video, 0, ""); 

// Get Input lines number.  
// The input lines for NDI device represents NDI stream sources available in a network 
m_objLive.PropsOptionGetCount("line-in", out lCount); 

// Get available NDI stream sources by input lines enumeratng.  
// Please note that NDI requires some time to register the device in a network, 
// so you might heed to refresh the devices list several times until you will see your source   
if (lCount > 0) 
{ 
    for (int i = 0; i < lCount; i++) 
    { 
        string _pOptions; 
        string _pHelp; 
        m_objLive.PropsOptionGetByIndex("line-in", i, out _pOptions, out _pHelp);                         
    } 
} 

// Specify required stream source by seting the line in property.  
// Let's assume I need to connect to the first streamer 
m_objLive.PropsOptionSetByIndex("line-in", 0); 

//... make a separate thread that you will use to process your frames 

// Start taking frames from your live source in a loop 
m_objLive.SourceFrameGet(-1, out pFrame, "");