Yeah I think is a linking issue and I am not quite able to figure it out. Now two videos do get created and are shown by cv2 imshow but when i save it nothing gets saved.
#!/usr/bin/env python3
import cv2
import depthai as dai
import contextlib
def createPipeline():
# Start defining a pipeline
pipeline = dai.Pipeline()
# Define a source - color camera
camRgb = pipeline.create(dai.node.ColorCamera)
camRgb.setPreviewSize(300, 300)
camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
camRgb.setInterleaved(False)
camRgb.setVideoSize(1920, 1080)
# Create output
xoutVideo = pipeline.create(dai.node.XLinkOut)
xoutVideo.setStreamName("video")
xoutVideo.input.setBlocking(False)
xoutVideo.input.setQueueSize(1)
# Define the duration (in seconds) of the video capture here
capture_duration = 10
# Linking
camRgb.video.link(xoutVideo.input)
return pipeline
with contextlib.ExitStack() as stack:
deviceInfos = dai.Device.getAllAvailableDevices()
usbSpeed = dai.UsbSpeed.SUPER
openVinoVersion = dai.OpenVINO.Version.VERSION_2021_4
qRgbMap = []
devices = []
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())
mxId = device.getMxId()
cameras = device.getConnectedCameras()
usbSpeed = device.getUsbSpeed()
eepromData = device.readCalibration2().getEepromData()
print(" >>> MXID:", mxId)
print(" >>> Num of cameras:", len(cameras))
print(" >>> USB speed:", usbSpeed)
if eepromData.boardName != "":
print(" >>> Board name:", eepromData.boardName)
if eepromData.productName != "":
print(" >>> Product name:", eepromData.productName)
pipeline = createPipeline()
device.startPipeline(pipeline)
frame_width = int(1920)
frame_height = int(1080)
size = (frame_width, frame_height)
# Output queue will be used to get the rgb frames from the output defined above
video = device.getOutputQueue(name="video", maxSize=1, blocking=False)
stream_name = "rgb-" + mxId + "-" + eepromData.productName
qRgbMap.append((video, stream_name))
result = cv2.VideoWriter('filename_'+str(mxId)+'.avi',
cv2.VideoWriter_fourcc(\*'MJPG'),
10, size)
while True:
for video, stream_name in qRgbMap:
if video.has():
videoIn = video.get()
result.write(videoIn.getCvFrame())
cv2.imshow(stream_name, videoIn.getCvFrame())
if cv2.waitKey(1) == ord('q'):
break
result.release()
cv2.destroyAllWindows()
print("The video was successfully saved")