### Run ndi-python examples Source: https://github.com/buresu/ndi-python/blob/master/README.md Clone the repository, navigate to the example directory, install dependencies, and run the find.py example script. ```bash git clone https://github.com/buresu/ndi-python.git cd ndi-python/example pip install -r requirements.txt python find.py ``` -------------------------------- ### AudioFrameV2 Example Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-frames.md Example demonstrating how to create and set data for an AudioFrameV2 object. ```APIDOC ## AudioFrameV2 Example ### Description Example demonstrating how to create and set data for an AudioFrameV2 object. ### Code Example ```python import numpy as np import NDIlib as ndi # Create a 2-channel audio frame audio = ndi.AudioFrameV2(sample_rate=48000, no_channels=2, no_samples=1024) # Set audio data audio_data = np.random.randn(2, 1024).astype(np.float32) audio.data = audio_data audio.timecode = 0 ``` ``` -------------------------------- ### Install ndi-python Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/quick-start.md Install the ndi-python library using pip. Ensure your Python version and platform are supported. For Linux, Avahi must also be installed and enabled. ```bash pip install ndi-python ``` ```bash # Ubuntu sudo apt install avahi-daemon sudo systemctl enable --now avahi-daemon # Arch sudo pacman -S avahi sudo systemctl enable --now avahi-daemon ``` -------------------------------- ### Install ndi-sdk on Arch Linux Source: https://github.com/buresu/ndi-python/blob/master/README.md Install the NDI SDK package on Arch Linux using the AUR helper 'yay'. ```bash yay -S ndi-sdk ``` -------------------------------- ### Install ndi-python using pip Source: https://github.com/buresu/ndi-python/blob/master/README.md Install the ndi-python package from PyPI. This is the recommended method for supported environments. ```bash pip install ndi-python ``` -------------------------------- ### Install Avahi Daemon (Ubuntu/Debian) Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/configuration.md Install and enable the Avahi daemon for mDNS service discovery on Ubuntu/Debian-based systems. ```bash # Ubuntu/Debian sudo apt install avahi-daemon sudo systemctl enable --now avahi-daemon ``` -------------------------------- ### Install Avahi daemon on Ubuntu Source: https://github.com/buresu/ndi-python/blob/master/README.md Install and enable the Avahi daemon on Ubuntu systems. This is required for NDI source discovery on Linux. ```bash sudo apt install avahi-daemon sudo systemctl enable --now avahi-daemon ``` -------------------------------- ### Get Audio Queue Depth Example Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-framesync.md Demonstrates how to get the current audio queue depth using framesync_audio_queue_depth() and print the result. This is useful for understanding the real-time processing load. ```python depth = ndi.framesync_audio_queue_depth(framesync) print(f"Audio queue depth: {depth}") ``` -------------------------------- ### recv_recording_start Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recording.md Starts recording from the NDI receiver to a specified file or directory. ```APIDOC ## recv_recording_start() ### Description Starts recording from the receiver to a file. ### Method Signature ```python def recv_recording_start(instance: capsule, filename_hint: str) -> bool ``` ### Parameters #### Path Parameters - **instance** (capsule) - Required - The Receiver instance - **filename_hint** (str) - Required - Suggested filename or directory path for the recording ### Return Type - **bool** - Returns `True` if recording started successfully, `False` otherwise. ### Request Example ```python if ndi.recv_recording_start(recv, "/recordings/capture.mov"): print("Recording started") ``` ``` -------------------------------- ### Basic NDI Receiver Example Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/README.md Connect to an NDI source and capture a single video frame. Requires NDI SDK and Avahi daemon (Linux). ```python import NDIlib as ndi if not ndi.initialize(): exit(1) # Find sources ndi_find = ndi.find_create_v2() ndi.find_wait_for_sources(ndi_find, 5000) sources = ndi.find_get_current_sources(ndi_find) if sources: # Create receiver recv = ndi.recv_create_v3() ndi.recv_connect(recv, sources[0]) # Capture video frame_type, video, _, _ = ndi.recv_capture_v2(recv, 5000) if frame_type == ndi.FRAME_TYPE_VIDEO: print(f"Received {video.xres}x{video.yres} video") ndi.recv_free_video_v2(recv, video) ndi.recv_destroy(recv) di.find_destroy(ndi_find) di.destroy() ``` -------------------------------- ### Create and Configure VideoFrameV2 Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-frames.md Example of creating a VideoFrameV2 with specific resolution and setting its video data, FourCC format, frame rate, and frame rate denominator. ```python import numpy as np import NDIlib as ndi # Create a frame with specific resolution frame = ndi.VideoFrameV2(xres=1920, yres=1080) # Set video data from numpy array img = np.zeros((1080, 1920, 4), dtype=np.uint8) # 1080p RGBA frame.data = img frame.FourCC = ndi.FOURCC_VIDEO_TYPE_BGRX frame.frame_rate_N = 24000 frame.frame_rate_D = 1001 # 23.976 fps ``` -------------------------------- ### Install Avahi daemon on Arch Linux Source: https://github.com/buresu/ndi-python/blob/master/README.md Install and enable the Avahi daemon on Arch Linux systems. This is required for NDI source discovery on Linux. ```bash sudo pacman -S avahi sudo systemctl enable --now avahi-daemon ``` -------------------------------- ### Start NDI Recording Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recording.md Initiates a recording from the NDI receiver to a specified file path. Provide a filename hint or directory. Returns True on success. ```python if ndi.recv_recording_start(recv, "/recordings/capture.mov"): print("Recording started") ``` -------------------------------- ### Install Targets for NDIlib Source: https://github.com/buresu/ndi-python/blob/master/CMakeLists.txt Installs the NDIlib target and associated runtime libraries or DLLs based on the operating system. ```cmake install( TARGETS NDIlib RUNTIME DESTINATION NDIlib LIBRARY DESTINATION NDIlib ) if(WIN32) install( FILES "${NDI_DIR}/Bin/${NDI_ARCH}/Processing.NDI.Lib.${NDI_ARCH}.dll" "${NDI_LICENSE_DIR}/Processing.NDI.Lib.Licenses.txt" DESTINATION NDIlib ) elseif(APPLE) install( FILES "${NDI_LIBRARY_DIR}/libndi.dylib" "${NDI_LICENSE_DIR}/libndi_licenses.txt" DESTINATION NDIlib ) elseif(UNIX) file(GLOB DLL "${NDI_LIBRARY_DIR}/libndi.so*") install( FILES ${DLL} "${NDI_LICENSE_DIR}/libndi_licenses.txt" DESTINATION NDIlib ) endif() ``` -------------------------------- ### Get Tally State Example Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-send.md Demonstrates how to get the tally state from receivers. Initializes a Tally object and checks if the state was updated within the specified timeout. ```python tally = ndi.Tally() if ndi.send_get_tally(send, tally, 1000): print(f"On program: {tally.on_program}, On preview: {tally.on_preview}") ``` -------------------------------- ### Build ndi-python from source Source: https://github.com/buresu/ndi-python/blob/master/README.md Clone the repository and install the ndi-python package using pip. This command builds the package from the source code. ```bash git clone https://github.com/buresu/ndi-python.git cd ndi-python pip install . ``` -------------------------------- ### Receive Audio Frames Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/quick-start.md Capture audio frames using NDI Python. This example demonstrates how to initialize NDI, set up a receiver (assuming connection to a source), and continuously capture and process audio frames. ```python import NDIlib as ndi if not ndi.initialize(): exit(1) # Setup receiver (see Receiving Video section) # ... (setup code to get recv instance connected to a source) try: while True: frame_type, _, audio, _ = ndi.recv_capture_v2( recv, 5000, want_video=False, want_audio=True, want_metadata=False ) if frame_type == ndi.FRAME_TYPE_AUDIO: print(f"Audio frame: {audio.no_channels} channels, " f"{audio.no_samples} samples @ {audio.sample_rate}Hz") # Access raw audio data audio_data = audio.data # numpy array (channels, samples) print(f"Audio data shape: {audio_data.shape}") ndi.recv_free_audio_v2(recv, audio) except KeyboardInterrupt: pass ndi.recv_destroy(recv) di.destroy() ``` -------------------------------- ### Get NDI Library Version Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-initialization.md Returns the version string of the NDI library. Useful for checking compatibility. ```python version = ndi.version() print(f"NDI Version: {version}") ``` -------------------------------- ### Build ndi-python with explicit NDI SDK path Source: https://github.com/buresu/ndi-python/blob/master/README.md Install the ndi-python package from source, explicitly setting the NDI SDK directory using CMAKE_ARGS. This is useful if the SDK is not in a default location. ```bash CMAKE_ARGS="-DNDI_SDK_DIR=/path/to/ndisdk" pip install . ``` -------------------------------- ### Send Video Stream Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/quick-start.md Broadcast a video stream using NDI Python. This example initializes NDI, creates a sender, configures a video frame, and sends a sequence of frames with changing image data. ```python import numpy as np import NDIlib as ndi if not ndi.initialize(): exit(1) # Create sender send_create = ndi.SendCreate(p_ndi_name="Python Sender") send = ndi.send_create(send_create) if send is None: print("Failed to create sender") exit(1) # Create and configure a video frame video_frame = ndi.VideoFrameV2() video_frame.FourCC = ndi.FOURCC_VIDEO_TYPE_BGRX # Generate some video data (1920x1080 BGRX) img = np.zeros((1080, 1920, 4), dtype=np.uint8) video_frame.data = img print("Sending video frames...") try: for i in range(300): # Update frame data img.fill(255 if i % 2 else 0) video_frame.data = img # Send the frame ndi.send_send_video_v2(send, video_frame) print(f"Sent frame {i+1}") except KeyboardInterrupt: pass ndi.send_destroy(send) ndi.destroy() ``` -------------------------------- ### Get Receiver Performance Statistics - Python Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recv.md Retrieves performance statistics for the receiver, including total and dropped frames for video, audio, and metadata. ```python def recv_get_performance(instance: capsule) -> tuple[RecvPerformance, RecvPerformance] ``` -------------------------------- ### Create and Use NDI Source Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-source.md Demonstrates how to manually create an NDI Source object for direct connection or use a discovered source from the network. ```python # Manually create a source to connect to a specific IP source = ndi.Source(p_ndi_name="My Camera", p_url_address="192.168.1.100:5961") # Or use a discovered source sources = ndi.find_get_current_sources(ndi_find) if sources: discovered = sources[0] print(f"Connecting to: {discovered.ndi_name}") print(f"Address: {discovered.url_address}") ``` -------------------------------- ### Initialize and Use NDIlib Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/INDEX.md Demonstrates basic initialization and usage of the NDIlib module. Ensure proper initialization before using other NDI functions. ```python import NDIlib as ndi # Use functions and classes ndi.initialize() source = ndi.Source() recv = ndi.recv_create_v3() # ... etc ``` -------------------------------- ### Initialize AudioFrameV3 Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-frames.md Create an AudioFrameV3 instance with specified audio parameters. Ensure correct sample rate, channel count, and sample count for your audio data. ```python import numpy as np import NDIlib as ndi audio = ndi.AudioFrameV3(sample_rate=48000, no_channels=2, no_samples=1024) audio.FourCC = ndi.FOURCC_AUDIO_TYPE_FLTP ``` -------------------------------- ### Discover NDI Sources with Python Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/quick-start.md Initialize the NDI library, create a find instance, and wait for sources to appear on the network. This snippet then lists the names of all discovered NDI sources. ```python import NDIlib as ndi # Initialize the library if not ndi.initialize(): print("Failed to initialize NDI") exit(1) # Create a find instance ndi_find = ndi.find_create_v2() if ndi_find is None: print("Failed to create find instance") exit(1) # Wait for sources and display them print("Searching for NDI sources...") ndi.find_wait_for_sources(ndi_find, 5000) sources = ndi.find_get_current_sources(ndi_find) print(f"Found {len(sources)} sources:") for i, source in enumerate(sources): print(f"{i+1}. {source.ndi_name}") # Clean up di.find_destroy(ndi_find) di.destroy() ``` -------------------------------- ### Create Send Advertiser Instance Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-advertiser.md Initializes a SendAdvertiserCreateV2 object for configuring a sender advertiser. Use this to set up the server URL address. ```python class SendAdvertiserCreateV2: def __init__(self, url_address: str = "") ``` -------------------------------- ### Get Current NDI Sources Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-find.md Get the current list of available NDI sources. This call does not block and returns a list of Source objects, which may be empty. ```python def find_get_current_sources(instance: capsule) -> list[Source] ``` ```python sources = ndi.find_get_current_sources(ndi_find) print(f"Found {len(sources)} sources:") for source in sources: print(f" - {source.ndi_name}") ``` -------------------------------- ### send_listener_get_senders Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Gets the list of all senders known to the server. ```APIDOC ## send_listener_get_senders() ### Description Gets the list of all senders known to the server. ### Method `send_listener_get_senders(instance: capsule) -> list[Sender]` ### Parameters #### Path Parameters - **instance** (capsule) - Required - The SendListener instance ### Return Type `list[Sender]` Returns a list of `Sender` objects. ``` -------------------------------- ### send_listener_get_server_url Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Gets the server URL for the sender listener. ```APIDOC ## send_listener_get_server_url() ### Description Gets the server URL for the sender listener. ### Method `send_listener_get_server_url(instance: capsule) -> str | None` ### Parameters #### Path Parameters - **instance** (capsule) - Required - The SendListener instance ### Return Type `str | None` ``` -------------------------------- ### framesync_audio_queue_depth Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-framesync.md Gets the current queue depth for audio frames. ```APIDOC ## framesync_audio_queue_depth() ### Description Gets the current queue depth for audio frames. ### Parameters - instance (capsule) - The FrameSync instance ### Return Type int Returns the number of audio frames currently queued in the frame sync. ### Example ```python depth = ndi.framesync_audio_queue_depth(framesync) print(f"Audio queue depth: {depth}") ``` ``` -------------------------------- ### Create and Set AudioFrameV2 Data Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-frames.md Demonstrates how to create an AudioFrameV2 instance and populate it with random audio data using NumPy. Ensure the data is float32 and matches the specified channel and sample counts. ```python import numpy as np import NDIlib as ndi # Create a 2-channel audio frame audio = ndi.AudioFrameV2(sample_rate=48000, no_channels=2, no_samples=1024) # Set audio data audio_data = np.random.randn(2, 1024).astype(np.float32) audio.data = audio_data audio.timecode = 0 ``` -------------------------------- ### recv_listener_get_receivers Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Gets the list of all receivers connected to the server. Returns a list of Receiver objects. ```APIDOC ## recv_listener_get_receivers() ### Description Gets the list of all receivers connected to the server. ### Method Python Function ### Parameters #### Path Parameters - **instance** (capsule) - Required - The RecvListener instance ### Return Type `list[Receiver]` Returns a list of `Receiver` objects describing all receivers known to the server. ### Example ```python receivers = ndi.recv_listener_get_receivers(listener) for receiver in receivers: print(f"Receiver: {receiver.name} (UUID: {receiver.uuid})") print(f" Address: {receiver.address}") print(f" Streams: {receiver.streams}") ``` ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/buresu/ndi-python/blob/master/CMakeLists.txt Sets the minimum CMake version, project name and version, module path, C++ standard, and macOS deployment target and architectures. ```cmake cmake_minimum_required(VERSION 3.17) project(NDIlib VERSION 6.3.2.3) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0") set(CMAKE_OSX_ARCHITECTURES "arm64") ``` -------------------------------- ### recv_listener_get_server_url Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Gets the server URL that the listener is connected to. Returns the URL string, or None if not connected. ```APIDOC ## recv_listener_get_server_url() ### Description Gets the server URL that the listener is connected to. ### Method Python Function ### Parameters #### Path Parameters - **instance** (capsule) - Required - The RecvListener instance ### Return Type `str | None` Returns the URL string, or `None` if not connected. ``` -------------------------------- ### Configure NDI Sender Settings Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-send.md Use SendCreate to define the display name, network groups, and clock synchronization for video and audio frames. ```python class SendCreate: def __init__(self, p_ndi_name: str | None = None, p_groups: str | None = None, clock_video: bool = True, clock_audio: bool = True) ``` ```python send_create = ndi.SendCreate(p_ndi_name="My Sender", p_groups="Production") send_create.clock_video = True ``` -------------------------------- ### send_get_no_connections Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-send.md Gets the number of active receiver connections for a given sender instance. It allows specifying a timeout for the operation. ```APIDOC ## send_get_no_connections() ### Description Gets the number of active receiver connections. ### Parameters #### Path Parameters - **instance** (capsule) - Required - The Sender instance - **timeout_in_ms** (int) - Required - Maximum time to wait in milliseconds ### Return Type `int` Returns the number of connected receivers. ### Example ```python num_connections = ndi.send_get_no_connections(send, 100) print(f"Connected receivers: {num_connections}") ``` ``` -------------------------------- ### Configure NDI Discovery (FindCreate) Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/configuration.md Configure NDI discovery behavior by specifying whether to include local sources, target specific groups, and add extra IP addresses. ```python create = ndi.FindCreate( show_local_sources=True, # Include local/multicast sources p_groups="Production,Backup", # Specific groups to search p_extra_ips="192.168.1.100" # Additional IP addresses ) ndi_find = ndi.find_create_v2(create) ``` -------------------------------- ### Get Sender Source Name Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-send.md Retrieves the network-advertised name of the NDI source. This is useful for identifying the sender on the network. ```python def send_get_source_name(instance: capsule) -> str: # ... implementation details ... pass ``` -------------------------------- ### Create Receiver Advertiser Instance Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-advertiser.md Creates a receiver advertiser instance using the provided configuration. Returns an opaque instance or None if creation fails. The instance must be destroyed using recv_advertiser_destroy(). ```python def recv_advertiser_create(create_settings: RecvAdvertiserCreateV2 | None = None) -> capsule | None: pass ``` ```python advertiser = ndi.recv_advertiser_create() if advertiser is None: print("Failed to create recv advertiser") exit(1) ``` -------------------------------- ### recv_recording_get_filename Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recording.md Gets the full path of the current recording file. Returns the full filename/path or an empty string if not recording. ```APIDOC ## recv_recording_get_filename() ### Description Gets the full path of the current recording file. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method None (Python function call) ### Endpoint None (Python function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **instance** (capsule) - Required - The Receiver instance ### Request Example ```python filename = ndi.recv_recording_get_filename(recv) if filename: print(f"Recording to: {filename}") ``` ### Response #### Success Response - **return** (str) - The full filename/path of the active recording, or empty string if not recording. #### Response Example ```json { "return": "/path/to/recording.mxf" } ``` ``` -------------------------------- ### routing_get_no_connections() Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-routing.md Gets the number of connections to the routing instance. This function returns the count of receivers currently connected to the router. ```APIDOC ## routing_get_no_connections() ### Description Gets the number of connections to the routing instance. ### Parameters #### Parameters - **instance** (capsule) - The Routing instance - **timeout_in_ms** (int) - Maximum time to wait in milliseconds ### Return Type int Returns the number of receivers connected to this router. ### Example ```python num_connections = ndi.routing_get_no_connections(routing, 100) print(f"Connected receivers: {num_connections}") ``` ``` -------------------------------- ### Configure NDI Receiver (RecvCreateV3) Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/configuration.md Configure receiver behavior at creation time, including the source to connect to, desired color format, bandwidth mode, support for interlaced video, and a display name for the receiver. ```python create = ndi.RecvCreateV3( source_to_connect_to=source, color_format=ndi.RECV_COLOR_FORMAT_BGRX_BGRA, # Color conversion bandwidth=ndi.RECV_BANDWIDTH_HIGHEST, # Bandwidth mode allow_video_fields=True, # Interlaced support p_ndi_recv_name="MyReceiver" # Display name ) recv = ndi.recv_create_v3(create) ``` -------------------------------- ### routing_get_source_name() Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-routing.md Gets the name of the currently routed source. This function returns the NDI name of the source that the router is currently connected to. ```APIDOC ## routing_get_source_name() ### Description Gets the name of the currently routed source. ### Parameters #### Parameters - **instance** (capsule) - The Routing instance ### Return Type str Returns the NDI source name string of the current routing source, or empty string if not routed. ### Example ```python source_name = ndi.routing_get_source_name(routing) if source_name: print(f"Currently routing: {source_name}") else: print("Router is not currently routing any source") ``` ``` -------------------------------- ### find_create_v2() Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-find.md Creates an NDI source discovery instance based on provided configuration settings. Returns an opaque handle to the instance or None if creation fails. ```APIDOC ## Function: find_create_v2() ### Description Creates a source discovery instance. Returns an opaque NDI Find instance (capsule) or `None` if creation fails. The returned instance must be destroyed with `find_destroy()`. ### Signature ```python def find_create_v2(create_settings: FindCreate | None = None) -> capsule | None ``` ### Parameters #### Parameters - **create_settings** (FindCreate or None) - Optional - Configuration for discovery; None uses defaults. ### Return Type `capsule | None` ### Example ```python ndi_find = ndi.find_create_v2() if ndi_find is None: print("Failed to create find instance") exit(1) # Use the find instance... di.find_destroy(ndi_find) ``` ``` -------------------------------- ### Proper NDI Resource Management Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/INDEX.md Illustrates the correct way to initialize and destroy NDI resources using a try-finally block. Always ensure NDI is destroyed to prevent resource leaks. ```python if not ndi.initialize(): exit(1) try: # Use NDI functions pass finally: ndi.destroy() ``` -------------------------------- ### send_listener_get_events Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Gets pending events from subscribed senders. This function retrieves a list of all pending events from senders that the listener is currently subscribed to. ```APIDOC ## send_listener_get_events() ### Description Gets pending events from subscribed senders. ### Method ```python def send_listener_get_events(instance: capsule, timeout_in_ms: int = 0) -> list[ListenerEvent] ``` ### Parameters #### Path Parameters - **instance** (capsule) - Required - The SendListener instance - **timeout_in_ms** (int) - Optional - Defaults to 0. The timeout in milliseconds for retrieving events. ### Return Type `list[ListenerEvent]` Returns a list of `ListenerEvent` objects from subscribed senders. ``` -------------------------------- ### Initialization & Library Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/INDEX.md Functions for initializing and destroying the NDI library, checking version, and CPU support. ```APIDOC ## Initialization & Library ### Functions - `initialize()`: Initializes the NDI library. - `destroy()`: Destroys the NDI library. - `version()`: Returns the NDI library version. - `is_supported_CPU()`: Checks if the CPU supports NDI operations. ``` -------------------------------- ### Get Recording Error Message Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recording.md Retrieves the error message from a failed recording operation. Returns an empty string if no error occurred. ```python def recv_recording_get_error(instance: capsule) -> str ``` ```python error = ndi.recv_recording_get_error(recv) if error: print(f"Recording error: {error}") ``` -------------------------------- ### Configure NDI Sender (SendCreate) Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/configuration.md Configure sender behavior by setting the network display name, NDI groups, and enabling synchronization for both video and audio clocks. ```python create = ndi.SendCreate( p_ndi_name="MyApp", # Display name on network p_groups="Production", # NDI groups clock_video=True, # Synchronize video clock_audio=True # Synchronize audio ) send = ndi.send_create(create) ``` -------------------------------- ### Get Number of NDI Connections Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-routing.md Retrieves the number of receivers currently connected to the NDI routing instance. A timeout can be specified for the query. ```python num_connections = ndi.routing_get_no_connections(routing, 100) print(f"Connected receivers: {num_connections}") ``` -------------------------------- ### Initialize MetadataFrame Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-frames.md Instantiate a MetadataFrame to transmit custom data, typically XML. Set the timecode and provide the metadata string. ```python import NDIlib as ndi metadata = ndi.MetadataFrame( timecode=0, p_data="value" ) ``` -------------------------------- ### Get Number of Active Receiver Connections Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-send.md Retrieves the count of active receiver connections for a given Sender instance. Specify a timeout for the operation. ```python def send_get_no_connections(instance: capsule, timeout_in_ms: int) -> int: # ... implementation details ... pass num_connections = ndi.send_get_no_connections(send, 100) print(f"Connected receivers: {num_connections}") ``` -------------------------------- ### Check NDI Library Version Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/configuration.md Initializes the NDI library, retrieves the version, prints it, and then destroys the library instance. ```python import NDIlib as ndi ndi.initialize() version = ndi.version() print(f"NDI Library Version: {version}") di.destroy() ``` -------------------------------- ### initialize() Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-initialization.md Initializes the NDI library. This function must be called before any other NDI functions can be used. Subsequent calls are safe and have no additional effect. ```APIDOC ## initialize() ### Description Initializes the NDI library and must be called before using any other NDI functions. ### Return Type `bool` Returns `True` if initialization is successful, `False` otherwise. Subsequent calls to initialize are harmless and safe. ### Example ```python import NDIlib as ndi if not ndi.initialize(): print("Failed to initialize NDI") exit(1) # Use NDI functions here... ndi.destroy() ``` ``` -------------------------------- ### Get Recording Timing Information Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recording.md Retrieves timing details for the current or last recording operation. Populates a RecvRecordingTime object and returns True on success. ```python def recv_recording_get_times(instance: capsule, times: RecvRecordingTime) -> bool ``` ```python times = ndi.RecvRecordingTime() if ndi.recv_recording_get_times(recv, times): print(f"Frames recorded: {times.no_frames}") print(f"Duration: {(times.last_time - times.start_time) / 10_000_000:.2f} seconds") ``` -------------------------------- ### Create NDI Source Discovery Instance Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-find.md Create an NDI source discovery instance using find_create_v2. Pass a FindCreate object for custom settings or None to use defaults. The instance must be destroyed with find_destroy. ```python def find_create_v2(create_settings: FindCreate | None = None) -> capsule | None ``` ```python ndi_find = ndi.find_create_v2() if ndi_find is None: print("Failed to create find instance") exit(1) # Use the find instance... ndi.find_destroy(ndi_find) ``` -------------------------------- ### Get NDI Receiver Recording Filename Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recording.md Retrieves the full path of the currently active recording file. If no recording is in progress, it returns an empty string. ```python def recv_recording_get_filename(instance: capsule) -> str: pass ``` ```python filename = ndi.recv_recording_get_filename(recv) if filename: print(f"Recording to: {filename}") ``` -------------------------------- ### RecvRecordingTime Structure Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recording.md Represents timing information and frame counts for a recording. Contains total frames, start time, and last recorded frame time. ```python class RecvRecordingTime: no_frames: int start_time: int last_time: int ``` -------------------------------- ### AudioFrameV2 Constructor Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-frames.md Initializes an AudioFrameV2 object with specified audio parameters. You can set sample rate, number of channels, number of samples, timecode, channel stride, metadata, and timestamp. ```APIDOC ## AudioFrameV2 Constructor ### Description Initializes an AudioFrameV2 object with specified audio parameters. ### Parameters #### Constructor Parameters - **sample_rate** (int) - Optional - Audio sample rate in Hz (48000 is standard). Default: 48000 - **no_channels** (int) - Optional - Number of audio channels. Default: 2 - **no_samples** (int) - Optional - Number of samples per channel. Default: 0 - **timecode** (int) - Optional - Timecode in 100ns units. Default: SEND_TIMECODE_SYNTHESIZE - **channel_stride_in_bytes** (int) - Optional - Bytes between channel starts (0 = calculated). Default: 0 - **p_metadata** (str or None) - Optional - XML metadata string. Default: None - **timestamp** (int) - Optional - Timestamp in 100ns units. Default: 0 ``` -------------------------------- ### Get Receiver Web Control URL Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recv.md Retrieves the web control URL for a receiver instance. This URL can be used to access the receiver's web interface. ```python def recv_get_web_control(instance: capsule) -> str: pass ``` -------------------------------- ### Get Receiver Queue Depth Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-recv.md Retrieves the current queue depth for a receiver instance. This indicates the number of video, audio, and metadata frames waiting in the queue. ```python def recv_get_queue(instance: capsule) -> RecvQueue: pass ``` -------------------------------- ### Initialize NDI Library Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-initialization.md Initializes the NDI library. Must be called before any other NDI functions. Subsequent calls are safe. ```python import NDIlib as ndi if not ndi.initialize(): print("Failed to initialize NDI") exit(1) # Use NDI functions here... di.destroy() ``` -------------------------------- ### send_get_tally Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-send.md Gets the current tally state from connected receivers. This function attempts to retrieve the tally status from NDI receivers and updates a provided Tally object. ```APIDOC ## send_get_tally() ### Description Gets the current tally state from connected receivers. ### Parameters #### Path Parameters - **instance** (capsule) - Required - The Sender instance - **tally** (Tally) - Required - Tally object to receive the state into - **timeout_in_ms** (int) - Required - Maximum time to wait in milliseconds ### Return Type `bool` Returns `True` if tally state was updated, `False` on timeout. ### Example ```python tally = ndi.Tally() if ndi.send_get_tally(send, tally, 1000): print(f"On program: {tally.on_program}, On preview: {tally.on_preview}") ``` ``` -------------------------------- ### Configure NDI Source Discovery Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-find.md Use the FindCreate class to configure settings for NDI source discovery. You can specify whether to include local sources and define groups or extra IP addresses to search. ```python class FindCreate: def __init__(self, show_local_sources: bool = True, p_groups: str | None = None, p_extra_ips: str | None = None) ``` ```python create_settings = ndi.FindCreate(show_local_sources=True) create_settings.groups = "Production,Backup" ``` -------------------------------- ### recv_listener_get_events Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Gets pending events from subscribed receivers. This function retrieves a list of events that have occurred since the last call, related to all currently subscribed receivers. ```APIDOC ## recv_listener_get_events() ### Description Gets pending events from subscribed receivers. ### Method Signature ```python def recv_listener_get_events(instance: capsule, timeout_in_ms: int = 0) -> list[ListenerEvent] ``` ### Parameters #### Path Parameters - **instance** (capsule) - Required - The RecvListener instance - **timeout_in_ms** (int) - Optional - Maximum time to wait in milliseconds (default: 0) ### Return Type list[ListenerEvent] Returns a list of `ListenerEvent` objects describing state changes in subscribed receivers. ### Example ```python events = ndi.recv_listener_get_events(listener, 1000) for event in events: print(f"Event from {event.uuid}: {event.name} = {event.value}") ``` ``` -------------------------------- ### Configure Sender Listener Creation Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Defines the configuration settings for creating a sender listener instance. The `url_address` property specifies the server URL. ```python class SendListenerCreateV2: def __init__(self, url_address: str = ""): pass ``` -------------------------------- ### Get Receiver Listener Server URL Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Retrieve the server URL the receiver listener is connected to using `recv_listener_get_server_url`. Returns the URL as a string or `None` if not connected. ```python def recv_listener_get_server_url(instance: capsule) -> str | None ``` -------------------------------- ### NDIlib Module Entry Point Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/quick-start.md This snippet shows the main functions and classes available directly from the NDIlib module for initializing, destroying, and querying NDI functionalities, as well as creating NDI sources and frames. ```APIDOC ## Module Entry Point All public functions and classes are in the `NDIlib` module: ```python import NDIlib as ndi # Available: ndi.initialize() di.destroy() di.version() di.is_supported_CPU() di.find_create_v2() di.Source() di.VideoFrameV2() di.AudioFrameV2() di.recv_create_v3() di.send_create() # ... and many more ``` See the full API reference documentation for complete details on all available functions and classes. ``` -------------------------------- ### Get Current NDI Source Name Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-routing.md Retrieves the NDI source name string of the currently routed source. Returns an empty string if no source is currently routed. ```python source_name = ndi.routing_get_source_name(routing) if source_name: print(f"Currently routing: {source_name}") else: print("Router is not currently routing any source") ``` -------------------------------- ### Create NDI Routing Instance Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-routing.md Creates a routing instance for switching between NDI sources. The returned instance must be destroyed using routing_destroy(). ```python routing_create = ndi.RoutingCreate(p_ndi_name="MyRouter") routing = ndi.routing_create(routing_create) if routing is None: print("Failed to create routing instance") exit(1) ``` -------------------------------- ### FindCreate Class Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-find.md Configuration object for NDI source discovery settings. Allows customization of which sources to include and which network groups or IPs to search. ```APIDOC ## Class: FindCreate ### Description Configuration object for source discovery settings. Allows customization of which sources to include and which network groups or IPs to search. ### Constructor ```python FindCreate(show_local_sources: bool = True, p_groups: str | None = None, p_extra_ips: str | None = None) ``` ### Parameters #### Constructor Parameters - **show_local_sources** (bool) - Optional - Whether to include local sources in discovery. Defaults to True. - **p_groups** (str or None) - Optional - Comma-separated list of NDI groups to search; None searches all groups. Defaults to None. - **p_extra_ips** (str or None) - Optional - Additional IP addresses to search for NDI sources. Defaults to None. ### Properties - `show_local_sources` (bool): Get/set whether to show local sources. - `groups` (str): Get/set the groups filter string. - `extra_ips` (str): Get/set extra IP addresses to search. ### Example ```python create_settings = ndi.FindCreate(show_local_sources=True) create_settings.groups = "Production,Backup" ``` ``` -------------------------------- ### Receive Video Frames from NDI Source Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/quick-start.md Connect to a specific NDI source and continuously capture video and audio frames. The receiver is configured to use BGRX_BGRA color format. Press Ctrl+C to stop. ```python import NDIlib as ndi if not ndi.initialize(): exit(1) # Find sources di_find = ndi.find_create_v2() di.find_wait_for_sources(ndi_find, 5000) sources = ndi.find_get_current_sources(ndi_find) if not sources: print("No sources found") exit(1) # Create and connect receiver recv_create = ndi.RecvCreateV3() recv_create.color_format = ndi.RECV_COLOR_FORMAT_BGRX_BGRA recv = ndi.recv_create_v3(recv_create) if recv is None: print("Failed to create receiver") exit(1) di.recv_connect(recv, sources[0]) di.find_destroy(ndi_find) # Capture frames print(f"Connecting to {sources[0].ndi_name}...") try: while True: frame_type, video, audio, metadata = ndi.recv_capture_v2(recv, 5000) if frame_type == ndi.FRAME_TYPE_VIDEO: print(f"Video: {video.xres}x{video.yres}, timecode={video.timecode}") ndi.recv_free_video_v2(recv, video) elif frame_type == ndi.FRAME_TYPE_AUDIO: print(f"Audio: {audio.no_samples} samples @ {audio.sample_rate}Hz") ndi.recv_free_audio_v2(recv, audio) elif frame_type == ndi.FRAME_TYPE_NONE: print("No data...") except KeyboardInterrupt: pass di.recv_destroy(recv) di.destroy() ``` -------------------------------- ### Get Pending Listener Events Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Retrieves a list of pending events from subscribed NDI receivers. You can specify a timeout to control how long the function waits for events. Each event object contains details about the state change. ```python def recv_listener_get_events(instance: capsule, timeout_in_ms: int = 0) -> list[ListenerEvent] ``` ```python events = ndi.recv_listener_get_events(listener, 1000) for event in events: print(f"Event from {event.uuid}: {event.name} = {event.value}") ``` -------------------------------- ### routing_create() Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-routing.md Creates a routing instance for switching between NDI sources. This function initializes an NDI router based on the provided configuration. ```APIDOC ## routing_create() ### Description Creates a routing instance for switching between NDI sources. ### Parameters #### Parameters - **create_settings** (RoutingCreate) - Configuration for the router ### Return Type capsule | None Returns an opaque NDI Routing instance (capsule) or `None` if creation fails. The returned instance must be destroyed with `routing_destroy()`. ### Example ```python routing_create = ndi.RoutingCreate(p_ndi_name="MyRouter") routing = ndi.routing_create(routing_create) if routing is None: print("Failed to create routing instance") exit(1) ``` ``` -------------------------------- ### SendCreate Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-send.md Configuration object for creating an NDI sender instance. It allows setting the display name, network groups, and clock synchronization for video and audio. ```APIDOC ## SendCreate ### Description Configuration object for creating a sender instance. It allows setting the display name, network groups, and clock synchronization for video and audio. ### Class Signature ```python class SendCreate: def __init__(self, p_ndi_name: str | None = None, p_groups: str | None = None, clock_video: bool = True, clock_audio: bool = True) ``` ### Constructor Parameters #### Parameters - **p_ndi_name** (str | None) - Optional - Display name for the sender on the network - **p_groups** (str | None) - Optional - Comma-separated list of NDI groups to advertise in - **clock_video** (bool) - Optional - Whether to clock (synchronize) video frames. Defaults to True. - **clock_audio** (bool) - Optional - Whether to clock (synchronize) audio frames. Defaults to True. ### Properties - **ndi_name** (str): Get/set the sender display name - **groups** (str): Get/set the groups string - **clock_video** (bool): Get/set video clocking - **clock_audio** (bool): Get/set audio clocking ### Example ```python send_create = ndi.SendCreate(p_ndi_name="My Sender", p_groups="Production") send_create.clock_video = True ``` ``` -------------------------------- ### Get List of Connected Receivers Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Obtain a list of all `Receiver` objects connected to the server via the listener. This function returns a list of `Receiver` objects, each containing details like name, UUID, address, and streams. ```python receivers = ndi.recv_listener_get_receivers(listener) for receiver in receivers: print(f"Receiver: {receiver.name} (UUID: {receiver.uuid})") print(f" Address: {receiver.address}") print(f" Streams: {receiver.streams}") ``` -------------------------------- ### Utilities Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/INDEX.md Utility functions for format conversion and audio manipulation. ```APIDOC ## Utilities ### Audio Conversion - `util_audio_to_interleaved_16s_v2()`: Converts audio to interleaved 16-bit signed format (v2). - `util_audio_from_interleaved_16s_v2()`: Converts interleaved 16-bit signed audio (v2). - `util_audio_to_interleaved_32s_v2()`: Converts audio to interleaved 32-bit signed format (v2). - `util_audio_from_interleaved_32s_v2()`: Converts interleaved 32-bit signed audio (v2). - `util_audio_to_interleaved_32f_v2()`: Converts audio to interleaved 32-bit float format (v2). - `util_audio_from_interleaved_32f_v2()`: Converts interleaved 32-bit float audio (v2). - `util_audio_to_interleaved_16s_v3()`: Converts audio to interleaved 16-bit signed format (v3). - `util_audio_from_interleaved_16s_v3()`: Converts interleaved 16-bit signed audio (v3). - `util_audio_to_interleaved_32s_v3()`: Converts audio to interleaved 32-bit signed format (v3). - `util_audio_from_interleaved_32s_v3()`: Converts interleaved 32-bit signed audio (v3). - `util_audio_to_interleaved_32f_v3()`: Converts audio to interleaved 32-bit float format (v3). - `util_audio_from_interleaved_32f_v3()`: Converts interleaved 32-bit float audio (v3). ### Video Conversion - `util_V210_to_P216()`: Converts V210 video to P216 format. - `util_P216_to_V210()`: Converts P216 video to V210 format. ### Interleaved Audio Sending - `util_send_send_audio_interleaved_16s()`: Sends interleaved 16-bit signed audio. - `util_send_send_audio_interleaved_32s()`: Sends interleaved 32-bit signed audio. - `util_send_send_audio_interleaved_32f()`: Sends interleaved 32-bit float audio. ``` -------------------------------- ### Build ndi-python for a specific Python version Source: https://github.com/buresu/ndi-python/blob/master/README.md Install the ndi-python package for a specific Python version, setting the NDI SDK directory and using the target Python interpreter's pip. This ensures compatibility with the desired Python environment. ```bash CMAKE_ARGS="-DNDI_SDK_DIR=/path/to/ndisdk" /path/to/python3.12 -m pip install . ``` -------------------------------- ### RecvAdvertiserCreateV2 Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-advertiser.md Configuration class for creating a receiver advertiser instance. It holds settings like the server URL. ```APIDOC ## RecvAdvertiserCreateV2 ### Description Configuration for creating a receiver advertiser instance. ### Class Signature ```python class RecvAdvertiserCreateV2: def __init__(self, url_address: str = "") ``` ### Constructor Parameters #### Parameters - **url_address** (str) - Optional - Server URL for the advertiser; empty for default ### Properties - **url_address** (str): Get/set the server URL address ``` -------------------------------- ### Define RecvListenerCreateV2 Configuration Source: https://github.com/buresu/ndi-python/blob/master/_autodocs/api-reference-listeners.md Defines the configuration settings for creating a receiver listener instance. The url_address parameter specifies the server URL for the listener. ```python class RecvListenerCreateV2: def __init__(self, url_address: str = "") ```