RTSP 使用 Erlang 从 IP 摄像机获取视频

问题描述 投票:0回答:1

尝试找到如何通过 RTSP 从 IP 摄像机获取视频并使用 Erlang 将其记录在磁盘上的示例。有没有例子或手册?从哪里开始开发这个功能呢?对我来说,不清楚与相机交互的全局机制。

发现的东西是:

尝试通过 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:

但是视频流没有出现。我缺少什么?

用于连接 IP 摄像机的 Erlang 代码如下所示:

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.

网络摄像机的描述如下:

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

当尝试使用 SETUP 命令时 - 只是无故关闭连接:

SETUP rtsp://192.168.*.*:554 RTSP/1.0
Authorization: Basic *************=

Connection closed by foreign host.

OPTIONS 命令回复如下所示:

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
erlang rtsp
1个回答
0
投票

目前 RTSP 消息的问题已解决。基于参考 https://www.ietf.org/rfc/rfc2326.txt 和 CURL-RTSP 示例应用程序 https://github.com/Akagi201/curl-rtsp 使所有消息都能与 Erlang 一起使用:

OPTIONS rtsp://user:[email protected].*.*:554/live/main RTSP/1.0
CSeq: 1
Authorization: Basic **************=

RTSP/1.0 200 OK
CSeq: 1
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, SET_PARAMETER

DESCRIBE rtsp://user:[email protected].*.*:554/live/main RTSP/1.0
CSeq: 2
Accept: application/sdp
Authorization: Basic **************=

RTSP/1.0 200 OK
CSeq: 2
Content-Type: application/sdp
Content-Length: 390

v=0
o=- 1694003440986752 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

SETUP rtsp://user:[email protected].*.*:554/live/main/track2 RTSP/1.0
CSeq: 3
Transport: RTP/AVP;unicast;client_port=1234-1235
Authorization: Basic **************=

RTSP/1.0 200 OK
CSeq: 3
Transport: RTP/AVP;unicast;client_port=1234-1235;server_port=34659-34660
Session: 1b50a95a

PLAY rtsp://user:[email protected].*.*:554/live/main/ RTSP/1.0
CSeq: 4
Session: 1b50a95a
Range: 0.000-
Authorization: Basic **************=

RTSP/1.0 200 OK
CSeq: 4
Range: npt=0.000-
Session: 1b50a95a
RTP-Info: url=rtsp://user:[email protected].*.*:554/live/main/track2;seq=49593;rtptime=1278180033

但仍然不知道在哪里以及如何从网络摄像机获取视频流。基于RFC参考,RTSP服务器是一种摄像机的远程控制。如何根据RTSP消息中的数据获取视频流?相机应该向服务器发送数据还是服务器应该从相机获取数据?

有人可以解释一下 RTSP 摄像头的一般工作原理吗?在我的相机中,可用端口 TCP、RTSP、HTTP。视频流应该出现在哪里? PLAY 命令收到 200 OK 状态后应该做什么?

更新:

发现 OpenRTSP 应用程序显示与 IP 摄像机交互的完整日志。

$ openRTSP rtsp://user:[email protected].*.*:554/live/main
Created new TCP socket 3 for connection
Connecting to 192.168.*.*, port 554 on socket 3...
...remote connection opened
Sending request: OPTIONS rtsp://user:[email protected].*.*:554/live/main RTSP/1.0
CSeq: 2
User-Agent: openRTSP (LIVE555 Streaming Media v2023.07.24)


Received 93 new bytes of response data.
Received a complete OPTIONS response:
RTSP/1.0 200 OK
CSeq: 2
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, SET_PARAMETER


Sending request: DESCRIBE rtsp://user:[email protected].*.*:554/live/main RTSP/1.0
CSeq: 3
User-Agent: openRTSP (LIVE555 Streaming Media v2023.07.24)
Accept: application/sdp


Received 86 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 401 Authorization Required
CSeq: 3
WWW-Authenticate: Basic realm="RTSP"


Resending...
Sending request: DESCRIBE rtsp://user:[email protected].*.*:554/live/main RTSP/1.0
CSeq: 4
Authorization: Basic ****************************=
User-Agent: openRTSP (LIVE555 Streaming Media v2023.07.24)
Accept: application/sdp


Received 470 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 200 OK
CSeq: 4
Content-Type: application/sdp
Content-Length: 390

v=0
o=- 1694017411868114 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

Opened URL "rtsp://user:[email protected].*.*:554/live/main", returning a SDP description:
v=0
o=- 1694017411868114 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

Created receiver for "video/H264" subsession (client ports 54468-54469)
Created receiver for "audio/PCMA" subsession (client ports 49248-49249)
Sending request: SETUP rtsp://user:[email protected].*.*:554/live/main/track1 RTSP/1.0
CSeq: 5
Authorization: Basic ****************************=
User-Agent: openRTSP (LIVE555 Streaming Media v2023.07.24)
Transport: RTP/AVP;unicast;client_port=54468-54469


Received 123 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 5
Transport: RTP/AVP;unicast;client_port=54468-54469;server_port=38510-38511
Session: 4fca269b


Setup "video/H264" subsession (client ports 54468-54469)
Sending request: SETUP rtsp://user:[email protected].*.*:554/live/main/track2 RTSP/1.0
CSeq: 6
Authorization: Basic ****************************=
User-Agent: openRTSP (LIVE555 Streaming Media v2023.07.24)
Transport: RTP/AVP;unicast;client_port=49248-49249
Session: 4fca269b


Received 123 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 6
Transport: RTP/AVP;unicast;client_port=49248-49249;server_port=31985-31986
Session: 4fca269b


Setup "audio/PCMA" subsession (client ports 49248-49249)
Created output file: "video-H264-1"
Created output file: "audio-PCMA-2"
Sending request: PLAY rtsp://user:[email protected].*.*:554/live/main RTSP/1.0
CSeq: 7
Authorization: Basic ****************************=
User-Agent: openRTSP (LIVE555 Streaming Media v2023.07.24)
Session: 4fca269b
Range: npt=0.000-


Received 255 new bytes of response data.
Received a complete PLAY response:
RTSP/1.0 200 OK
CSeq: 7
Range: npt=0.000-
Session: 4fca269b
RTP-Info: url=rtsp://user:[email protected].*.*:554/live/main/track1;seq=38244;rtptime=393853382,url=rtsp://user:[email protected].*.*:554/live/main/track2;seq=31624;rtptime=723537895


Started playing session
Receiving streamed data (signal with "kill -HUP 4761" or "kill -USR1 4761" to terminate)...
^OGot shutdown signal
Sending request: TEARDOWN rtsp://user:[email protected].*.*:554/live/main RTSP/1.0
CSeq: 8
Authorization: Basic ****************************=
User-Agent: openRTSP (LIVE555 Streaming Media v2023.07.24)
Session: 4fca269b

基于此日志,需要创建某种音频和视频接收器。该怎么做呢?只是 TCP 监听器吗?

© www.soinside.com 2019 - 2024. All rights reserved.