Skip to main content

NDI support for the visiongraph library.

Project description

Visiongraph NDI PyPI

Visiongraph NDI is an extension of the visiongraph library, adding support for real-time video streaming over the network via NewTek's NDI® protocol. This library provides both sending and receiving capabilities, making it easy to integrate NDI into computer vision workflows.

Installation

Install visiongraph NDI with pip:

pip install visiongraph-ndi

Requirements

Ensure you have the latest version of visiongraph installed.

Usage Examples

Sending Video Streams

The NDIVideoOutput class allows you to broadcast images in real-time. This example shows how to generate a simple time-based pattern and send it as a video stream.

from visiongraph_ndi.NDIVideoOutput import NDIVideoOutput

# Set up NDI output with a stream name
with NDIVideoOutput("Demo") as ndi:
    image_bgr = ... # load or get an image in BGR format
    ndi.send(image_bgr)  # Send the generated image

The NDIVideoOutput class initializes an NDI output stream with the given name. Use ndi.send(frame) to transmit frames, which can be in BGR or BGRA format.

Receiving Video Streams

The NDIVideoInput class supports finding available NDI sources and streaming from them in real-time. Below are examples of how to find NDI sources and receive streams.

Finding Sources

Use NDIVideoInput.find_sources() to list all available NDI sources on the network. It is possible to set the timeout to find sources (default: 1.0 seconds).

from visiongraph_ndi.NDIVideoInput import NDIVideoInput

# Discover NDI sources for 5 seconds
for source in NDIVideoInput.find_sources(timeout=5.0):
    print(source.name)

Receiving Video Streams

The following example demonstrates how to receive a video stream from a the first NDI source available and display it using OpenCV.

import cv2
from visiongraph_ndi.NDIVideoInput import NDIVideoInput

# Connect to an NDI source
with NDIVideoInput(stream_name="Demo") as ndi:
    while ndi.is_connected:
        ts, frame = ndi.read()  # Receive timestamped frame

        if frame is None:
            continue  # Skip if no frame is received

        # Display the frame
        cv2.imshow(f"NDI {ndi.source.stream_name}", frame)
        cv2.waitKey(1)

The NDIVideoInput class automatically connects to the first available NDI source or allows for specific source selection if desired (using the stream_name and/or host_name parameter in the constructor). By calling ndi.read(), you retrieve frames as numpy arrays, ready for processing or display.

About

Visiongraph NDI is powered by the NDI Python wrapper cyndilib (MIT license). Special thanks to nocarryr for making this integration possible.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

visiongraph_ndi-0.2.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file visiongraph_ndi-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for visiongraph_ndi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0b96be012e28697efbcd20b8afad77f924c0de967f89047dcaeeb2fd6b6c7be
MD5 919f473bcd2ffc500c347ace0d480d17
BLAKE2b-256 b57455d7d8d91003f8d4f051f1e44fc82b5f2395d7f61ebc4f54fd854edae855

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page