Search code examples
pythonrtspopenrtsp

How to check if rtsp url is up/down using python script


I have a camera running on rtsp link. I want to write python code to check if the camera is live or dead. Similar to using curl to check http if url is working or not. What is a similar command can one use to check rtsp url status?

I have tried using openRTSP on terminal and I want to use it as python script

openRTSP rtsp://test_url_here


Solution

  • You can call FFMPEG to extract a snapshot. If successful stream is accessible.

    Test this functionality (exctracting snapshot from rtsp) with https://videonow.live/broadcast-ip-camera-or-stream/ per tutorial at https://broadcastlivevideo.com/publish-ip-camera-stream-to-website/.

    Command to extract should be something like:

    /usr/bin/ffmpeg -y -frames 1 snapshot.png -rtsp_transport tcp -i rtsp://test_url_here
    

    Then check if snapshot file was created and is not empty.

    You can find exact code for functionality in this free open source WP plugin https://wordpress.org/plugins/videowhisper-live-streaming-integration/ .