Timeout when grabbing frame from RTSP stream, from inside WSL2

Hi guys
I am having problem with reading frames from rtsp link. I can open stream by doing
ffplay -rtsp_transport tcp -i "rtsp://admin:Admin123456*@@192.168.8.191:554/cam/realmonitor?channel=1&subtype=0"
or open it with VLC. But when using cv2 to open it I get timeout problem.

[ WARN:0@30.045] global cap_ffmpeg_impl.hpp:453 _opencv_ffmpeg_interrupt_callback Stream timeout triggered after 30034.740031 ms
[ WARN:0@60.095] global cap_ffmpeg_impl.hpp:453 _opencv_ffmpeg_interrupt_callback Stream timeout triggered after 30045.549792 ms
Error: Cannot grab frame from RTSP stream.

Any explanation. I installed the environment and ran the source code on wsl2’s Ubuntu 24.04 distro

import cv2

rtsp_url = "rtsp://admin:Admin123456*@@192.168.8.191:554/cam/realmonitor?channel=1&subtype=0"

cap = cv2.VideoCapture(rtsp_url, cv2.CAP_FFMPEG)

if not cap.isOpened():
    print("Error: Cannot open the RTSP stream.")
    exit()

while True:
    ret, frame = cap.read()
    if not ret:
        print("Error: Cannot grab frame from RTSP stream.")
        break

    cv2.imshow("RTSP Stream", frame)

    if cv2.waitKey(30) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Do you get the same error if you remove the minimum 30ms wait after reading every frame? What is the fps of the source?

WSL2 is a virtual machine. the networking is going to be more complicated than if you had run this on the host itself.

I still have the same problem tho.

so that means there is no solution, we should use os itself?

Here the answer. Problem solved.