Encoding manager

EncodingManager is a class that is made to help you with creating videos from OAK cameras.

Getting started

Same as PreviewManager, EncodingManager works hand in hand with the PipelineManager, so before you can use the encoder, you will first have to declare and initialize the PipelineManager. Again, same as the PreviewManager, it is not needed to use PipelineManager, you can create the pipeline without it. The managers are created to help you and make your programing experience with DepthAi SDK easier.

 1from pathlib import Path
 2from depthai_sdk import Previews
 3from depthai_sdk import EncodingManager
 4from depthai_sdk.managers import PipelineManager
 5import depthai as dai
 6
 7
 8# Before declaring the pipeline and encoder, we must create a dictionary of streams, with fps ans values
 9encodeConfig = dict()
10encodeConfig[Previews.color.name] = 30
11
12# create encoder with above declared dictionary and path to save the file ("" will save it next to the program file)
13em = EncodingManager(encodeConfig, Path(__file__))
14
15# create pipeline with above mentioned streams
16pm = PipelineManager()
17pm.createColorCam(xoutVideo=True)
18
19# create encoders for all streams that were initialized
20em.createEncoders(pm)
21
22# start device
23with dai.Device(pm.pipeline) as device:
24    # create stream queues
25    em.createDefaultQueues(device)
26
27    while True:
28        # save frames to .h256 files
29        em.parseQueues()

The most important part, when using the EncodingManager is that the encoder must be created during the pipeline creation. So to begin, first we create a dictionary, which will contain all streams from the OAK camera as keys, and number of fps as their values. After that we declare the EncodingManager with the dictionary, which we just declared, and the wanted path, where the files will be stored. So to store our videos we have to give our encoder the wanted path for saving. We specify our path with Path(__file__). All the files will be stored in .h265 format, with the file name beeing the source name (so in the above example we will create color.h256).

As you can also see after we declare the pipeline and initialize it’s sources, we must set xoutVideo to True instead of xout. And after connecting to the device we parse through the queues and save frames to files.

class depthai_sdk.managers.EncodingManager

Manager class that handles video encoding

__init__(encodeConfig, encodeOutput=None)
Parameters
  • encodeConfig (dict) – Encoding config consisting of keys as preview names and values being the encoding FPS

  • encodeOutput (pathlib.Path, Optional) – Output directory for the recorded videos

createEncoders(pm)

Creates VideoEncoder nodes using Pipeline manager, based on config provided during initialization

Parameters

pm (depthai_sdk.managers.PipelineManager) – Pipeline Manager instance

createDefaultQueues(device)

Creates output queues for VideoEncoder nodes created in create_encoders function. Also, opems up the H.264 / H.265 stream files (e.g. color.h265) where the encoded data will be stored.

Parameters

device (depthai.Device) – Running device instance

parseQueues()

Parse the output queues, consuming the available data packets in it and storing them inside opened stream files

close()

Closes opened stream files and tries to perform FFMPEG-based conversion from raw stream into mp4 video.

If successful, each stream file (e.g. color.h265) will be available along with a ready to use video file (e.g. color.mp4).

In case of failure, this method will print traceback and commands that can be used for manual conversion