Creative an Audio and Video mixer

Butter_coder

New member
Im currenty tring to make a program using the NDI SDK and C++ to make a program that can take two ndi sources one being video and the other being audio, and eventually my goal is to make both sources combine and send out as one source, but im currently unable to get the program to properly recognize the sources on my system and was seeing if anyone had info.
"
#include <Processing.NDI.Lib.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <Windows.h>



int main(){
// Initialize NDI
NDIlib_initialize();

// Create a finder for NDI sources
NDIlib_find_create_t NDI_find_create_desc = {};
NDI_find_create_desc.p_extra_ips = nullptr;
NDI_find_create_desc.show_local_sources = true;
NDI_find_create_desc.p_groups = nullptr; // Optional, to search only in specific groups

NDIlib_find_instance_t pNDI_find = NDIlib_find_create_v2(&NDI_find_create_desc);
if (!pNDI_find) {
std::cout << "Failed to create a finder";
return false;
}

// Wait for sources to be found
NDIlib_find_wait_for_sources(pNDI_find, 5000);

// Get the number of sources found
uint32_t num_sources = 0;
const NDIlib_source_t* p_senders = NDIlib_find_get_current_sources(pNDI_find, &num_sources);//make sure we referebce here or it wont work


std::vector<std::string> video_source_names;
std::vector<std::string> audio_source_names;
// Store the names of the sources found

for (uint32_t i = 0; i < num_sources; i++) //maybe another method to connect i?
{
// Get the current source
const NDIlib_source_t* pSource = NDIlib_find_get_current_sources(pNDI_find, &i);

// Check if the source has a valid video stream
if (pSource->p_ndi_name && pSource->p_url_address) //need to find correct path so it can connect
{
// Store the name of the current video source
video_source_names.push_back(pSource->p_ndi_name);
}

// Check if the source has a valid audio stream
if (pSource->p_ndi_name && pSource->p_url_address)
{
// Store the name of the current audio source
audio_source_names.push_back(pSource->p_ndi_name);
}
}

// Print the names of the video sources found
std::cout << "Found " << video_source_names.size() << " video sources:" << std::endl;
for (uint32_t i = 0; i < video_source_names.size(); i++)
{
std::cout << i + 1 << ". " << video_source_names << std::endl;
}

// Ask the user to select a video source
std::cout << "Enter the number of the video source you want to use: ";
uint32_t selected_video_source_idx;
std::cin >> selected_video_source_idx;

// Print the names of the audio sources found
std::cout << "Found " << audio_source_names.size() << " audio sources:" << std::endl;
for (uint32_t i = 0; i < audio_source_names.size(); i++)
{
std::cout << i + 1 << ". " << audio_source_names << std::endl;
}

// Ask the user to select an audio source
std::cout << "Enter the number of the audio source you want to use: ";
uint32_t selected_audio_source_idx;
std::cin >> selected_audio_source_idx;


// Create an NDI sender
NDIlib_send_create_t NDI_send_create_desc = {};
NDI_send_create_desc.p_ndi_name = "Combined Source";
NDIlib_send_instance_t pNDI_send = NDIlib_send_create(&NDI_send_create_desc);

if (!pNDI_send) {
std::cout << "Failed to create an NDI sender" << std::endl;
return false;
}



return 0;
}

"
 
You're using `NDIlib_find_get_current_sources` wrong. It returns a pointer to an ARRAY of sources, and (in the num_sources param) the size of that array.

So, just call it once, then iterate over the returned array. Something like this.

C++:
uint32_t num_sources = 0;

NDIlib_source_t* p_senders = NDIlib_find_get_current_sources(pNDI_find, &num_sources);//make sure we referebce here or it wont work

for (uint32_t i = 0; i < num_sources; i++)
{
  // Get the current source
  const NDIlib_source_t* pSource = &p_senders[i];
    ... etc ...
}
 
Back
Top