user244791
user244791

Reputation: 115

Delay/Lag in OpenCV VideoCapture

I'm trying to read an rtsp stream from an ip camera using opencv's VideoCapture Class on Ubuntu 20.04 with opencv 4.5. There is a lag in the video on ubuntu but none when I run the same code on a windows 10 machine.

cap.set(cv2.CAP_PROP_BUFFERSIZE, size) returns false and the cameras default buffer size does not change.

cap = cv2.VideoCapture("rtsp://admin:@[email protected]")
while (cap.isOpened()):
    ret, frame = cap.read()
    cv2.imshow("Live", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'): #press q to quit
        break
cap.release()

The stream works well when I play it using ffplay with the following parameters:

'''ffplay -fflags nobuffer -flags low_delay -tune zerolatency -framedrop -rtsp_transport tcp "rtsp://192.168.1.64"'''

Need help on how to reduce/handle the lag in my code.

Upvotes: 3

Views: 7018

Answers (1)

Deumaudit
Deumaudit

Reputation: 1026

I had the same question bro)

Actually I've done some research, and there is my result

In openCV 4.5.1 property CAP_PROP_BUFFERSIZE is supported for some backends, but not for all. You can easily check if your backend supports this property. Just look at the result of the cap.get(CAP_PROP_BUFFERSIZE). If it returns 0, then your backend does not support this property. As good as I understand OpenCV's source code, only aravis, DC1394, V4L backends support this property

Upvotes: 3

Related Questions