5.16. sail.Encoder
Encoder, supporting video and image encoding.
5.16.1. __init__
Encoder init
piture encoder init.
- Interface:
def __init__(self)
video encoder init.
- Interface:
def __init__(self, output_path: str, handle: sail.Handle, enc_fmt: str, pix_fmt: str, enc_params: str)
Parameters:
output_path: str
output path, support local video file and rtsp/rtmp stream.
handle: sail.Hnadle
Handle instance
enc_fmt: str
encoder format, support h264_bm and h265_bm/hevc_bm.
pix_fmt: str
output pixel format, support NV12 and I420。
enc_params: str
encoder params, “width=1902:height=1080:gop=32:gop_preset=3:framerate=25:bitrate=2000”, width and height are necessary. By default, Bitrate is used to control quality, and Bitrate becomes invalid when qp is specified in the parameter.
5.16.2. is_opened
Determine if the encoder is turned on.
- Interface:
def is_opened(self) -> bool
return:
judge_ret: bool
return True when opened, and False when failed.
5.16.3. pic_encode
Encode an image and return the encoded data.
- Interface:
def pic_encode(self, ext: str, image: BMImage)->numpy.array
Parameters:
ext: str
Image encoding format. such as “.jpg”, “.png”
image: sail.BMImage
Input image, only supports picture of FORMAT_BGR_PACKET and DATA_TYPE_EXT_1N_BYTE.
return:
data: numpy.array
Encoded data stored in system memory.
5.16.4. video_write
Send a frame of image to the video encoder
- Interface:
def video_write(self, image: sail.BMImage)->int
Parameters:
image: sail.BMImage
Enter a picture. It is recommended that the pixel format of the input image be consistent with the pixel format specified by the encoder constructor (NV12 or I420), otherwise it will be converted internally in this function.
Return:
judge_ret: int
Success returns 0, failure returns other values.
5.16.5. release
release encoder
- Interface:
def release(self)->None