|
3399proD上,使用如下py代码,接入网络摄像头,并尝试转成rtsp流推送出去,发现解码过程耗时较高,想请问下,原因出在哪里?
- import cv2
- import time
- import gi
- gi.require_version('Gst', '1.0')
- gi.require_version('GstRtspServer', '1.0')
- from gi.repository import GObject, Gst, GstRtspServer
- uri = "rtsp://admin:a1234567@192.168.49.94/h264/ch1/main/av_stream"
- t0 = time.time()
- gst_str = ('rtspsrc location={} latency=0 ! '
- 'rtph264depay ! h264parse ! mppvideodec ! '
- 'videoconvert ! video/x-raw,format=BGR,formaterate=25/1 ! appsink sync=false').format(uri)
- cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
- t = time.time()
- print('VideoCapture cost', t - t0)
- print('cap isOpened', cap.isOpened())
- width = 1920
- height = 1080
- out_send = cv2.VideoWriter('appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw,width={},height={} ! queue ! mpph264enc ! queue ! video/x-h264, stream-format=byte-stream ! h264parse ! rtph264pay pt=96 config-interval=1 ! udpsink host=127.0.0.1 port=5400'.format(width, height), cv2.CAP_GSTREAMER, 0, 25, (width, height), True)
- print('out_send', out_send.isOpened())
- rtsp_port_num = 8554
- server = GstRtspServer.RTSPServer.new()
- server.props.service = "%d" % rtsp_port_num
- server.attach(None)
- factory = GstRtspServer.RTSPMediaFactory.new()
- factory.set_launch("(udpsrc name=pay0 port=5400 \
- caps="application/x-rtp, media=video, clock-rate=90000, \
- encoding-name=(string)H264, payload=96 ")")
- factory.set_shared(True)
- server.get_mount_points().add_factory("/test", factory)
- num = 0
- start = time.perf_counter()
- while True:
- t1 = time.time()
- ret, frame = cap.read()
- t2 = time.time()
- print('time cost', round(t2 - t1, 4))
- if not ret:
- break
- t3 = time.time()#
- out_send.write(frame)
- t4 = time.time()
- if cv2.waitKey(1) & 0xFF == ord("q"):
- cap.release()
- out_send.release()
- break
- num +=1
测试发现,在cap.read()出的耗时,达到170ms+,这个是什么原因呢??
然后我也用dmesg命令查看后台日志,发现如下问题:
- [ 600.365372] rk_vcodec: vpu_service_ioctl:2140: error: unknown vpu service ioctl cmd 40086c01
- [ 605.194149] Core dump to |/usr/lib/systemd/systemd-coredump 3732 1000 1000 11 1681456866 18446744073709551615 debian10.toybrick mpp_dec_parser pipe failed
- [ 3189.955584] rk_vcodec: vpu_service_ioctl:2140: error: unknown vpu service ioctl cmd 40086c01
- [ 3189.960992] Core dump to |/usr/lib/systemd/systemd-coredump 21788 1000 1000 11 1681459451 18446744073709551615 debian10.toybrick mpp_dec_parser pipe failed
|
|