尝试仅将 RTSP 流中的元数据保存到文件中

And*_*Gee 5 bash shell command-line-interface rtsp gstreamer

我正在尝试访问并保存来自 IP 摄像机的元数据流。

到目前为止,我已成功保存元数据:

openRTSP -b 400000 -K -t rtsp://username:password@192.168.2.4:5554/live/ch1
Run Code Online (Sandbox Code Playgroud)

这会创建一个元数据文件application-VND.ONVIF.METADATA-2(示例如下),但这也会流式传输视频文件并将其保存到:video-H264-1当前目录中。我宁愿不流式传输视频数据,因为我没有用它,而且带宽是多个流的问题。

元数据样本

user@server:~# tail -n 1 application-VND.ONVIF.METADATA-2 
Run Code Online (Sandbox Code Playgroud)
<tt:MetadataStream xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"><tt:VideoAnalytics><tt:Frame UtcTime="2022-04-02T06:55:13.577000"><tt:Transformation><tt:Translate x="-1.0" y="1.0"/><tt:Scale x="2.0" y="-2.0"/></tt:Transformation><tt:Object ObjectId="39242"><tt:Appearance><tt:Shape><tt:BoundingBox left="0.949999988079071" top="0.0" right="0.981249988079071" bottom="0.251800000667572"/><tt:CenterOfGravity x="0.965624988079071" y="0.125900000333786"/></tt:Shape><tt:Class><tt:ClassCandidate><tt:Type>Person</tt:Type><tt:Likelihood>0.47999998927116394</tt:Likelihood></tt:ClassCandidate></tt:Class></tt:Appearance></tt:Object></tt:Frame><tt:Frame UtcTime="2022-04-02T06:55:13.577000"><tt:Transformation><tt:Translate x="-1.0" y="1.0"/><tt:Scale x="2.0" y="-2.0"/></tt:Transformation><tt:Object ObjectId="39283"><tt:Appearance><tt:Shape><tt:BoundingBox left="0.21143999695777893" top="0.2988300025463104" right="0.33105000853538513" bottom="0.9925199747085571"/><tt:CenterOfGravity x="0.27124500274658203" y="0.6456749886274338"/></tt:Shape><tt:Class><tt:ClassCandidate><tt:Type>Person</tt:Type><tt:Likelihood>0.4699999988079071</tt:Likelihood></tt:ClassCandidate></tt:Class></tt:Appearance></tt:Object></tt:Frame><tt:Frame UtcTime="2022-04-02T06:55:13.577000"><tt:Transformation><tt:Translate x="-1.0" y="1.0"/><tt:Scale x="2.0" y="-2.0"/></tt:Transformation><tt:Object ObjectId="39287"><tt:Appearance><tt:Shape><tt:BoundingBox left="0.20412999391555786" top="0.28610000014305115" right="0.33774998784065247" bottom="0.6600499749183655"/><tt:CenterOfGravity x="0.27093999087810516" y="0.4730749875307083"/></tt:Shape><tt:Class><tt:ClassCandidate><tt:Type>Person</tt:Type><tt:Likelihood>0.23000000417232513</tt:Likelihood></tt:ClassCandidate></tt:Class></tt:Appearance></tt:Object></tt:Frame><tt:Frame UtcTime="2022-04-02T06:55:13.577000"><tt:Transformation><tt:Translate x="-1.0" y="1.0"/><tt:Scale x="2.0" y="-2.0"/></tt:Transformation><tt:Object ObjectId="39288"><tt:Appearance><tt:Shape><tt:BoundingBox left="0.6440899968147278" top="0.0" right="0.7041800022125244" bottom="0.19472000002861023"/><tt:CenterOfGravity x="0.6741349995136261" y="0.09736000001430511"/></tt:Shape><tt:Class><tt:ClassCandidate><tt:Type>Person</tt:Type><tt:Likelihood>0.18000000715255737</tt:Likelihood></tt:ClassCandidate></tt:Class></tt:Appearance></tt:Object></tt:Frame><tt:Frame UtcTime="2022-04-02T06:55:13.577000"><tt:Transformation><tt:Translate x="-1.0" y="1.0"/><tt:Scale x="2.0" y="-2.0"/></tt:Transformation><tt:Object ObjectId="39289"><tt:Appearance><tt:Shape><tt:BoundingBox left="0.29583001136779785" top="0.30309998989105225" right="0.4729200005531311" bottom="0.7376400232315063"/><tt:CenterOfGravity x="0.3843750059604645" y="0.5203700065612793"/></tt:Shape><tt:Class><tt:ClassCandidate><tt:Type>Person</tt:Type><tt:Likelihood>0.18000000715255737</tt:Likelihood></tt:ClassCandidate></tt:Class></tt:Appearance></tt:Object></tt:Frame></tt:VideoAnalytics></tt:MetadataStream>
Run Code Online (Sandbox Code Playgroud)
几乎可用
user@server:~# openRTSP -b 400000 -K -t rtsp://username:password@192.168.2.4:5554/live/ch1
Run Code Online (Sandbox Code Playgroud)

标准输出:

Created new TCP socket 3 for connection
Connecting to 192.168.2.4, port 5554 on socket 3...
...remote connection opened
Sending request: OPTIONS rtsp://username:password@192.168.2.4:5554/live/ch1 RTSP/1.0
CSeq: 2
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)


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


Sending request: DESCRIBE rtsp://username:password@192.168.2.4:5554/live/ch1 RTSP/1.0
CSeq: 3
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Accept: application/sdp


Received 156 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 401 Unauthorized
CSeq: 3
WWW-Authenticate: Digest realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a"


Resending...
Sending request: DESCRIBE rtsp://username:password@192.168.2.4:5554/live/ch1 RTSP/1.0
CSeq: 4
Authorization: Digest username="username", realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a", uri="rtsp://username:password@192.168.2.4:5554/live/ch1", response="6b90e55e0af2db247e4ea2c674e58b38"
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Accept: application/sdp


Received 592 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 200 OK
CSeq: 4
Content-Base: rtsp://username:password@192.168.2.4:5554/live/ch1
Content-Type: application/sdp
Content-Length: 447

v=0
o=- 1 1 IN IP4 192.168.2.4
s=Media Server
t=0 0
a=type:broadcast
c=IN IP4 0.0.0.0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z0IAKpY1QPAET8s3BQEFAg==,aM48gA==
a=control:rtsp://username:password@192.168.2.4:5554/live/ch1/video
m=application 0 RTP/AVP 97
a=rtpmap:97 VND.ONVIF.METADATA/8000
a=control:rtsp://username:password@192.168.2.4:5554/live/ch1/meta

Opened URL "rtsp://username:password@192.168.2.4:5554/live/ch1", returning a SDP description:
v=0
o=- 1 1 IN IP4 192.168.2.4
s=Media Server
t=0 0
a=type:broadcast
c=IN IP4 0.0.0.0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z0IAKpY1QPAET8s3BQEFAg==,aM48gA==
a=control:rtsp://username:password@192.168.2.4:5554/live/ch1/video
m=application 0 RTP/AVP 97
a=rtpmap:97 VND.ONVIF.METADATA/8000
a=control:rtsp://username:password@192.168.2.4:5554/live/ch1/meta

Created receiver for "video/H264" subsession (client ports 41390-41391)
Created receiver for "application/VND.ONVIF.METADATA" subsession (client ports 54122-54123)
Sending request: SETUP rtsp://username:password@192.168.2.4:5554/live/ch1/video RTSP/1.0
CSeq: 5
Authorization: Digest username="username", realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a", uri="rtsp://username:password@192.168.2.4:5554/live/ch1", response="a7a7d51269283cd92b37e41dd8889109"
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Transport: RTP/AVP/TCP;unicast;interleaved=0-1


Received 128 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 5
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
Session: 05EB326D3901E880B71E1370F83E85;timeout=60


Setup "video/H264" subsession (client ports 41390-41391)
Sending request: SETUP rtsp://username:password@192.168.2.4:5554/live/ch1/meta RTSP/1.0
CSeq: 6
Authorization: Digest username="username", realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a", uri="rtsp://username:password@192.168.2.4:5554/live/ch1", response="a7a7d51269283cd92b37e41dd8889109"
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
Session: 05EB326D3901E880B71E1370F83E85


Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 6
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
Session: 05EB326D3901E880B71E1370F83E85;timeout=60


Setup "application/VND.ONVIF.METADATA" subsession (client ports 54122-54123)
Created output file: "video-H264-1"
Created output file: "application-VND.ONVIF.METADATA-2"
Sending request: PLAY rtsp://username:password@192.168.2.4:5554/live/ch1 RTSP/1.0
CSeq: 7
Authorization: Digest username="username", realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a", uri="rtsp://username:password@192.168.2.4:5554/live/ch1", response="b7bf5ee1ed4dab7afcb85bede5e7e785"
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Session: 05EB326D3901E880B71E1370F83E85
Range: npt=0.000-


Received a complete PLAY response:
RTSP/1.0 200 OK
CSeq: 7
Session: 05EB326D3901E880B71E1370F83E85
Range: clock=20220402T065513.225Z-
RTP-Info: url=rtsp://username:password@192.168.2.4:5554/live/ch1/video?;seq=29232;rtptime=2063989750,url=rtsp://username:password@192.168.2.4:5554/live/ch1/meta?;seq=29232;rtptime=2070061960


Started playing session
Receiving streamed data (signal with "kill -HUP 492099" or "kill -USR1 492099" to terminate)...
^C

Run Code Online (Sandbox Code Playgroud)

流发现

user@server:~# gst-discoverer-1.0 -v -t 60 rtsp://username:password@192.168.2.4:5554/live/ch3

Done discovering rtsp://username:pass@192.168.2.4:5554/live/ch1
Analyzing URI timed out

Topology:
  container: application/rtsp
    unknown: application/x-rtp, media=(string)video, payload=(int)96, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)64001F, sprop-parameter-sets=(string)"Z0IAKpY1QPAET8s3BQEFAg\=\=\,aM48gA\=\=", a-type=(string)broadcast, npt-start=(guint64)23571980000000, play-speed=(double)1, play-scale=(double)1, ssrc=(uint)1304347240
      video: video/x-h264, stream-format=(string)avc, alignment=(string)au, codec_data=(buffer)0142002affe100106742002a963540f0044fcb370501050201000468ce3c80, level=(string)4.2, profile=(string)baseline, width=(int)1920, height=(int)1080, framerate=(fraction)0/1, interlace-mode=(string)progressive, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true
        Tags:
          video codec: H.264 (Baseline Profile)
        
        Codec:
          video/x-h264, stream-format=(string)avc, alignment=(string)au, codec_data=(buffer)0142002affe100106742002a963540f0044fcb370501050201000468ce3c80, level=(string)4.2, profile=(string)baseline, width=(int)1920, height=(int)1080, framerate=(fraction)0/1, interlace-mode=(string)progressive, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true
        Additional info:
          None
        Stream ID: b71011accfcd9e6ac1d42a60b4611071674cf9321b63a6b8cc4a6b480fca3e9f/0/video:0:0:RTP:AVP:96
        Width: 1920
        Height: 1080
        Depth: 24
        Frame rate: 0/1
        Pixel aspect ratio: 1/1
        Interlaced: false
        Bitrate: 0
        Max bitrate: 0

Properties:
  Duration: 99:99:99.999999999
  Seekable: no
  Live: yes
  Tags: 
      video codec: H.264 (Baseline Profile)


Run Code Online (Sandbox Code Playgroud)

鉴于此处的信息,有什么方法可以让我只访问元数据吗?

我尝试过的其他事情。

gst-launch-1.0 rtspsrc location=rtsp://username:password@192.168.2.4:5554/live/ch3 ! application/x-rtp, media=application ! fakesink dump=true >> cap.xml
Run Code Online (Sandbox Code Playgroud)

这将创建带有某种编码元数据的 cap.xml 文件。我相信这也会传输视频数据,因此编码并不理想。它也往往会定期死亡。

cap.xml 示例

Created new TCP socket 3 for connection
Connecting to 192.168.2.4, port 5554 on socket 3...
...remote connection opened
Sending request: OPTIONS rtsp://username:password@192.168.2.4:5554/live/ch1 RTSP/1.0
CSeq: 2
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)


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


Sending request: DESCRIBE rtsp://username:password@192.168.2.4:5554/live/ch1 RTSP/1.0
CSeq: 3
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Accept: application/sdp


Received 156 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 401 Unauthorized
CSeq: 3
WWW-Authenticate: Digest realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a"


Resending...
Sending request: DESCRIBE rtsp://username:password@192.168.2.4:5554/live/ch1 RTSP/1.0
CSeq: 4
Authorization: Digest username="username", realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a", uri="rtsp://username:password@192.168.2.4:5554/live/ch1", response="6b90e55e0af2db247e4ea2c674e58b38"
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Accept: application/sdp


Received 592 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 200 OK
CSeq: 4
Content-Base: rtsp://username:password@192.168.2.4:5554/live/ch1
Content-Type: application/sdp
Content-Length: 447

v=0
o=- 1 1 IN IP4 192.168.2.4
s=Media Server
t=0 0
a=type:broadcast
c=IN IP4 0.0.0.0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z0IAKpY1QPAET8s3BQEFAg==,aM48gA==
a=control:rtsp://username:password@192.168.2.4:5554/live/ch1/video
m=application 0 RTP/AVP 97
a=rtpmap:97 VND.ONVIF.METADATA/8000
a=control:rtsp://username:password@192.168.2.4:5554/live/ch1/meta

Opened URL "rtsp://username:password@192.168.2.4:5554/live/ch1", returning a SDP description:
v=0
o=- 1 1 IN IP4 192.168.2.4
s=Media Server
t=0 0
a=type:broadcast
c=IN IP4 0.0.0.0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z0IAKpY1QPAET8s3BQEFAg==,aM48gA==
a=control:rtsp://username:password@192.168.2.4:5554/live/ch1/video
m=application 0 RTP/AVP 97
a=rtpmap:97 VND.ONVIF.METADATA/8000
a=control:rtsp://username:password@192.168.2.4:5554/live/ch1/meta

Created receiver for "video/H264" subsession (client ports 41390-41391)
Created receiver for "application/VND.ONVIF.METADATA" subsession (client ports 54122-54123)
Sending request: SETUP rtsp://username:password@192.168.2.4:5554/live/ch1/video RTSP/1.0
CSeq: 5
Authorization: Digest username="username", realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a", uri="rtsp://username:password@192.168.2.4:5554/live/ch1", response="a7a7d51269283cd92b37e41dd8889109"
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Transport: RTP/AVP/TCP;unicast;interleaved=0-1


Received 128 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 5
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
Session: 05EB326D3901E880B71E1370F83E85;timeout=60


Setup "video/H264" subsession (client ports 41390-41391)
Sending request: SETUP rtsp://username:password@192.168.2.4:5554/live/ch1/meta RTSP/1.0
CSeq: 6
Authorization: Digest username="username", realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a", uri="rtsp://username:password@192.168.2.4:5554/live/ch1", response="a7a7d51269283cd92b37e41dd8889109"
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
Session: 05EB326D3901E880B71E1370F83E85


Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 6
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
Session: 05EB326D3901E880B71E1370F83E85;timeout=60


Setup "application/VND.ONVIF.METADATA" subsession (client ports 54122-54123)
Created output file: "video-H264-1"
Created output file: "application-VND.ONVIF.METADATA-2"
Sending request: PLAY rtsp://username:password@192.168.2.4:5554/live/ch1 RTSP/1.0
CSeq: 7
Authorization: Digest username="username", realm="ITX_VABOX", nonce="6247f394ff1fb1c1acaa90dcfec31e506cf149052cad069b41fb45a9b913e69a", uri="rtsp://username:password@192.168.2.4:5554/live/ch1", response="b7bf5ee1ed4dab7afcb85bede5e7e785"
User-Agent: openRTSP (LIVE555 Streaming Media v2020.01.19)
Session: 05EB326D3901E880B71E1370F83E85
Range: npt=0.000-


Received a complete PLAY response:
RTSP/1.0 200 OK
CSeq: 7
Session: 05EB326D3901E880B71E1370F83E85
Range: clock=20220402T065513.225Z-
RTP-Info: url=rtsp://username:password@192.168.2.4:5554/live/ch1/video?;seq=29232;rtptime=2063989750,url=rtsp://username:password@192.168.2.4:5554/live/ch1/meta?;seq=29232;rtptime=2070061960


Started playing session
Receiving streamed data (signal with "kill -HUP 492099" or "kill -USR1 492099" to terminate)...
^C

Run Code Online (Sandbox Code Playgroud)

cdu*_*dub 1

这个链接,如上面的评论所述:

您可以将该-L选项添加到openRTSP命令行,然后将输出重定向到文件,或通过管道将其传输到其他应用程序以处理元数据。