• Community
  • OAK-1 device encoded video+ rgb stream

hello,

I am using one video rgb display script to capture videos and this script to store encoded video.
I have tried this independently, it works fine.
But if I want to write this in only one script then, the encoded script does not work properly, it actually saves the video at a low frame rate (30 fps), so after converting the video to mp4 it's very fast.

I am using an OAK-1 device with USB 3.
how can I run this script in parallel as an independent script, is it possible? if yes, please suggest any example.

@erik @jakaskerl

  • erik replied to this.

    Capen could you share a minimal reproducible script?

    i am trying this code to show the video frame using cv2.inshow which I feel is the wrong way to do

    \#!/usr/bin/env python3*
    
    import depthai as dai
    
    # 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.CAM_A)
    camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
    videoEnc.setDefaultProfilePreset(30, dai.VideoEncoderProperties.Profile.H265_MAIN)
    
    # Linking
    camRgb.video.link(videoEnc.input)
    videoEnc.bitstream.link(xout.input)
    
    # Connect to device and start pipeline*
    with dai.Device(pipeline) as device:
    
        # Output queue will be used to get the encoded data from the output defined above*
        q = device.getOutputQueue(name="h265", maxSize=30, blocking=**True**)
    
        # The .h265 file is a raw stream file (not playable yet)*
        with open('video.h265', 'wb') as videoFile:
            print("Press Ctrl+C to stop encoding...")
            try:
                while True:
                    h265Packet = q.get()  # Blocking call, will wait until a new data has arrived*
                    h265Packet.getData().tofile(videoFile)  # Appends the packet data to the opened file
                    cv2.imshow(h265Packet)
            except KeyboardInterrupt:
                # Keyboard interrupt (Ctrl + C) detected*
                pass
    
        print("To view the encoded data, convert the stream file (.h265) into a video file (.mp4) using a command below:")
        print("ffmpeg -framerate 30 -i video.h265 -c copy video.mp4")
    • erik replied to this.

      erik
      thank you Erik for the help.

      I have tried this example, it serves the purpose for what I am looking to do. But I have one more question to ask.

      I am using an oak-1 sensor with an FFC3 board, the 4-k feed has a good amount of latency. I am running this on ARM Board.
      is there any way to reduce this latency? maybe increase the number of shaves?
      please guide.

      • erik replied to this.