VideoEncoder

VideoEncoder node is used to encode image frames into H264/H265/JPEG.

How to place it

pipeline = dai.Pipeline()
encoder = pipeline.create(dai.node.VideoEncoder)
dai::Pipeline pipeline;
auto encoder = pipeline.create<dai::node::VideoEncoder>();

Inputs and Outputs

          ┌──────────────┐
          │              │
 input    │              │bitstream
─────────►│ VideoEncoder ├────────►
          │              │
          │              │
          └──────────────┘

Message types

Usage

pipeline = dai.Pipeline()

# Create ColorCamera beforehand
# Set H265 encoding for the ColorCamera video output
videoEncoder = pipeline.create(dai.node.VideoEncoder)
videoEncoder.setDefaultProfilePreset(cam.getVideoSize(), cam.getFps(), dai.VideoEncoderProperties.Profile.H265_MAIN)

# Create MJPEG encoding for still images
stillEncoder = pipeline.create(dai.node.VideoEncoder)
stillEncoder.setDefaultProfilePreset(cam.getStillSize(), 1, dai.VideoEncoderProperties.Profile.MJPEG)

cam.still.link(stillEncoder.input)
cam.video.link(videoEncoder.input)
dai::Pipeline pipeline;

// Create ColorCamera beforehand
// Set H265 encoding for the ColorCamera video output
auto videoEncoder = pipeline.create<dai::node::VideoEncoder>();
videoEncoder->setDefaultProfilePreset(cam->getVideoSize(), cam->getFps(), dai::VideoEncoderProperties::Profile::H265_MAIN);

// Create MJPEG encoding for still images
stillEncoder = pipeline.create(dai.node.VideoEncoder);
stillEncoder->setDefaultProfilePreset(cam->getStillSize(), 1, dai::VideoEncoderProperties::Profile::MJPEG);

cam->still.link(stillEncoder->input);
cam->video.link(videoEncoder->input);

Limitations

  • Due to a HW constraint, video encoding can be done only on frames whose width values are multiples of 32.

Reference

class depthai.node.VideoEncoder

VideoEncoder node. Encodes frames into MJPEG, H264 or H265.

class Connection

Connection between an Input and Output

class Id

Node identificator. Unique for every node on a single Pipeline

Properties

alias of depthai.VideoEncoderProperties

property bitstream

Outputs ImgFrame message that carries BITSTREAM encoded (MJPEG, H264 or H265) frame data.

getAssetManager(*args, **kwargs)

Overloaded function.

  1. getAssetManager(self: depthai.Node) -> depthai.AssetManager

Get node AssetManager as a const reference

  1. getAssetManager(self: depthai.Node) -> depthai.AssetManager

Get node AssetManager as a const reference

getBitrate(self: depthai.node.VideoEncoder)int

Get bitrate in bps

getBitrateKbps(self: depthai.node.VideoEncoder)int

Get bitrate in kbps

getFrameRate(self: depthai.node.VideoEncoder)float

Get frame rate

getHeight(self: depthai.node.VideoEncoder)int

Get input height

getInputRefs(*args, **kwargs)

Overloaded function.

  1. getInputRefs(self: depthai.Node) -> List[depthai.Node.Input]

Retrieves reference to node inputs

  1. getInputRefs(self: depthai.Node) -> List[depthai.Node.Input]

Retrieves reference to node inputs

getInputs(self: depthai.Node) → List[depthai.Node.Input]

Retrieves all nodes inputs

getKeyframeFrequency(self: depthai.node.VideoEncoder)int

Get keyframe frequency

getLossless(self: depthai.node.VideoEncoder)bool

Get lossless mode. Applies only when using [M]JPEG profile.

getName(self: depthai.Node)str

Retrieves nodes name

getNumBFrames(self: depthai.node.VideoEncoder)int

Get number of B frames

getNumFramesPool(self: depthai.node.VideoEncoder)int

Get number of frames in pool

Returns

Number of pool frames

getOutputRefs(*args, **kwargs)

Overloaded function.

  1. getOutputRefs(self: depthai.Node) -> List[depthai.Node.Output]

Retrieves reference to node outputs

  1. getOutputRefs(self: depthai.Node) -> List[depthai.Node.Output]

Retrieves reference to node outputs

getOutputs(self: depthai.Node) → List[depthai.Node.Output]

Retrieves all nodes outputs

getParentPipeline(*args, **kwargs)

Overloaded function.

  1. getParentPipeline(self: depthai.Node) -> depthai.Pipeline

  2. getParentPipeline(self: depthai.Node) -> depthai.Pipeline

getProfile(self: depthai.node.VideoEncoder)depthai.VideoEncoderProperties.Profile

Get profile

getQuality(self: depthai.node.VideoEncoder)int

Get quality

getRateControlMode(self: depthai.node.VideoEncoder)depthai.VideoEncoderProperties.RateControlMode

Get rate control mode

getSize(self: depthai.node.VideoEncoder) → Tuple[int, int]

Get input size

getWidth(self: depthai.node.VideoEncoder)int

Get input width

property id

Id of node

property input

Input for NV12 ImgFrame to be encoded Default queue is blocking with size set by ‘setNumFramesPool’ (4).

setBitrate(self: depthai.node.VideoEncoder, bitrateKbps: int)None

Set output bitrate in bps. Final bitrate depends on rate control mode

setBitrateKbps(self: depthai.node.VideoEncoder, bitrateKbps: int)None

Set output bitrate in kbps. Final bitrate depends on rate control mode

setDefaultProfilePreset(*args, **kwargs)

Overloaded function.

  1. setDefaultProfilePreset(self: depthai.node.VideoEncoder, width: int, height: int, fps: float, profile: depthai.VideoEncoderProperties.Profile) -> None

Sets a default preset based on specified input size, frame rate and profile

Parameter width:

Input frame width

Parameter height:

Input frame height

Parameter fps:

Frame rate in frames per second

Parameter profile:

Encoding profile

  1. setDefaultProfilePreset(self: depthai.node.VideoEncoder, size: Tuple[int, int], fps: float, profile: depthai.VideoEncoderProperties.Profile) -> None

Sets a default preset based on specified input size, frame rate and profile

Parameter size:

Input frame size

Parameter fps:

Frame rate in frames per second

Parameter profile:

Encoding profile

setFrameRate(self: depthai.node.VideoEncoder, frameRate: float)None

Sets expected frame rate

Parameter frameRate:

Frame rate in frames per second

setKeyframeFrequency(self: depthai.node.VideoEncoder, freq: int)None

Set keyframe frequency. Every Nth frame a keyframe is inserted.

Applicable only to H264 and H265 profiles

Examples:

  • 30 FPS video, keyframe frequency: 30. Every 1s a keyframe will be inserted

  • 60 FPS video, keyframe frequency: 180. Every 3s a keyframe will be inserted

setLossless(self: depthai.node.VideoEncoder, arg0: bool)None

Set lossless mode. Applies only to [M]JPEG profile

Parameter lossless:

True to enable lossless jpeg encoding, false otherwise

setNumBFrames(self: depthai.node.VideoEncoder, numBFrames: int)None

Set number of B frames to be inserted

setNumFramesPool(self: depthai.node.VideoEncoder, frames: int)None

Set number of frames in pool

Parameter frames:

Number of pool frames

setProfile(*args, **kwargs)

Overloaded function.

  1. setProfile(self: depthai.node.VideoEncoder, size: Tuple[int, int], profile: depthai.VideoEncoderProperties.Profile) -> None

Set encoding profile

  1. setProfile(self: depthai.node.VideoEncoder, width: int, height: int, profile: depthai.VideoEncoderProperties.Profile) -> None

Set encoding profile

setQuality(self: depthai.node.VideoEncoder, quality: int)None

Set quality

Parameter quality:

Value between 0-100%. Approximates quality

setRateControlMode(self: depthai.node.VideoEncoder, mode: depthai.VideoEncoderProperties.RateControlMode)None

Set rate control mode

class dai::node::VideoEncoder : public dai::Node

VideoEncoder node. Encodes frames into MJPEG, H264 or H265.

Public Types

using Properties = dai::VideoEncoderProperties

Public Functions

std::string getName() const override

Retrieves nodes name.

VideoEncoder(const std::shared_ptr<PipelineImpl> &par, int64_t nodeId)
void setDefaultProfilePreset(int width, int height, float fps, Properties::Profile profile)

Sets a default preset based on specified input size, frame rate and profile

Parameters
  • width: Input frame width

  • height: Input frame height

  • fps: Frame rate in frames per second

  • profile: Encoding profile

void setDefaultProfilePreset(std::tuple<int, int> size, float fps, Properties::Profile profile)

Sets a default preset based on specified input size, frame rate and profile

Parameters
  • size: Input frame size

  • fps: Frame rate in frames per second

  • profile: Encoding profile

void setNumFramesPool(int frames)

Set number of frames in pool

Parameters
  • frames: Number of pool frames

int getNumFramesPool() const

Get number of frames in pool

Return

Number of pool frames

void setRateControlMode(Properties::RateControlMode mode)

Set rate control mode.

void setProfile(std::tuple<int, int> size, Properties::Profile profile)

Set encoding profile.

void setProfile(int width, int height, Properties::Profile profile)

Set encoding profile.

void setBitrate(int bitrate)

Set output bitrate in bps. Final bitrate depends on rate control mode.

void setBitrateKbps(int bitrateKbps)

Set output bitrate in kbps. Final bitrate depends on rate control mode.

void setKeyframeFrequency(int freq)

Set keyframe frequency. Every Nth frame a keyframe is inserted.

Applicable only to H264 and H265 profiles

Examples:

  • 30 FPS video, keyframe frequency: 30. Every 1s a keyframe will be inserted

  • 60 FPS video, keyframe frequency: 180. Every 3s a keyframe will be inserted

void setNumBFrames(int numBFrames)

Set number of B frames to be inserted.

void setQuality(int quality)

Set quality

Parameters
  • quality: Value between 0-100%. Approximates quality

void setLossless(bool lossless)

Set lossless mode. Applies only to [M]JPEG profile

Parameters
  • lossless: True to enable lossless jpeg encoding, false otherwise

void setFrameRate(float frameRate)

Sets expected frame rate

Parameters
  • frameRate: Frame rate in frames per second

Properties::RateControlMode getRateControlMode() const

Get rate control mode.

Properties::Profile getProfile() const

Get profile.

int getBitrate() const

Get bitrate in bps.

int getBitrateKbps() const

Get bitrate in kbps.

int getKeyframeFrequency() const

Get keyframe frequency.

int getNumBFrames() const

Get number of B frames.

int getQuality() const

Get quality.

std::tuple<int, int> getSize() const

Get input size.

int getWidth() const

Get input width.

int getHeight() const

Get input height.

float getFrameRate() const

Get frame rate.

bool getLossless() const

Get lossless mode. Applies only when using [M]JPEG profile.

Public Members

Input input = {*this, "in", Input::Type::SReceiver, true, 4, {{DatatypeEnum::ImgFrame, true}}}

Input for NV12 ImgFrame to be encoded Default queue is blocking with size set by ‘setNumFramesPool’ (4).

Output bitstream = {*this, "bitstream", Output::Type::MSender, {{DatatypeEnum::ImgFrame, false}}}

Outputs ImgFrame message that carries BITSTREAM encoded (MJPEG, H264 or H265) frame data.

Private Functions

nlohmann::json getProperties() override
std::shared_ptr<Node> clone() override

Private Members

Properties properties

Got questions?

We’re always happy to help with code or other questions you might have.