How to generate a RTSP stream from within python-cv2?

Hello all knowing Nvidia community!

I have a TX2 with a camera attached to it.
The camera is a PCIe camera and is not easy to use but the manufacturer has provided me with an example code. It displays a live video feed in a window on the TX2 desktop.

The problem is i want the TX2 to stream the video to another computer! So that i could watch the live stream with VLC.

How do i create a rtsp stream from within cv2 ?

here is the code that creates a video:

from ximea import xiapi
import cv2
import time

#create instance for first connected camera
cam = xiapi.Camera()

#start communication
print(‘Opening first camera…’)
cam.open_device()

#settings
cam.set_exposure(20000)

#create instance of Image to store image data and metadata
img = xiapi.Image()

#start data acquisition
print(‘Starting data acquisition…’)
cam.start_acquisition()

try:
print(‘Starting video. Press CTRL+C to exit.’)
t0 = time.time()
while True:
#get data and pass them from camera to img
cam.get_image(img)

    #create numpy array with data from camera. Dimensions of the array are
    #determined by imgdataformat
    data = img.get_image_data_numpy()

    #show acquired image with time since the beginning of acquisition
    font = cv2.FONT_HERSHEY_SIMPLEX
    text = '{:5.2f}'.format(time.time()-t0)
    cv2.putText(
        data, text, (900,150), font, 4, (255, 255, 255), 2 )
    cv2.imshow('XiCAM example', data)

    cv2.waitKey(1)

except KeyboardInterrupt:
cv2.destroyAllWindows()

#stop data acquisition
print(‘Stopping acquisition…’)
cam.stop_acquisition()

#stop communication
cam.close_device()

print(‘Done.’)

You may try a videoWriter encoding into h264 and sending to a socket that can be read by RTSP sever such as in this example.