[Python] How to terminate cv2.VideoCapture(rtsp_url) call if execution stalls due to RTSP...

Discussão em 'Python' iniciado por Stack, Julho 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have RTSP URLs for 80 total cameras. I am trying to get a screenshot from every camera using cv2.VideoCapture(rtsp_url). I am doing some image processing operations on the captured screenshots from each camera. I have total 80 such URLs for each camera. A sample RTSP URL is:

    rtsp://192.168.0.101:554/user=admin_password=oyXv12aW_channel=1_stream=0.sdp?real_stream


    Now, sometimes due to the network or other technical issues, some of the cameras temporarily don't function. In that case cv2.VideoCapture(rtsp_url) takes more than 30 seconds to return. In a normal scenario it usually takes 2-3 seconds to return with screenshots. But if a camera is down, it takes too much time. Since my application is running in a for loop on many cameras, I cannot afford to wait. Sometimes the inactive camera count is high and it takes forever to execute the loop. What can be done to reduce the waiting time for cv2.VideoCapture?

    I have also used multiprocessing and have tried terminating processes if they exceed a given time threshold. I don't want to use multiprocessing though it is working very fine. I want to find a solution using only opencv

    Continue reading...

Compartilhe esta Página