Toybrick

标题: 3399proD解码速度缓慢问题 [打印本页]

作者: lmw0320    时间: 2023-4-14 16:11
标题: 3399proD解码速度缓慢问题
3399proD上,使用如下py代码,接入网络摄像头,并尝试转成rtsp流推送出去,发现解码过程耗时较高,想请问下,原因出在哪里?
  1. import cv2
  2. import time
  3. import gi
  4. gi.require_version('Gst', '1.0')
  5. gi.require_version('GstRtspServer', '1.0')
  6. from gi.repository import GObject, Gst, GstRtspServer

  7. uri = "rtsp://admin:a1234567@192.168.49.94/h264/ch1/main/av_stream"
  8. t0 =  time.time()
  9. gst_str = ('rtspsrc location={} latency=0 ! '
  10.            'rtph264depay ! h264parse ! mppvideodec ! '
  11.            'videoconvert ! video/x-raw,format=BGR,formaterate=25/1 ! appsink sync=false').format(uri)
  12. cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

  13. t = time.time()
  14. print('VideoCapture cost', t - t0)
  15. print('cap isOpened', cap.isOpened())
  16. width = 1920
  17. height = 1080
  18. 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)
  19. print('out_send', out_send.isOpened())
  20. rtsp_port_num = 8554
  21. server = GstRtspServer.RTSPServer.new()
  22. server.props.service = "%d" % rtsp_port_num

  23. server.attach(None)
  24. factory = GstRtspServer.RTSPMediaFactory.new()
  25. factory.set_launch("(udpsrc name=pay0 port=5400 \
  26.                                         caps="application/x-rtp, media=video, clock-rate=90000, \
  27.                                         encoding-name=(string)H264, payload=96 ")")
  28. factory.set_shared(True)
  29. server.get_mount_points().add_factory("/test", factory)

  30. num = 0
  31. start = time.perf_counter()
  32. while True:       
  33.         t1 = time.time()
  34.         ret, frame = cap.read()
  35.         t2 = time.time()
  36.         print('time cost', round(t2 - t1, 4))
  37.         if not ret:
  38.                 break
  39.         t3 = time.time()#
  40.         out_send.write(frame)
  41.         t4 = time.time()
  42.         if cv2.waitKey(1) & 0xFF == ord("q"):
  43.                 cap.release()
  44.                 out_send.release()
  45.                 break
  46.         num +=1
复制代码
测试发现,在cap.read()出的耗时,达到170ms+,这个是什么原因呢??

然后我也用dmesg命令查看后台日志,发现如下问题:
  1. [  600.365372] rk_vcodec: vpu_service_ioctl:2140: error: unknown vpu service ioctl cmd 40086c01
  2. [  605.194149] Core dump to |/usr/lib/systemd/systemd-coredump 3732 1000 1000 11 1681456866 18446744073709551615 debian10.toybrick mpp_dec_parser pipe failed
  3. [ 3189.955584] rk_vcodec: vpu_service_ioctl:2140: error: unknown vpu service ioctl cmd 40086c01
  4. [ 3189.960992] Core dump to |/usr/lib/systemd/systemd-coredump 21788 1000 1000 11 1681459451 18446744073709551615 debian10.toybrick mpp_dec_parser pipe failed
复制代码



作者: user    时间: 2023-4-19 18:21
mppvideodec 这个库转码安装的





欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3