I need to output the h264 or h265 video stream from the camera using cv2 or PIL. this is necessary to transfer a video stream from one computer to another. the problem is that I do not know how to output frames using one of these codecs.
that's how I get to output with the MJPEG codec, but when I use h265\h 264, cv2.imdecode(frame, v2.IMREAD_COLOR) is None:
import cv2
import depthai as dai
pipeline = dai.Pipeline()
camRgb = pipeline.create(dai.node.ColorCamera)
xoutVideo = pipeline.create(dai.node.XLinkOut)
xoutVideo.setStreamName("video")
camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
camRgb.setVideoSize(1920, 1080)
camRgb.setFps(60)
videoEnc = pipeline.create(dai.node.VideoEncoder)
videoEnc.setDefaultProfilePreset(60, dai.VideoEncoderProperties.Profile.MJPEG)
camRgb.video.link(videoEnc.input)
videoEnc.bitstream.link(xoutVideo.input)
with dai.Device(pipeline) as device:
video = device.getOutputQueue(name="video", maxSize=1, blocking=False)
while True:
videoIn = video.get()
frame = videoIn.getData()
frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
cv2.imshow("video", frame)
if cv2.waitKey(1) == ord('q'):
break