1

I have an RTP/RTSP stream that's running at 25fps, as verified by ffprobe -i <URI>. Also, VLC plays back the RTSP stream at a real-time rate, but doesn't show me the FPS in the Media Information window.

However, when I use OpenCV 4.1.1.26 to retrieve the input stream's frame rate, it is giving me a response of 90000.0.

Question: How can I use OpenCV to probe for the correct frame rate of the RTSP stream? What would cause it to report 90000.0 instead of 25?

Here's my Python function to retrieve the frame rate:

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)
  • MacOS Catalina
  • Python 3.7.4

1 Answers1

0

I hope this helps you somehow. It is a simple calculator that takes cont captures and measure the beginning and the ending time. Then with the rule of three, i converted it to fps.

Related to you second question i read here that it could be due to bad installation. Also, you can check that your camera is working properly by printing ret variable. If it is true then you should be able to see the fps, if it is false then you can have an unpredictable result.

cv2.imshow() and key = cv2.waitKey(1) should be commented as it adds ping/delay resulting in bad measurement.


I post this as a comment because i do not have enough reputation points.

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()`