Hi,
I am trying to put together a script for field work that basically encodes 4K rgb videos that then can be used for POCs.
I have been using the rgb_mono_encoding.py (luxonis/depthai-pythonblob/main/examples/VideoEncoder/rgb_mono_encoding.py) script for that and it works fine. However, for some installation points I need to rotate the frames 90 degrees prior to encoding.
I am trying to merge the image_manip_rotate.py (luxonis/depthai-pythonblob/main/examples/ImageManip/image_manip_rotate.py) script for that.
import cv2
import depthai as dai
# Create pipeline
pipeline = dai.Pipeline()
# Rotate color frames
camRgb = pipeline.create(dai.node.ColorCamera)
camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
manipRgb = pipeline.create(dai.node.ImageManip)
manipRgb.setMaxOutputFrameSize(24883200)
rgbRr = dai.RotatedRect()
rgbRr.center.x, rgbRr.center.y = camRgb.getResolutionWidth() // 2, camRgb.getResolutionHeight() // 2
rgbRr.size.width, rgbRr.size.height = camRgb.getResolutionHeight(), camRgb.getResolutionWidth()
rgbRr.angle = 90
manipRgb.initialConfig.setCropRotatedRect(rgbRr, False)
camRgb.preview.link(manipRgb.inputImage)
manipRgbOut = pipeline.create(dai.node.XLinkOut)
manipRgbOut.setStreamName("manip_rgb")
manipRgb.out.link(manipRgbOut.input)
# Rotate mono frames
monoLeft = pipeline.create(dai.node.MonoCamera)
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
manipLeft = pipeline.create(dai.node.ImageManip)
rr = dai.RotatedRect()
rr.center.x, rr.center.y = monoLeft.getResolutionWidth() // 2, monoLeft.getResolutionHeight() // 2
rr.size.width, rr.size.height = monoLeft.getResolutionHeight(), monoLeft.getResolutionWidth()
rr.angle = 90
manipLeft.initialConfig.setCropRotatedRect(rr, False)
monoLeft.out.link(manipLeft.inputImage)
manipLeftOut = pipeline.create(dai.node.XLinkOut)
manipLeftOut.setStreamName("manip_left")
manipLeft.out.link(manipLeftOut.input)
# Define encoders
ve1 = pipeline.create(dai.node.VideoEncoder)
ve2 = pipeline.create(dai.node.VideoEncoder)
ve3 = pipeline.create(dai.node.VideoEncoder)
ve1Out = pipeline.create(dai.node.XLinkOut)
ve2Out = pipeline.create(dai.node.XLinkOut)
ve3Out = pipeline.create(dai.node.XLinkOut)
ve1Out.setStreamName('ve1Out')
ve2Out.setStreamName('ve2Out')
ve3Out.setStreamName('ve3Out')
# Set encoder properties
ve1.setDefaultProfilePreset(15, dai.VideoEncoderProperties.Profile.H264_MAIN)
ve2.setDefaultProfilePreset(15, dai.VideoEncoderProperties.Profile.H265_MAIN)
ve3.setDefaultProfilePreset(15, dai.VideoEncoderProperties.Profile.H264_MAIN)
# Linking
manipLeft.out.link(ve1.input)
manipRgb.out.link(ve2.input)
manipLeft.out.link(ve3.input)
ve1.bitstream.link(ve1Out.input)
ve2.bitstream.link(ve2Out.input)
ve3.bitstream.link(ve3Out.input)
# Connect to device and start pipeline
with dai.Device(pipeline) as dev:
# Output queues for encoders
outQ1 = dev.getOutputQueue(name='ve1Out', maxSize=30, blocking=True)
outQ2 = dev.getOutputQueue(name='ve2Out', maxSize=30, blocking=True)
outQ3 = dev.getOutputQueue(name='ve3Out', maxSize=30, blocking=True)
print("Press Ctrl+C to stop encoding...")
while True:
try:
# Empty each queue
while outQ1.has():
outQ1.get().getData().tofile(fileMono1H264)
while outQ2.has():
outQ2.get().getData().tofile(fileColorH265)
while outQ3.has():
outQ3.get().getData().tofile(fileMono2H264)
except KeyboardInterrupt:
# Keyboard interrupt (Ctrl + C) detected
break
print("To view the encoded data, convert the stream file (.h264/.h265) into a video file (.mp4), using commands below:")
cmd = "ffmpeg -framerate 30 -i {} -c copy {}"
print(cmd.format("mono1.h264", "mono1.mp4"))
print(cmd.format("mono2.h264", "mono2.mp4"))
print(cmd.format("color.h265", "color.mp4"))
But I a getting the following error:
[18443010D197780E00] [1.2.1] [1.356] [VideoEncoder(8)] [critical] Width must be multiple of 32, height multiple of 8 for H26x encoder profile. Received (400, 640)
[18443010D197780E00] [1.2.1] [1.356] [VideoEncoder(6)] [critical] Width must be multiple of 32, height multiple of 8 for H26x encoder profile. Received (400, 640)
[18443010D197780E00] [1.2.1] [2.129] [VideoEncoder(7)] [critical] Width must be multiple of 32, height multiple of 8 for H26x encoder profile. Received (2160, 3840)
How can I get this fixed? Appreciate the help from the community.
Regards