Medialooks Knowledge Base Support Center

Contact Us

Input and output video with NDI

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 form m_objPlaylist (MPlaylist) and out put to NDI               
m_objRenderer.ObjectStart(m_objPlaylist);

MFormats SDK

// 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 use to process your frames  
MFFrame pFrame;
mySource.SourceFrameGet(-1, out pFrame, "");

// Send the frame to the renderer in a loop                   
m_objRenderer.ReceiverFramePut(pFrame, -1, "");

Receiving an NDI stream

To receive an NDI source stream you should 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. 

Please note that it takes some time for NDI devices to register in a network. So you might require refreshing the input lines list few times to get the proper NDI sources list. 

MPlatform SDK

// 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);

MFormats SDK
// 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, "");