VideoEncoder
最后更新
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)输入和输出
注意
输出消息类型
bitstream 和 out 互斥。用法
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)限制
- 编码器限制为 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.
需要帮助?
请访问讨论论坛以获取技术支持或您可能有的任何其他问题。