RTSP get video from IP Camera with Erlang

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:

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

Almost every camera vendor has their own bugs in RTSP implementation (so does erlyvideo code las modified 12 years ago).
The best I can suggest is connecting to that camera with other client (e.g. ffmpeg) and modifying rtsp.erl to make the same requests on handshake.
Also you may try switching the transport (udp/tcp), it may help with some cameras.

Oh-yea-a-a!!! Especially from cheap-China-vendors …
We decided to proceed with FFMPEG implementation of RTSP. Developing erlang application that is using FFMPEG. So far so good …

1 Like