Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to do a simple health check of RTSP stream with curl tool?

Tags:

curl

rtsp

I'm trying to do a simple health check of RTSP stream with curl tool.
But command like this always gives me 404 Stream Not Found error:

curl -v --url rtsp://192.168.1.80/h264/ --user admin:1234
*   Trying 192.168.1.80...
* Connected to 192.168.1.80 (192.168.1.80) port 554 (#0)
* Server auth using Basic with user 'admin'
> OPTIONS * RTSP/1.0
> CSeq: 1
> User-Agent: curl/7.47.0
> Authorization: Basic YWRtaW46YWRtaW4=
> 
< RTSP/1.0 404 Stream Not Found
< CSeq: 1
< Date: Tue, Feb 27 2018 01:14:21 GMT
< 
* Connection #0 to host 192.168.1.80 left intact  

It looks like that instead of * it should be an URL after OPTIONS here: > OPTIONS * RTSP/1.0

For instance, I tested the same URI with VLC media player and captured packets with tcpdump. With VLC it works without any issues and data send in request to RTSP server looks like this:

OPTIONS rtsp://192.168.1.80:554/h264 RTSP/1.0
CSeq: 2
User-Agent: LibVLC/2.2.2 (LIVE555 Streaming Media v2016.02.09)

It looks that there is an option CURLOPT_RTSP_STREAM_URI in libcurl that works under the hood of curl tool, but I can't find command line option to set this parameter so * is used as default value according to this: https://curl.haxx.se/libcurl/c/CURLOPT_RTSP_STREAM_URI.html And it doesn't automatically use value of --url neither.

Is there a way to test(a simple OK response to DESCRIBE or OPTIONS would be enough I think) RTSP stream with curl tool?

like image 754
VitalyZ Avatar asked Feb 27 '18 06:02

VitalyZ


1 Answers

Probably too late to be helpful to the author of the original question, but might be useful to others. I've ran into an issue with an rtsp stream on my Laview Doorbell camera dying every couple of days, whereas camera actually stays up. A simple curl command returns options and waits for more prompt:

> curl -i -X OPTIONS username:[email protected]:554/Streaming/Channels/101 RTSP/1.0
200 OK Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE

Not wanting to dive more into RTSP protocol, I tried to simply get a return status

> curl --head --connect-timeout 15 -i -X OPTIONS username:[email protected]:554/Streaming/Channels/101
curl: (8) Weird server reply

This is actually different from the status of a 'dead' stream:

> curl --head --connect-timeout 15 -i -X OPTIONS username:[email protected]:554/Streaming/Channels/101
curl: (56) Recv failure: Connection reset by peer

This leads to this naive but functional script that restarts the camera if the status is not '8':

curl --head --silent --connect-timeout 15 -i -X OPTIONS username:[email protected]:554/Streaming/Channels/101
if [ $? -ne 8 ]
then

 curl "http://username:[email protected]/ISAPI/System/reboot" -X PUT -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0" -H "Accept: */*" -H "Accept-Language: en-US,en;q=0.5" -H "Referer: http://192.168.1.15/doc/page/config.asp" --data ""

fi
like image 64
Maksym Avatar answered Oct 01 '22 02:10

Maksym