From 9314c5e7f149a9ebea3efa4a6d48e0250b7fdc74 Mon Sep 17 00:00:00 2001 From: Naoto Kondo Date: Sat, 19 Mar 2022 15:03:27 +0900 Subject: [PATCH] add example for the ndi recv --- example/recv.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 example/recv.py diff --git a/example/recv.py b/example/recv.py new file mode 100644 index 0000000..13e7af7 --- /dev/null +++ b/example/recv.py @@ -0,0 +1,59 @@ +import sys +import numpy as np +import NDIlib as ndi + + +def main(): + + if not ndi.initialize(): + return 0 + + ndi_find = ndi.find_create_v2() + + if ndi_find is None: + return 0 + + sources = [] + while not len(sources) > 0: + print('Looking for sources ...') + ndi.find_wait_for_sources(ndi_find, 1000) + sources = ndi.find_get_current_sources(ndi_find) + + ndi_recv_create = ndi.RecvCreateV3() + ndi_recv_create.color_format = ndi.RECV_COLOR_FORMAT_BGRX_BGRA + + ndi_recv = ndi.recv_create_v3(ndi_recv_create) + + if ndi_recv is None: + return 0 + + ndi.recv_connect(ndi_recv, sources[0]) + + ndi.find_destroy(ndi_find) + + while True: + t, v, a, _ = ndi.recv_capture_v2(ndi_recv, 5000) + + if t == ndi.FRAME_TYPE_NONE: + print('No data received.') + continue + + if t == ndi.FRAME_TYPE_VIDEO: + print('Video data received (%dx%d).' % (v.xres, v.yres)) + ndi.recv_free_video_v2(ndi_recv, v) + continue + + if t == ndi.FRAME_TYPE_AUDIO: + print('Audio data received (%d samples).' % a.no_samples) + ndi.recv_free_audio_v2(ndi_recv, a) + continue + + ndi.recv_destroy(ndi_recv) + + ndi.destroy() + + return 0 + + +if __name__ == "__main__": + sys.exit(main())