@FabPoll I am currently using aiortc with python. I pasted the code I put together to give you an idea of the work around I had to use to get the stream to work. This does work but it’s not great, and uses around 30% CPU on a jetson Orin nano while running. I’m curious to hear what you are using and the kind of CPU usage you are seeing.
class VideoCamera(object):
def __init__(self):
self.pipeline = dai.Pipeline()
# Define sources and output
self.camRgb = self.pipeline.create(dai.node.ColorCamera)
self.videoEnc = self.pipeline.create(dai.node.VideoEncoder)
self.xout = self.pipeline.create(dai.node.XLinkOut)
self.xout.setStreamName('h264')
# Properties
self.camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
self.camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
self.videoEnc.setDefaultProfilePreset(30, dai.VideoEncoderProperties.Profile.H264_MAIN)
self.videoEnc.setKeyframeFrequency(10) # Insert a keyframe every 30 frames
self.videoEnc.setQuality(25)
self.camRgb.setFps(30)
# Linking
self.camRgb.video.link(self.videoEnc.input)
self.videoEnc.bitstream.link(self.xout.input)
self.device = dai.Device(self.pipeline)
self.pts = 0
def __del__(self):
# shutdown the pipeline
self.device.close()
async def get_frame(self):
# Output queue will be used to get the encoded data from the output defined above
q = self.device.getOutputQueue(name="h264", maxSize=1, blocking=True)
packet = None
# Emptying queue
while packet is None:
if q.has():
packet = av.packet.Packet(q.get().getData())
packet.pts = self.pts
packet.time_base = Fraction(1, 30)
self.pts += 1
else:
await asyncio.sleep(0.01)
return packet
def force_codec(pc, sender, forced_codec):
kind = forced_codec.split("/")[0]
codecs = RTCRtpSender.getCapabilities(kind).codecs
transceiver = next(t for t in pc.getTransceivers() if t.sender == sender)
transceiver.setCodecPreferences(
[codec for codec in codecs if codec.mimeType == forced_codec]
)
class CameraStreamTrack(VideoStreamTrack):
def __init__(self, camera):
super().__init__()
self.camera = camera
async def recv(self):
frame = None
while frame is None:
frame = await self.camera.get_frame()
return frame