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)输入和输出
注意
输出消息类型
bitstream 和 out 互斥。用法
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)限制
- 编码器有 2.48 亿像素/秒 (4K@30) 的限制。分辨率和帧率可以分成多个流,但所有像素/秒的总和需要低于 2.48 亿。
- 由于硬件限制,视频编码只能在宽度为 32 的倍数的帧上进行。
- 帧的最大宽度为 4096 像素。
功能示例
- 视频编码 - 将 ColorCamera 的视频流编码为 H264/H265/MJPEG
- RGB 编码和 YOLO - 运行 YOLOv6n 对象检测模型并在视频流上显示结果(边界框),同时将视频流编码为 H264。
参考
class
dai::node::VideoEncoder
variable
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)需要帮助?
请访问讨论论坛以获取技术支持或您可能有的任何其他问题。