4.2. 多媒体接口使用说明
4.2.1. 模块概要介绍
4.2.1.1. 模块名
hobot_vio
是python包名,libsrcampy
是模块名称,里面包含四个子模块,分别为Camera
、Encoder
、Decoder
、Display
。
4.2.1.2. 创建对象的方法
导入模块: from hobot_vio import libsrcampy
对象 = libsrcampy.<模块名>
4.2.1.3. 使用模块对应的方法
<模块名>.<方法>
比如img = cam.get_img()
,返回值为具体的对象,可以对该对象进行具体的操作。
4.2.2. libsrcampy(系统设定)API
4.2.2.1. bind
【函数声明】
bind(src,dst)
【功能描述】
本接口可以把 Camera
,Encoder
,Decoder
,Display
, 这四个模块的输出与输入进行内部绑定,绑定后的两个模块的数据会在内部自动流转,无需用户操作。
比如绑定 Camera
和 Display
后,打开的mipi摄像头的数据会直接显示到显示屏上,不需要调用Camera
的get_img
接口获取数据,之后再调用Display
的set_img
接口进行显示。
【参数描述】
参数名称 | 描述 |
---|---|
src | 源数据模块 |
dst | 目标数据模块 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】无
【参考代码】接口使用示例代码
4.2.2.2. unbind
【函数声明】
unbind(src, dst)
【功能描述】
解绑两个模块
【参数描述】
参数名称 | 描述 |
---|---|
src | 源数据模块 |
dst | 目标数据模块 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】无
【参考代码】接口使用示例代码
4.2.3. Camera(视频输入)API
libsrcampy.Camera
:
4.2.3.1. open_cam
【函数声明】
open_cam(pipe_id,video_index ,fps = 30,width = 1920, height = 1080)
【功能描述】
初始化接入到旭日X3派上的MIPI摄像头。 设置输出分辨率,支持设置最多5组分辨率,其中只有1组可以放大,4组可以缩小。最大支持放大到原始图像的1.5倍,最小支持缩小到原始图像的1/8。
【参数描述】
参数名称 | 描述 |
---|---|
pipe_id | 当前pipeline所属pipe_id |
video_index | video_index 对应camera的索引 1:F37, GC4663 |
fps | camera输出帧率 |
width | camera输出宽,默认值与具体camera有关;类型也可为列表类型,表示多开通道,最多开5个 |
height | camera输出高,默认值与具体camera有关;类型也可为列表类型,表示多开通道,最多开5个 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.默认开启一路与MIPI摄像头相同分辨率的通道,无需设置,该通道不计入5个通道之内
【参考代码】接口使用示例代码
4.2.3.2. open_vps
【函数声明】
open_vps(pipe_id = 1, proc_mode = 0, src_width = 1920, src_height = 1080,dst_width = 0,dst_height = 0, crop_rect = [0, 0],rotate = 0, src_size = [1920, 1080], dst_size = [0, 0])
【功能描述】
打开一路图像处理模块,支持对输入的图像完成缩小、放大、旋转、裁剪任务。
【参数描述】
参数名称 | 描述 |
---|---|
pipe_id | 当前pipeline所属pipe_id |
proc_mode | vps处理模式 1.缩放 2.缩放+裁剪 3.缩放+旋转 4.缩放+裁剪+旋转 |
src_width | vps输入宽 |
src_height | vps输入宽 |
dst_width | 缩放功能输出宽,默认输出跟输入相同尺寸;类型也可为列表类型,表示多开通道,最多开6个 |
dst_height | 缩放功能输出高,默认输出跟输入相同尺寸;类型也可为列表类型,表示多开通道,最多开6个 |
crop_rect | 裁剪功能的区域,以列表形式传入,嵌套列表的时候每个列表代表一个通道的裁剪区域,最多6个; 注:裁剪在缩放之前处理 |
rotate | 旋转角度,最多对两个通道使能旋转 0.0度 1.90度 2.180度 3.270度 |
src_size | 输入宽高传参优化,与src_width和src_height参数功能相同,可以以列表传入 [1920,1080] |
dst_size | 输出宽高传参优化,与dst_width和dst_height参数功能相同,可以以列表传入 [[1920,1080], [1920, 1080]] |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.若设置输出宽高不足6个通道,会默认多开启一路原图输出;
【参考代码】接口使用示例代码
4.2.3.3. get_img
【函数声明】
get_img(module = 2,width,height)
【功能描述】
获取图像,需要在open_cam
、open_vps
之后调用
【参数描述】
参数名称 | 描述 |
---|---|
module | 获取对应模块的图像,0:SIF 1: ISP 2:IPU,建议使用2,除非你知道0和1具体代表什么意思 |
width | 当module为IPU时,可选择指定输出宽高(原图或open_cam时指定的宽高) |
height | 同上 |
【返回值】
返回值 | 描述 |
---|---|
bytes | 成功 |
none | 失败 |
【注意事项】
1.需要在open_cam
、open_vps
之后调用;
【参考代码】接口使用示例代码
4.2.3.4. set_img
【函数声明】
set_img(img)
【功能描述】
将图片回灌回VPS
进行处理
【参数描述】
参数名称 | 描述 |
---|---|
img | 需要处理的图像buffer |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.需要在open_vps
之后调用;
【参考代码】接口使用示例代码
4.2.3.5. close_cam
【函数声明】
close_cam()
【功能描述】
关闭camera
【参数描述】无
【返回值】
返回值 | 描述 |
---|---|
none |
【注意事项】
1.调用open_cam
之后,退出程序时调用;
【参考代码】接口使用示例代码
4.2.4. Encode(编码模块)API
libsrcampy.Encoder
:
4.2.4.1. encode(编码模块)API
【函数声明】
encode(video_chn, encode_type , width, height, bits = 8000)
【功能描述】
编码模块的encode
方法,用于图像的编码
【参数描述】
参数名称 | 描述 |
---|---|
video_chn | 对应的编码器通道(0-31) |
encode_type | 编码类型 1:H264 2:H265 3:MJPEG |
width | 编码的图像宽度 |
height | 编码的图像高度 |
bits | 编码速率,默认为8000 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】无
【参考代码】接口使用示例代码
4.2.4.2. encode_file
【函数声明】
encode_file(img)
【功能描述】
编码模块的encode
方法,用于图像文件的编码
【参数描述】
参数名称 | 描述 |
---|---|
img | 需要编码的YUV buffer,需要使用NV12格式 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】无
【参考代码】接口使用示例代码
4.2.4.3. get_img
【函数声明】
get_img()
【功能描述】
编码模块的get_img
方法,返回python对象该接口内部会释放buffer,无需用户释放
【参数描述】无
【返回值】
返回值 | 描述 |
---|---|
bytes | 成功 |
none | 失败 |
【注意事项】
1.需要在encode
之后调用;
【参考代码】接口使用示例代码
4.2.4.4. close
【函数声明】
close()
【功能描述】
编码模块的close
方法,关闭编码模块
【参数描述】无
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.调用encode
或encode_file
之后,退出程序时调用;
【参考代码】接口使用示例代码
4.2.5. Decode(解码模块)API
libsrcampy.Decoder
:
4.2.5.1. decode
【函数声明】
decode(file, video_chn,decode_type, width, height,dec_mode = 1)
【功能描述】
解码模块的decode
方法,用于图像的解码
【参数描述】
参数名称 | 描述 |
---|---|
file | 需要解码的文件名 |
video_chn | 对应的解码器通道(0-31) |
decode_type | 编码类型 1:H264 2:H265 3:MJPEG |
width | 解码的图像宽度 |
height | 解码的图像高度 |
【返回值】
decode
返回2个值的元祖。
返回值 | 描述 | |
---|---|---|
list[0] | 0 | 成功 |
list[0] | 非0 | 失败 |
list[1] | frame_count | 当前码流文件的帧数 |
【参考代码】接口使用示例代码
4.2.5.2. get_img
【函数声明】
get_img()
【功能描述】
解码模块的get_img
方法,返回python对象,返回python对象该接口内部会释放buffer,无需用户释放
【参数描述】无
【返回值】
返回值 | 描述 |
---|---|
bytes | 成功 |
none | 失败 |
【注意事项】
1.需要在decode
之后调用;
【参考代码】接口使用示例代码
4.2.5.3. set_img
【函数声明】
set_img(img,chn = 0, eos = 0)
【功能描述】
解码模块的set_img
方法
【参数描述】
参数名称 | 描述 |
---|---|
img | 需要解码的以bytes保存的NV12 buffer |
chn | 解码器通道号 |
eos | 解码是否结束 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.需要在deocde
使能之后调用;
【参考代码】接口使用示例代码
4.2.5.4. close
【函数声明】
close()
【功能描述】
解码模块的close
方法,关闭解码模块
【参数描述】无
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.调用decode
之后,退出程序时调用;
【参考代码】接口使用示例代码
4.2.6. Display(显示模块)API
libsrcampy.Display
:
4.2.6.1. display
【函数声明】
display(chn = 0, width = 1920, height = 1080, vot_intf = 0, vot_out_mode = 1)
【功能描述】
显示模块的display
方法,用于图像显示初始化
【参数描述】
参数名称 | 描述 |
---|---|
chn | chn 显示输出层,0~1为video层,2~3为图形层 |
width | 显示的图像宽度 |
height | 显示的图像高度 |
vot_intf | 默认0为VOT_OUTPUT_1920x1080,表示硬件层输出分辨率 |
vot_out_mode | 默认输出模式1为HDMI输出,表示硬件层的输出接口 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】无
【参考代码】接口使用示例代码
4.2.6.2. set_img
【函数声明】
set_img(img)
【功能描述】
将传入的img
数据输出到display
函数绑定的显示模块,如显示器
【参数描述】
以bytes
储存的NV12
格式图片
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.需要在display
之后调用;
【参考代码】接口使用示例代码
4.2.6.3. set_graph_rect
【函数声明】
set_graph_rect(x0, y0, x1, y1, chn = 2, flush = 0,color = 0xffff0000,line_width = 4)
【功能描述】
显示模块的set_graph_rect
方法,在显示模块的图形层绘制矩形框
【参数描述】
参数名称 | 描述 |
---|---|
x0 | 绘制矩形框第一个坐标的x值 |
y0 | 绘制矩形框第一个坐标的y值 |
x1 | 绘制矩形框第二个坐标的x值 |
y1 | 绘制矩形框第二个坐标的y值 |
chn | chn 显示输出层,2\~3为图形层 |
flush | 是否清零当前图形层buffer |
color | 矩形框颜色(颜色格式为ARGB8888) |
line_width | 矩形框边的宽度 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.需要在display
使能图形层之后调用;
【参考代码】接口使用示例代码
4.2.6.4. set_graph_word
【函数声明】
set_graph_word(x, y, str, chn = 2, flush = 0, color = 0xffff0000, line_width = 1)
【功能描述】
显示模块的set_graph_word
方法,在显示模块的图形层绘制字符串
【参数描述】
参数名称 | 描述 |
---|---|
x | 绘制字符串起始坐标的x值 |
y | 绘制字符串起始坐标的y值 |
str | 需要绘制的字符串(需要是GB2312编码) |
chn | chn 显示输出层,2\~3为图形层 |
flush | 是否清零当前图形层buffer |
color | 字体颜色(颜色格式为ARGB8888) |
line_width | 字体边的宽度 |
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.需要在display
使能图形层之后调用;
【参考代码】接口使用示例代码
4.2.6.5. close
【函数声明】
close()
【功能描述】
显示模块的close
方法,关闭显示模块
【参数描述】无
【返回值】
返回值 | 描述 |
---|---|
0 | 成功 |
非0 | 失败 |
【注意事项】
1.调用display
之后,退出程序时调用;
【参考代码】接口使用示例代码
4.2.7. 接口使用示例代码
以下示例代码分成多个测试用例,覆盖了全部的接口使用:
import sys, os, time
sys.path.append('/usr/lib/hobot-srcampy')
import numpy as np
import cv2
import libsrcampy
def get_nalu_pos(byte_stream):
size = byte_stream.__len__()
nals = []
retnals = []
startCodePrefixShort = b"\x00\x00\x01"
pos = 0
while pos < size:
is4bytes = False
retpos = byte_stream.find(startCodePrefixShort, pos)
if retpos == -1:
break
if byte_stream[retpos - 1] == 0:
retpos -= 1
is4bytes = True
if is4bytes:
pos = retpos + 4
else:
pos = retpos + 3
val = hex(byte_stream[pos])
val = "{:d}".format(byte_stream[pos], 4)
val = int(val)
fb = (val >> 7) & 0x1
nri = (val >> 5) & 0x3
type = val & 0x1f
nals.append((pos, is4bytes, fb, nri, type))
for i in range(0, len(nals) - 1):
start = nals[i][0]
if nals[i + 1][1]:
end = nals[i + 1][0] - 5
else:
end = nals[i + 1][0] - 4
retnals.append((start, end, nals[i][1], nals[i][2], nals[i][3], nals[i][4]))
start = nals[-1][0]
end = byte_stream.__len__() - 1
retnals.append((start, end, nals[-1][1], nals[-1][2], nals[-1][3], nals[-1][4]))
return retnals
def get_h264_nalu_type(byte_stream):
nalu_types = []
nalu_pos = get_nalu_pos(byte_stream)
for idx, (start, end, is4bytes, fb, nri, type) in enumerate(nalu_pos):
# print("NAL#%d: %d, %d, %d, %d, %d" % (idx, start, end, fb, nri, type))
nalu_types.append(type)
return nalu_types
def test_camera():
cam = libsrcampy.Camera()
ret = cam.open_cam(0, 1, 30, 1920, 1080)
print("Camera open_cam return:%d" % ret)
# wait for isp tuning
time.sleep(1)
img = cam.get_img(2)
if img is not None:
#save file
fo = open("output.img", "wb")
fo.write(img)
fo.close()
print("camera save img file success")
else:
print("camera save img file failed")
cam.close_cam()
print("test_camera done!!!")
def test_camera_vps():
#vps start
vps = libsrcampy.Camera()
ret = vps.open_vps(1, 1, 1920, 1080, 512, 512)
print("Camera vps return:%d" % ret)
fin = open("output.img", "rb")
img = fin.read()
fin.close()
ret = vps.set_img(img)
print ("Process set_img return:%d" % ret)
fo = open("output_vps.img", "wb+")
img = vps.get_img()
if img is not None:
fo.write(img)
print("encode write image success")
else:
print("encode write image failed")
fo.close()
vps.close_cam()
print("test_camera_vps done!!!")
def test_encode():
#encode file
enc = libsrcampy.Encoder()
ret = enc.encode(0, 1, 1920, 1080)
print("Encoder encode return:%d" % ret)
#save file
fo = open("encode.h264", "wb+")
a = 0
fin = open("output.img", "rb")
input_img = fin.read()
fin.close()
while a < 100:
ret = enc.encode_file(input_img)
print("Encoder encode_file return:%d" % ret)
img = enc.get_img()
if img is not None:
fo.write(img)
print("encode write image success count: %d" % a)
else:
print("encode write image failed count: %d" % a)
a = a + 1
enc.close()
print("test_encode done!!!")
def test_decode():
#decode start
dec = libsrcampy.Decoder()
ret = dec.decode("encode.h264", 0, 1, 1920, 1080)
print ("Decoder return:%d frame count: %d" %(ret[0], ret[1]))
img = dec.get_img()
if img is not None:
#save file
fo = open("output.img", "wb")
fo.write(img)
fo.close()
print("decode save img file success")
else:
print("decode save img file failed")
dec.close()
print("test_decode done!!!")
def test_display():
disp = libsrcampy.Display()
ret = disp.display(0, 1920, 1080, 0, 1)
print ("Display display 0 return:%d" % ret)
ret = disp.display(2)
print ("Display display 2 return:%d" % ret)
ret = disp.set_graph_rect(100, 100, 1920, 200, chn = 2, flush = 1, color = 0xffff00ff)
print ("Display set_graph_rect return:%d" % ret)
string = "horizon"
ret = disp.set_graph_word(300, 300, string.encode('gb2312'), 2, 0, 0xff00ffff)
print ("Display set_graph_word return:%d" % ret)
fo = open("output.img", "rb")
img = fo.read()
fo.close()
ret = disp.set_img(img)
print ("Display set_img return:%d" % ret)
time.sleep(3)
disp.close()
print("test_display done!!!")
def test_camera_bind_encode():
#camera start
cam = libsrcampy.Camera()
ret = cam.open_cam(0, 1, 30, [1920, 1280], [1080, 720])
print("Camera open_cam return:%d" % ret)
#encode start
enc = libsrcampy.Encoder()
ret = enc.encode(0, 1, 1920, 1080)
print("Encoder encode return:%d" % ret)
ret = libsrcampy.bind(cam, enc)
print("libsrcampy bind return:%d" % ret)
enc1 = libsrcampy.Encoder()
ret = enc1.encode(1, 1, 1280, 720)
print("Encoder encode return:%d" % ret)
ret = libsrcampy.bind(cam, enc1)
print("libsrcampy bind return:%d" % ret)
#save file
fo = open("encode.h264", "wb+")
fo1 = open("encode1.h264", "wb+")
a = 0
while a < 100:
img = enc.get_img()
img1 = enc1.get_img()
if img is not None:
fo.write(img)
fo1.write(img1)
print("encode write image success count: %d" % a)
else:
print("encode write image failed count: %d" % a)
a = a + 1
fo.close()
fo1.close()
print("save encode file success")
ret = libsrcampy.unbind(cam, enc)
print("libsrcampy unbind return:%d" % ret)
ret = libsrcampy.unbind(cam, enc1)
print("libsrcampy unbind return:%d" % ret)
enc1.close()
enc.close()
cam.close_cam()
print("test_camera_bind_encode done!!!")
def test_camera_bind_display():
#camera start
cam = libsrcampy.Camera()
ret = cam.open_cam(0, 1, 30, 1280, 720)
print("Camera open_cam return:%d" % ret)
#display start
disp = libsrcampy.Display()
ret = disp.display(0, 1920, 1080, 0, 1, chn_width = 1280, chn_height = 720)
print ("Display display 0 return:%d" % ret)
ret = disp.display(2, chn_width = 1280, chn_height = 720)
print ("Display display 2 return:%d" % ret)
disp.set_graph_rect(100, 100, 1920, 200, chn = 2, flush = 1, color = 0xffff00ff)
string = "horizon"
disp.set_graph_word(300, 300, string.encode('gb2312'), 2, 0, 0xff00ffff)
ret = libsrcampy.bind(cam, disp)
print("libsrcampy bind return:%d" % ret)
time.sleep(10)
ret = libsrcampy.unbind(cam, disp)
print("libsrcampy unbind return:%d" % ret)
disp.close()
cam.close_cam()
print("test_camera_bind_display done!!!")
def test_decode_bind_display():
#decode start
dec = libsrcampy.Decoder()
ret = dec.decode("encode.h264", 0, 1, 1920, 1080)
print ("Decoder return:%d frame count: %d" %(ret[0], ret[1]))
dec1 = libsrcampy.Decoder()
ret = dec1.decode("encode1.h264", 1, 1, 1280, 720)
print ("Decoder return:%d frame count: %d" %(ret[0], ret[1]))
#display start
disp = libsrcampy.Display()
ret = disp.display(0, 1920, 1080, 0, 1)
print ("Display display 0 return:%d" % ret)
ret = disp.display(2)
print ("Display display 2 return:%d" % ret)
disp.set_graph_rect(100, 100, 1920, 200, chn = 2, flush = 1, color = 0xffff00ff)
string = "horizon"
disp.set_graph_word(300, 300, string.encode('gb2312'), 2, 0, 0xff00ffff)
ret = libsrcampy.bind(dec, disp)
print("libsrcampy bind return:%d" % ret)
time.sleep(5)
ret = libsrcampy.unbind(dec, disp)
print("libsrcampy unbind return:%d" % ret)
disp.close()
dec1.close()
dec.close()
print("test_decode_bind_display done!!!")
def test_cam_bind_encode_decode_bind_display():
#camera start
cam = libsrcampy.Camera()
ret = cam.open_cam(0, 1, 30, [1920, 1280], [1080, 720])
print("Camera open_cam return:%d" % ret)
#encode file
enc = libsrcampy.Encoder()
ret = enc.encode(0, 1, 1920, 1080)
print("Encoder encode return:%d" % ret)
#decode start
dec = libsrcampy.Decoder()
ret = dec.decode("", 0, 1, 1920, 1080)
print ("Decoder return:%d frame count: %d" %(ret[0], ret[1]))
#display start
disp = libsrcampy.Display()
ret = disp.display(0, 1920, 1080, 0, 1)
print ("Display display 0 return:%d" % ret)
ret = libsrcampy.bind(cam, enc)
print("libsrcampy bind return:%d" % ret)
ret = libsrcampy.bind(dec, disp)
print("libsrcampy bind return:%d" % ret)
a = 0
while a < 100:
img = enc.get_img()
if img is not None:
dec.set_img(img)
print("encode get image success count: %d" % a)
else:
print("encode get image failed count: %d" % a)
a = a + 1
ret = libsrcampy.unbind(cam, enc)
ret = libsrcampy.unbind(dec, disp)
disp.close()
dec.close()
enc.close()
cam.close_cam()
print("test_cam_bind_encode_decode_bind_display done!!!")
def test_cam_vps_display():
#camera start
cam = libsrcampy.Camera()
ret = cam.open_cam(0, 1, 30, [1920, 1280], [1080, 720])
print("Camera open_cam return:%d" % ret)
#vps start
vps = libsrcampy.Camera()
ret = vps.open_vps(1, 1, 1920, 1080, 512, 512)
print("Camera vps return:%d" % ret)
#display start
disp = libsrcampy.Display()
ret = disp.display(0, 1920, 1080, 0, 1)
print ("Display display 0 return:%d" % ret)
a = 0
while a < 100:
img = cam.get_img()
if img is not None:
vps.set_img(img)
print("camera get image success count: %d" % a)
else:
print("camera get image failed count: %d" % a)
img = vps.get_img(2, 1920, 1080)
if img is not None:
disp.set_img(img)
print("vps get image success count: %d" % a)
else:
print("vps get image failed count: %d" % a)
a = a + 1
disp.close()
vps.close_cam()
cam.close_cam()
print("test_cam_vps_display done!!!")
def test_rtsp_decode_bind_vps_bind_disp(rtsp_url):
start_time = time.time()
image_count = 0
skip_count = 0
find_pps_sps = 0
#rtsp start
cap = cv2.VideoCapture(rtsp_url)
cap.set(cv2.CAP_PROP_FORMAT, -1) # get stream
if not cap.isOpened():
print("fail to open rtsp: {}".format(rtsp_url))
return -1
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
#decode start
dec = libsrcampy.Decoder()
ret = dec.decode("", 0, 1, width, height)
print ("Decoder return:%d frame count: %d" %(ret[0], ret[1]))
#camera start
vps = libsrcampy.Camera()
ret = vps.open_vps(0, 1, width, height, [1920, 512], [1080, 512])
print("Camera open_cam return:%d" % ret)
#display start
disp = libsrcampy.Display()
ret = disp.display(0, 1920, 1080, 0, 1)
print ("Display display 0 return:%d" % ret)
ret = libsrcampy.bind(dec, vps)
print("libsrcampy bind return:%d" % ret)
ret = libsrcampy.bind(vps, disp)
print("libsrcampy bind return:%d" % ret)
a = 0
while True:
ret, stream_frame = cap.read()
if not ret:
return
nalu_types = get_h264_nalu_type(stream_frame.tobytes())
# 送入解码的第一帧需要是 pps,sps, 否则解码器会报 "FAILED TO DEC_PIC_HDR" 异常而退出
if (nalu_types[0] in [1, 5]) and find_pps_sps == 0:
continue
find_pps_sps = 1
if stream_frame is not None:
ret = dec.set_img(stream_frame.tobytes(), 0) # 发送码流, 先解码数帧图像后再获取
if ret != 0:
return ret
if skip_count < 5:
skip_count += 1
image_count = 0
continue
ret = libsrcampy.unbind(dec, vps)
ret = libsrcampy.unbind(vps, disp)
disp.close()
dec.close()
vps.close_cam()
cap.release()
print("test_rtsp_decode_bind_vps_bind_disp done!!!")
test_camera()
test_camera_vps()
test_encode()
test_decode()
test_display()
test_camera_bind_encode()
test_camera_bind_display()
test_decode_bind_display()
test_cam_bind_encode_decode_bind_display()
test_cam_vps_display()
# rtsp_url = "rtsp://127.0.0.1/3840x2160.264"
# test_rtsp_decode_bind_vps_bind_disp(rtsp_url)