VideoEncoder
VideoEncoder
isp 输出(>4K 分辨率需要),它是 YUV420,在将其馈送到 VideoEncoder 之前需要转换为 NV12。 这是一个关于 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)输入和输出
Note
输出消息类型
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 / 12MP@20)。分辨率和帧率可以分成多个流,但所有像素/秒的总和必须低于 2.48 亿。
- 由于硬件限制,视频编码只能在宽度值为 32 的倍数的帧上进行。
- 帧的最大宽度为 4096 像素。
共享资源
请注意,编码器的处理资源在 H.26x 和 JPEG 之间共享。
功能示例
参考
class
depthai.node.VideoEncoder(depthai.Node)
method
getBitrate(self) -> int: intGet bitrate in bps
method
getBitrateKbps(self) -> int: intGet bitrate in kbps
method
getFrameRate(self) -> float: floatGet frame rate
method
getHeight(self) -> int: intGet input height
method
getKeyframeFrequency(self) -> int: intGet keyframe frequency
method
getLossless(self) -> bool: boolGet lossless mode. Applies only when using [M]JPEG profile.
method
method
getNumBFrames(self) -> int: intGet number of B frames
method
getNumFramesPool(self) -> int: intGet number of frames in pool Returns: Number of pool frames
method
getProfile(self) -> depthai.VideoEncoderProperties.Profile: depthai.VideoEncoderProperties.ProfileGet profile
method
getQuality(self) -> int: intGet quality
method
getRateControlMode(self) -> depthai.VideoEncoderProperties.RateControlMode: depthai.VideoEncoderProperties.RateControlModeGet rate control mode
method
getSize(self) -> tuple[int, int]: tuple[int, int]Get input size
method
getWidth(self) -> int: intGet input width
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.
需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。