ON THIS PAGE

  • VideoEncoder
  • How to place it
  • Inputs and Outputs
  • Usage
  • Limitations
  • Examples of functionality
  • Reference

VideoEncoder

VideoEncoder node is used to encode ImgFrame into either H264, H265, or MJPEG streams. Only NV12 or GRAY8 (which gets converted to NV12) format is supported as an input. All codecs are lossy (except lossless MJPEG), for more information please see encoding quality docs.Encoded bitstream (either MJPEG, H264, or H265) from the device can also be saved directly into .mp4 container with no computational overhead on the host computer. See demo here. for more information.MatroskaBesides ffmpeg and .mp4 video container (which is patent encumbered), you could also use the mkvmerge (see MKVToolNix for GUI usage) and .mkv video container to mux encoded stream into video file that is supported by all major video players (eg. VLC).
Command Line
1mkvmerge -o vid.mkv video.h265

How to place it

Python
C++

Python

Python
1pipeline = dai.Pipeline()
2encoder = pipeline.create(dai.node.VideoEncoder)

Inputs and Outputs

Usage

Python
C++

Python

Python
1pipeline = dai.Pipeline()
2
3# Create ColorCamera beforehand
4# Set H265 encoding for the ColorCamera video output
5videoEncoder = pipeline.create(dai.node.VideoEncoder)
6videoEncoder.setDefaultProfilePreset(cam.getFps(), dai.VideoEncoderProperties.Profile.H265_MAIN)
7videoEncoder.setBitrateKbps(500) # 0.5 Mbps
8
9# Create MJPEG encoding for still images
10stillEncoder = pipeline.create(dai.node.VideoEncoder)
11stillEncoder.setDefaultProfilePreset(1, dai.VideoEncoderProperties.Profile.MJPEG)
12# stillEncoder.setLossless(True) # Lossless only for MJPEG
13stillEncoder.setQuality(90) # 0-100, 100 being the best quality (not lossless though)
14
15cam.still.link(stillEncoder.input)
16cam.video.link(videoEncoder.input)

Limitations

For H.264 / H.265 encoding, we have the following limits:
  • 248 million pixels/second (4K@30) limit for the encoder. The resolution and frame rate can be divided into multiple streams - but the sum of all the pixels/second needs to be below 248 million.
  • Due to a HW constraint, video encoding can be done only on frames whose width values are multiples of 32.
  • 4096 pixel max width for a frame.
The MJPEG encoder is capable of 16384x8192 resolution at 450 MPix/sec. From our testing, we were able to encode 4K at 30FPS and 2x 800P at 55FPS.Note the processing resources of the encoder are shared between H.26x and JPEG.

Examples of functionality

Reference

class

depthai.node.VideoEncoder(depthai.Node)

method
method
method
method
method
method
getLossless(self) -> bool: bool
Get lossless mode. Applies only when using [M]JPEG profile.
method
method
getNumBFrames(self) -> int: int
Get number of B frames
method
getNumFramesPool(self) -> int: int
Get number of frames in pool  Returns:     Number of pool frames
method
method
method
method
method
method
setBitrate(self, bitrate: int)
Set output bitrate in bps, for CBR rate control mode. 0 for auto (based on frame size and FPS). Applicable only to H264 and H265 profiles
method
setBitrateKbps(self, bitrateKbps: int)
Set output bitrate in kbps, for CBR rate control mode. 0 for auto (based on frame size and FPS). Applicable only to H264 and H265 profiles
method
method
setFrameRate(self, frameRate: float)
Sets expected frame rate  Parameter ``frameRate``:     Frame rate in frames per second
method
setKeyframeFrequency(self, freq: int)
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
method
setLossless(self, arg0: bool)
Set lossless mode. Applies only to [M]JPEG profile  Parameter ``lossless``:     True to enable lossless jpeg encoding, false otherwise
method
setMaxOutputFrameSize(self, maxFrameSize: int)
Specifies maximum output encoded frame size
method
setNumBFrames(self, numBFrames: int)
Set number of B frames to be inserted. Applicable only to H264 and H265 profiles
method
setNumFramesPool(self, frames: int)
Set number of frames in pool  Parameter ``frames``:     Number of pool frames
method
method
setQuality(self, quality: int)
Set quality for [M]JPEG profile  Parameter ``quality``:     Value between 0-100%. Approximates quality
method
setRateControlMode(self, mode: depthai.VideoEncoderProperties.RateControlMode)
Set rate control mode Applicable only to H264 and H265 profiles
property
bitstream
Outputs ImgFrame message that carries BITSTREAM encoded (MJPEG, H264 or H265) frame data. Mutually exclusive with out.
property
input
Input for NV12 ImgFrame to be encoded Default queue is blocking with size set by 'setNumFramesPool' (4).
property
out
Outputs EncodedFrame message that carries encoded (MJPEG, H264 or H265) frame data. Mutually exclusive with bitstream.

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.