Trying to find any examples of how to get video from IP Camera via RTSP and record it on disk with Erlang. Is there any examples or manuals? Where to start to develop this functionality? For me isn’t clear the global mechanism of interacting with camera.
The things that found by is:
- example of RTSP from erlyvideo that is very outdated https://github.com/erlyvideo/publisher/blob/master/apps/rtsp/src/rtsp.erl
- erlang: how to receive HTTP/RTSP messages from socket? - Stack Overflow
When trying to connect via Telnet:
PLAY rtsp://192.168.*.*:554/live/main RTSP/1.0
Authorization: Basic *************=
RTSP/1.0 200 OK
CSeq: 0
Range: npt=0.000-
Session: 00000000
RTP-Info:
But video stream not appearing. What is missing by me?
The Erlang ode for connecting to IP Camera looks like:
get_rtsp() ->
{ok,Socket} = gen_tcp:connect("192.168.*.*",554,[binary, {packet, line}]),
ok = gen_tcp:send(Socket, "OPTIONS rtsp://192.168.*.*:554 RTSP/1.0\r\n\r\n"),
rtsp_data(Socket, []).
rtsp_data(Socket, SoFar) ->
receive
{tcp,Socket,Bin} ->
erlang:display(is_binary(Bin)),
erlang:display("Bin"),
erlang:display(Bin),
<<"RTSP/1.0 200 OK\r\n">> = Bin,
rtsp_data(Socket, [Bin|SoFar]);
{tcp_closed,Socket} ->
erlang:display("SoFar"),
erlang:display(SoFar)
end.
The DESCRIBE of IP Camera looks like:
DESCRIBE rtsp://192.168.*.*:554 RTSP/1.0
Authorization: Basic *************=
RTSP/1.0 200 OK
CSeq: 0
Content-Type: application/sdp
Content-Length: 390
v=0
o=- 1693921639435130 1 IN IP4 0
s=brovtech
t=0 0
a=control:*
a=range:npt=0-
a=recvonly
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:5000
a=control:track1
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=4d002a;sprop-parameter-sets=Z00AKpWoHgCJ+WbgICAgQA==,aO48gA==
m=audio 0 RTP/AVP 8
c=IN IP4 0.0.0.0
b=AS:50
a=rtpmap:8 PCMA/8000
a=control:track2
When trying to use SETUP command - just closing connection without any reason:
SETUP rtsp://192.168.*.*:554 RTSP/1.0
Authorization: Basic *************=
Connection closed by foreign host.
OPTIONS command reply looks like:
OPTIONS rtsp://192.168.*.*:554/live/main RTSP/1.0
RTSP/1.0 200 OK
CSeq: 0
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, SET_PARAMETER