此页面由 AI 自动翻译。查看英文原版
最后更新

本页目录

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

VideoEncoder

最后更新
Supported on:RVC2RVC4
VideoEncoder 节点用于将 ImgFrame 编码为 H264、H265 或 MJPEG 流。仅支持 NV12 或 GRAY8(将转换为 NV12)格式作为输入。所有编解码器都是有损的(无损 MJPEG 除外),有关更多信息,请参阅编码质量文档。来自设备的编码比特流(MJPEG、H264 或 H265)也可以直接保存到 .mp4 容器中,而主机计算机上没有计算开销。有关更多信息,请参阅此处演示。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# 预先创建 ColorCamera
4# 为 ColorCamera 视频输出设置 H265 编码
5videoEncoder = pipeline.create(dai.node.VideoEncoder)
6videoEncoder.setDefaultProfilePreset(cam.getFps(), dai.VideoEncoderProperties.Profile.H265_MAIN)
7videoEncoder.setBitrateKbps(500) # 0.5 Mbps
8
9# 为静止图像创建 MJPEG 编码
10stillEncoder = pipeline.create(dai.node.VideoEncoder)
11stillEncoder.setDefaultProfilePreset(1, dai.VideoEncoderProperties.Profile.MJPEG)
12# stillEncoder.setLossless(True) # 仅 MJPEG 支持无损
13stillEncoder.setQuality(90) # 0-100,100 为最佳质量(但不是无损)
14
15cam.still.link(stillEncoder.input)
16cam.video.link(videoEncoder.input)

C++

C++
1dai::Pipeline pipeline;
2
3// 预先创建 ColorCamera
4// 为 ColorCamera 视频输出设置 H265 编码
5auto videoEncoder = pipeline.create<dai::node.VideoEncoder>();
6videoEncoder->setDefaultProfilePreset(cam->getFps(), dai::VideoEncoderProperties::Profile::H265_MAIN);
7videoEncoder->setBitrateKbps(500); // 0.5 Mbps
8
9// 为静止图像创建 MJPEG 编码
10stillEncoder = pipeline.create(dai::node.VideoEncoder);
11stillEncoder->setDefaultProfilePreset(1, dai::VideoEncoderProperties::Profile::MJPEG);
12// stillEncoder->setLossless(true); // 仅 MJPEG 支持无损
13stillEncoder->setQuality(90); // 0-100,100 为最佳质量(但不是无损)
14
15cam->still.link(stillEncoder->input);
16cam->video.link(videoEncoder->input);

限制

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

功能示例

  • 视频编码 - 将 ColorCamera 的视频流编码为 H264/H265/MJPEG
  • RGB 编码和 YOLO - 运行 YOLOv6n 对象检测模型并在视频流上显示结果(边界框),同时将视频流编码为 H264。

参考

class

dai::node::VideoEncoder

#include VideoEncoder.hpp
variable
Input input
Input for NV12 ImgFrame to be encoded
variable
Output bitstream
Outputs ImgFrame message that carries BITSTREAM encoded (MJPEG, H264 or H265) frame data. Mutually exclusive with out.
variable
Output out
Outputs EncodedFrame message that carries encoded (MJPEG, H264 or H265) frame data. Mutually exclusive with bitstream.
function
std::shared_ptr< VideoEncoder > build(Node::Output & input)
function
void setDefaultProfilePreset(float fps, Properties::Profile profile)
Sets a default preset based on specified frame rate and profile
Parameters
  • fps: Frame rate in frames per second
  • profile: Encoding profile
function
void setNumFramesPool(int frames)
Set number of frames in pool
Parameters
  • frames: Number of pool frames
function
int getNumFramesPool()
Get number of frames in pool
Returns
Number of pool frames
function
void setRateControlMode(Properties::RateControlMode mode)
Set rate control mode.
function
void setProfile(Properties::Profile profile)
Set encoding profile.
function
void setBitrate(int bitrate)
Set output bitrate in bps, for CBR rate control mode. 0 for auto (based on frame size and FPS)
function
void setBitrateKbps(int bitrateKbps)
Set output bitrate in kbps, for CBR rate control mode. 0 for auto (based on frame size and FPS)
function
void setKeyframeFrequency(int freq)
Set keyframe frequency. Every Nth frame a keyframe is inserted.Applicable only to H264 and H265 profilesExamples:
  • 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
function
void setNumBFrames(int numBFrames)
Set number of B frames to be inserted.
function
void setQuality(int quality)
Set quality
Parameters
  • quality: Value between 0-100%. Approximates quality
function
void setLossless(bool lossless)
Set lossless mode. Applies only to [M]JPEG profile
Parameters
  • lossless: True to enable lossless jpeg encoding, false otherwise
function
void setFrameRate(float frameRate)
Sets expected frame rate
Parameters
  • frameRate: Frame rate in frames per second
function
void setMaxOutputFrameSize(int maxFrameSize)
Specifies maximum output encoded frame size
function
Properties::RateControlMode getRateControlMode()
Get rate control mode.
function
Properties::Profile getProfile()
Get profile.
function
int getBitrate()
Get bitrate in bps.
function
int getBitrateKbps()
Get bitrate in kbps.
function
int getKeyframeFrequency()
Get keyframe frequency.
function
int getNumBFrames()
Get number of B frames.
function
int getQuality()
Get quality.
function
float getFrameRate()
Get frame rate.
function
bool getLossless()
Get lossless mode. Applies only when using [M]JPEG profile.
function
int getMaxOutputFrameSize()
inline function
DeviceNodeCRTP()
inline function
DeviceNodeCRTP(const std::shared_ptr< Device > & device)
inline function
DeviceNodeCRTP(std::unique_ptr< Properties > props)
inline function
DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)
inline function
DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

需要帮助?

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