DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
此页面由 AI 自动翻译。查看英文原版
最后更新

本页目录

  • 如何放置
  • 输入和输出
  • 用法
  • 限制
  • 功能示例
  • 参考
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包

VideoEncoder

最后更新
VideoEncoder 节点用于将 ImgFrame 编码为 H264、H265 或 MJPEG 流。仅支持 NV12 或 GRAY8(将转换为 NV12)格式作为输入。所有编解码器都是有损的(无损 MJPEG 除外),有关更多信息,请参阅编码质量文档。来自设备的编码比特流(MJPEG、H264 或 H265)也可以直接保存到 .mp4 容器中,而主机计算机上没有计算开销。有关更多信息,请参阅此处演示。VideoEncoder 需要 NV12 或 GRAY8 输入格式的帧。因此,其他输出,例如 ColorCamera 的 isp 输出(>4K 分辨率所需),它是 YUV420,需要先转换为 NV12,然后才能将其馈送到 VideoEncoder。 这是一个12MP H265 视频编码 @ 20FPS的示例。Matroska除了 ffmpeg 和 .mp4 视频容器(受专利限制)之外,您还可以使用 mkvmerge (有关 GUI 用法,请参阅 MKVToolNix)和 .mkv 视频容器 将编码流复用到所有主要视频播放器(例如 VLC)支持的视频文件中。
Command Line
1mkvmerge -o vid.mkv video.h265

如何放置

Python

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

C++

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

输入和输出

用法

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)

C++

C++
1dai::Pipeline pipeline;
2
3// Create ColorCamera beforehand
4// Set H265 encoding for the ColorCamera video output
5auto videoEncoder = 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);

限制

对于 H.264 / H.265 编码,我们有以下限制:
  • 编码器限制为 2.48 亿像素/秒(4K@30 / 12MP@20)。分辨率和帧率可以分成多个流 - 但所有像素/秒的总和需要低于 2.48 亿。
  • 由于硬件限制,视频编码只能在宽度值为 32 的倍数的帧上进行。
  • 帧的最大宽度为 4096 像素。
MJPEG 编码器能够以 450 MPix/秒的速度实现 16384x8192 分辨率。根据我们的测试,我们能够以 30FPS 编码 4K,并以 55FPS 编码 2x 800P。

功能示例

参考

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: typing.SupportsInt)
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: typing.SupportsInt)
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: typing.SupportsFloat)
Sets expected frame rate  Parameter ``frameRate``:     Frame rate in frames per second
method
setKeyframeFrequency(self, freq: typing.SupportsInt)
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: typing.SupportsInt)
Specifies maximum output encoded frame size
method
setNumBFrames(self, numBFrames: typing.SupportsInt)
Set number of B frames to be inserted. Applicable only to H264 and H265 profiles
method
setNumFramesPool(self, frames: typing.SupportsInt)
Set number of frames in pool  Parameter ``frames``:     Number of pool frames
method
method
setQuality(self, quality: typing.SupportsInt)
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.

需要帮助?

请访问讨论论坛以获取技术支持或您可能有的任何其他问题。