Reducing Latency in RTMP Viewing with OpenCV

I’m reading an RTMP stream from a local RTMP server on Ubuntu 22.04 using OpenCV (installed via apt). When I play the stream with ffplay, the latency is almost nonexistent using the command below:

ffplay -f live_flv \
    -fast \
    -fflags nobuffer \
    -flags low_delay \
    -strict experimental \
    -vf "setpts=N/30/TB" \
    -noframedrop \
    -i "rtmp://localhost:1935/live"

However, when I use OpenCV to read the same stream, I experience noticeable latency. Here’s the code I’m using:

cap = cv2.VideoCapture("rtmp://localhost:1935/live buffer=0")
while cap.isOpened():
    success, frame = cap.read()
    if not success:
        continue
    cv2.imshow("window", frame)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break
cap.release()
cv2.destroyAllWindows()

The code shows stream, but there’s noticable latency compared to ffplay. How can I achieve the same low latency in OpenCV as I do with ffplay?

see also: