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)function
void setProfile(Properties::Profile profile)function
void setBitrate(int bitrate)function
void setBitrateKbps(int bitrateKbps)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)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()function
Properties::Profile getProfile()function
int getBitrate()function
int getBitrateKbps()function
int getKeyframeFrequency()function
int getNumBFrames()function
int getQuality()function
float getFrameRate()function
bool getLossless()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)需要帮助?
请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。