Initial commit

This commit is contained in:
Naoto Kondo
2019-04-16 19:59:04 +09:00
commit b3b94e0e51
10 changed files with 1034 additions and 0 deletions

50
example/send_capture.py Normal file
View File

@@ -0,0 +1,50 @@
import sys
import time
import numpy as np
import cv2
import NDIlib
def main():
if not NDIlib.initialize():
return 0
cap = cv2.VideoCapture(0)
send_settings = NDIlib.SendCreate()
send_settings.p_ndi_name = b'ndi-python'
ndi_send = NDIlib.send_create(send_settings)
video_frame = NDIlib.VideoFrameV2()
start = time.time()
while time.time() - start < 60 * 5:
start_send = time.time()
for idx in reversed(range(200)):
ret, img = cap.read()
if ret:
h, w = img.shape[:2]
img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)
video_frame.xres = w
video_frame.yres = h
video_frame.p_data = img.ctypes.data_as(NDIlib.POINTER(NDIlib.c_uint8))
video_frame.FourCC = NDIlib.FOURCC_TYPE_BGRX
video_frame.line_stride_in_bytes = w * 4
NDIlib.send_send_video_v2(ndi_send, video_frame)
print('200 frames sent, at %1.2ffps' % (200.0 / (time.time() - start_send)))
NDIlib.send_destroy(ndi_send)
NDIlib.destroy()
return 0
if __name__ == "__main__":
sys.exit(main())

45
example/send_png.py Normal file
View File

@@ -0,0 +1,45 @@
import sys
import time
import numpy as np
import cv2
import NDIlib
def main():
if not NDIlib.initialize():
return 0
img = cv2.imread('image/test2.png', cv2.IMREAD_ANYCOLOR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGBA)
h, w = img.shape[:2]
send_settings = NDIlib.SendCreate()
send_settings.p_ndi_name = b'ndi-python'
ndi_send = NDIlib.send_create(send_settings)
video_frame = NDIlib.VideoFrameV2()
video_frame.xres = w
video_frame.yres = h
video_frame.FourCC = NDIlib.FOURCC_TYPE_RGBA
video_frame.p_data = img.ctypes.data_as(NDIlib.POINTER(NDIlib.c_uint8))
video_frame.line_stride_in_bytes = w * 4
start = time.time()
while time.time() - start < 60 * 5:
start_send = time.time()
for idx in reversed(range(200)):
NDIlib.send_send_video_v2(ndi_send, video_frame)
print('200 frames sent, at %1.2ffps' % (200.0 / (time.time() - start_send)))
NDIlib.send_destroy(ndi_send)
NDIlib.destroy()
return 0
if __name__ == "__main__":
sys.exit(main())

46
example/send_video.py Normal file
View File

@@ -0,0 +1,46 @@
import sys
import time
import numpy as np
import NDIlib
import ctypes
def main():
if not NDIlib.initialize():
return 0
ndi_send = NDIlib.send_create()
if ndi_send is 0:
return 0
img = np.zeros((1080, 1920, 4), dtype=np.uint8)
h, w = img.shape[:2]
video_frame = NDIlib.VideoFrameV2()
video_frame.xres = w
video_frame.yres = h
video_frame.FourCC = NDIlib.FOURCC_TYPE_BGRX
#video_frame.data = img.ctypes.data_as(NDIlib.POINTER(NDIlib.c_uint8))
#video_frame.data = img.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))
print(type(video_frame.data))
start = time.time()
while time.time() - start < 60 * 5:
start_send = time.time()
for idx in reversed(range(200)):
img.fill(255 if idx % 2 else 0)
NDIlib.send_send_video_v2(ndi_send, video_frame)
print('200 frames sent, at %1.2ffps' % (200.0 / (time.time() - start_send)))
NDIlib.send_destroy(ndi_send)
NDIlib.destroy()
return 0
if __name__ == "__main__":
sys.exit(main())