我有一个以25fps运行的RTP / RTSP流,已由ffprobe -i <URI>
验证。另外,VLC以实时速率回放RTSP流,但在Media Information窗口中没有显示FPS。
但是,当我使用OpenCV 4.1.1.26检索输入流的帧速率时,它的响应为90000.0
。
问题:如何使用OpenCV探测RTSP流的正确帧速率?是什么导致它报告90000.0
而不是25
?
这是我的Python函数以获取帧速率:
import cv2
vid : cv2.VideoCapture = cv2.VideoCapture('rtsp://192.168.1.10/cam1/mpeg4')
def get_framerate(video: cv2.VideoCapture):
fps = video.get(cv2.CAP_PROP_FPS)
print('FPS is {0}'.format(fps))
get_framerate(vid)
ret
变量来检查相机是否正常工作。如果它是true
,那么您应该能够看到fps;如果它是false
,那么您将得到不可预测的结果。[cv2.imshow()
和key = cv2.waitKey(1)
应该加注释,因为它会增加ping /延迟,从而导致不良的测量。
我将此作为评论发表,因为我没有足够的声誉分。
img = cv2.VideoCapture('rtsp://192.168.1.10/cam1/mpeg4')
while True:
if cont == 50:
a = datetime.now() - start
b = (a.seconds * 10e6 + a.microseconds)
print((a.seconds * 10e6 + a.microseconds), "fps = ", (50 * 10e6)/ b)
break
ret, frame = img.read()
# Comment for best test
cv2.imshow('fer', frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
cont+=1
img.release()
cv2.destroyAllWindows()`