Hi, can above be done? Is there some example code?
The compression needs to be done on the camera's. Ive tried appending output streams to a list, and start a thread for each stream to save the data. That did not work yet, and it does not solve the sync issue.
#!/usr/bin/env python3
import depthai as dai
import contextlib
import threading
print(dai) #print depthai version
from datetime import datetime
# get current date and time
current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
str_current_datetime = str(current_datetime)
file_name = str_current_datetime
def createPipeline():
# Create pipeline
pipeline = dai.Pipeline()
*# Define sources and output*
camRgb = pipeline.create(dai.node.ColorCamera)
videoEnc = pipeline.create(dai.node.VideoEncoder)
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName('h265')
*# Properties*
camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
videoEnc.setDefaultProfilePreset(60, dai.VideoEncoderProperties.Profile.H265_MAIN)
*# Linking*
camRgb.video.link(videoEnc.input)
videoEnc.bitstream.link(xout.input)
return pipeline
def SaveStream(stream, fname):
with open(fname, 'wb') as videoFile:
print("Press Ctrl+C to stop encoding...")
try:
while True:
h265Packet = stream.get() *# Blocking call, will wait until a new data has arrived*
h265Packet.getData().tofile(videoFile) *# Appends the packet data to the opened file*
except KeyboardInterrupt:
*# Keyboard interrupt (Ctrl + C) detected*
pass
with contextlib.ExitStack() as stack:
deviceInfos = dai.Device.getAllAvailableDevices()
usbSpeed = dai.UsbSpeed.SUPER
openVinoVersion = dai.OpenVINO.Version.VERSION_2021_4
streamMap = []
devices = []
deviceCounter = 1
for deviceInfo in deviceInfos:
deviceInfo: dai.DeviceInfo
device: dai.Device = stack.enter_context(dai.Device(openVinoVersion, deviceInfo, usbSpeed))
devices.append(device)
print("===Connected to ", deviceInfo.getMxId())
pipeline = createPipeline()
device.startPipeline(pipeline)
file_name_numbered = file_name + '_' + str(deviceCounter) + ".h256"
q = device.getOutputQueue(name="h265", maxSize=30, blocking=True)
streamMap.append((q, file_name_numbered))
deviceCounter = deviceCounter + 1
task_list = []
for stream_tuple in streamMap:
stream = stream_tuple[0]
fname = stream_tuple[1]
task= threading.Thread(target=SaveStream, args=(stream, fname))
task.start()
task.join()
task_list.append(task)