jakaskerl
@erik
thank you. for getting back.
I am facing connection establishment issue while running the script I dont really knwo whats wrong in here. It happens in second script i run. To summarize i can only stream one camera at a time.
#!/usr/bin/env python3
import threading
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GLib
import depthai as dai
class RtspSystem(GstRtspServer.RTSPMediaFactory):
def __init__(self, **properties):
super(RtspSystem, self).__init__(**properties)
self.data = None
self.launch_string = 'appsrc name=source is-live=true block=true format=GST_FORMAT_TIME ! h265parse ! rtph265pay name=pay0 config-interval=1 name=pay0 pt=96'
def send_data(self, data):
self.data = data
def start(self):
t = threading.Thread(target=self._thread_rtsp)
t.start()
def _thread_rtsp(self):
loop = GLib.MainLoop()
loop.run()
def on_need_data(self, src, length):
if self.data is not None:
retval = src.emit('push-buffer', Gst.Buffer.new_wrapped(self.data.tobytes()))
if retval != Gst.FlowReturn.OK:
print(retval)
def do_create_element(self, url):
return Gst.parse_launch(self.launch_string)
def do_configure(self, rtsp_media):
self.number_frames = 0
appsrc = rtsp_media.get_element().get_child_by_name('source')
appsrc.connect('need-data', self.on_need_data)
class RTSPServer(GstRtspServer.RTSPServer):
def __init__(self, port, endpoint, device_ip, **properties):
super(RTSPServer, self).__init__(**properties)
self.rtsp = RtspSystem()
self.rtsp.set_shared(True)
self.get_mount_points().add_factory(endpoint, self.rtsp)
self.attach(None)
Gst.init(None)
self.rtsp.start()
def send_data(self, data):
self.rtsp.send_data(data)
if __name__ == "__main__":
port1 = 8554
endpoint1 = "/oak61"
device_ip1 = "10.10.10.61"
server1 = RTSPServer(port1, endpoint1, device_ip1)
pipeline1 = dai.Pipeline()
FPS = 60
colorCam1 = pipeline1.create(dai.node.ColorCamera)
colorCam1.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
colorCam1.setInterleaved(False)
colorCam1.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR)
colorCam1.setFps(FPS)
colorCam1.initialControl.setManualFocus(185) # 0..255
videnc1 = pipeline1.create(dai.node.VideoEncoder)
videnc1.setDefaultProfilePreset(FPS, dai.VideoEncoderProperties.Profile.H265_MAIN)
videnc1.setBitrateKbps(8000)
colorCam1.video.link(videnc1.input)
veOut1 = pipeline1.create(dai.node.XLinkOut)
veOut1.setStreamName("encoded")
videnc1.bitstream.link(veOut1.input)
device_infos = dai.DeviceBootloader.getAllAvailableDevices()
device_info1 = [device_info for device_info in device_infos if device_info.name == desired_ip][0]
if device_info1:
if device_info1.protocol != dai.XLinkProtocol.X_LINK_USB_VSC:
print("Running RTSP stream may be unstable due to connection... (protocol: {})".format(device_info1.protocol))
with dai.Device(pipeline1, device_info1) as device1:
encoded1 = device1.getOutputQueue("encoded", maxSize=30, blocking=True)
print("Setup finished, RTSP stream available under \"rtsp://localhost:{}/oak61\"".format(port1))
while True:
data1 = encoded1.get().getData()
server1.send_data(data1)
else:
print('No device found')
Further, about h26x artifacts, I now have doubt about bandwidth too. Since I have come to know about the ports are running on 1GBPS. and we have monitored traffic and its way less then capacity. So likely something else seems to be the issue. Over more, CPU also has good performance so processing should also not be the issue.
will share performance if it helps.