请问各位大佬,在python中opencv读取rtsp视频流延时800毫秒左右,如何控制在300毫秒左右,下面是我的测试代码,请大佬帮忙看看,怎么可以控制在300毫秒左右。
import multiprocessing
from multiprocessing import Process
import cv2
def run1(que, video):
cap = cv2.VideoCapture(video)
cap.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc('M','J','P','G'))
cap.set(cv2.CAP_PROP_FRAME_WIDTH,1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT,1080)
while 1:
ret, img = cap.read()
lenth = que.qsize()
print("que lenth: ", lenth)
if lenth > 2:
for i in range(lenth - 2):
frame = que.get() # 清除缓存
que.put(img)
cv2.imshow("read", img)
cv2.waitKey(1)
# cv2.destroyAllWindows()
# cap.release()
def test_2(que):
while 1:
img = que.get()
cv2.imshow("show", img)
key = cv2.waitKey(1)
if key == 27:
break
# cv2.destroyAllWindows()
if __name__ == "__main__":
manager = multiprocessing.Manager()
que = manager.Queue()
# que = Queue()
test1_start = 1
test2_start = 1
video = "rtsp://192.168.1.152/chn0"
t1 = Process(target=run1, args=(que, video,))
t1.start()
test_2(que)
t1.terminate()