require 'rtsp/client'
require 'log_switch'
require 'socket' RTSP::Client.log? # => false
RTSP::Client.log = true
client = RTSP::Client.new "rtsp://10.0.10.200:8557/H264" client.server_uri # => #<URI::Generic:0x00000100ba4db0 URL:rtsp://64.202.98.91:554/sa.sdp>
client.session_state # => :init
client.cseq # => 1
client.connection.do_capture # => true
client.connection.interleave # => false
client.connection.timeout # => 30
client.capturer.ip_addressing_type # => :unicast
client.capturer.rtp_port # => 6970
client.capturer.capture_file # => #<File:/var/folders/tg/j9jxvvfs4qn9cg4vztzyy2gc0000gp/T/rtp_capture.raw-59901-1l8dgv2>
client.capturer.transport_protocol # => :UDP response = client.options
response.class # => RTSP::Response
response.code # => 200
response.message # => "OK"
client.cseq # => 2 response = client.describe
response.body.class # => SDP::Description
response.content_type # => "application/sdp"
#response.server # => "DSS/5.5 (Build/489.7; Platform/Linux; Release/Darwin; )"
client.aggregate_control_track # => "rtsp://64.202.98.91:554/sa.sdp/"
client.media_control_tracks # => ["rtsp://64.202.98.91:554/sa.sdp/trackID=1"]
client.cseq # => 3 response = client.setup(client.media_control_tracks.first)
response.session[:session_id] # => 7098486223178290313
client.session[:session_id] # => 7098486223178290313
client.cseq # => 4
client.session_state # => :ready response = client.play(client.aggregate_control_track)
response.range # => "npt=now="
response.rtp_info # => "url=rtsp://64.202.98.91:554/sa.sdp/trackID=1"
client.session_state # => :playing # Wait while the video streams
sleep 5
#
client.pause(client.aggregate_control_track)
client.session_state # => :ready
#
# # Wait while the video is paused
sleep 2
#
client.teardown(client.aggregate_control_track)
client.session[:session_id] # => 0
client.session_state # => :init

执行后,如下:

[root@localhost script]# ruby rtsp.rb
[2017-03-31 15:17:49 +0800] Sending OPTIONS to rtsp://10.0.10.200:8557/H264
[2017-03-31 15:17:49 +0800] OPTIONS rtsp://10.0.10.200:8557/H264 RTSP/1.0
[2017-03-31 15:17:49 +0800] CSeq: 1
[2017-03-31 15:17:49 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Received response:
[2017-03-31 15:17:49 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:49 +0800] CSeq: 1
[2017-03-31 15:17:49 +0800] Date: Fri, Mar 31 2017 07:18:17 GMT
[2017-03-31 15:17:49 +0800] Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Sending DESCRIBE to rtsp://10.0.10.200:8557/H264
[2017-03-31 15:17:49 +0800] DESCRIBE rtsp://10.0.10.200:8557/H264 RTSP/1.0
[2017-03-31 15:17:49 +0800] CSeq: 2
[2017-03-31 15:17:49 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:49 +0800] Accept: application/sdp
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Received response:
[2017-03-31 15:17:49 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:49 +0800] CSeq: 2
[2017-03-31 15:17:49 +0800] Date: Fri, Mar 31 2017 07:18:17 GMT
[2017-03-31 15:17:49 +0800] Content-Base: rtsp://10.0.10.200:8557/H264/
[2017-03-31 15:17:49 +0800] Content-Type: application/sdp
[2017-03-31 15:17:49 +0800] Content-Length: 615
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] v=0
[2017-03-31 15:17:49 +0800] o=- 1489133093616171 1 IN IP4 10.0.10.200
[2017-03-31 15:17:49 +0800] s=RTSP/RTP stream from IPNC
[2017-03-31 15:17:49 +0800] i=H264
[2017-03-31 15:17:49 +0800] t=0 0
[2017-03-31 15:17:49 +0800] a=tool:LIVE555 Streaming Media v2014.09.11
[2017-03-31 15:17:49 +0800] a=type:broadcast
[2017-03-31 15:17:49 +0800] a=control:*
[2017-03-31 15:17:49 +0800] a=range:npt=0-
[2017-03-31 15:17:49 +0800] a=x-qt-text-nam:RTSP/RTP stream from IPNC
[2017-03-31 15:17:49 +0800] a=x-qt-text-inf:H264
[2017-03-31 15:17:49 +0800] m=video 0 RTP/AVP 96
[2017-03-31 15:17:49 +0800] c=IN IP4 0.0.0.0
[2017-03-31 15:17:49 +0800] b=AS:12000
[2017-03-31 15:17:49 +0800] a=rtpmap:96 H264/90000
[2017-03-31 15:17:49 +0800] a=fmtp:96 packetization-mode=1;profile-level-id=640032;sprop-parameter-sets=J2QAMq2EBUViuKxUcQgKisVxWKjiECSFITk8nyfk/k/J8nm5s00IEkKQnJ5Pk/J/J+T5PNzZphcqAeAIn5ZsgAAB9AAA6mBwAAAPQkAAAPQkBe91hAAAAAE=,KP4Brg==
[2017-03-31 15:17:49 +0800] a=control:track1
[2017-03-31 15:17:49 +0800] m=audio 0 RTP/AVP 0
[2017-03-31 15:17:49 +0800] c=IN IP4 0.0.0.0
[2017-03-31 15:17:49 +0800] b=AS:64
[2017-03-31 15:17:49 +0800] a=control:track2
[2017-03-31 15:17:49 +0800] Sending SETUP to rtsp://10.0.10.200:8557/H264/track1
[2017-03-31 15:17:49 +0800] SETUP rtsp://10.0.10.200:8557/H264/track1 RTSP/1.0
[2017-03-31 15:17:49 +0800] CSeq: 3
[2017-03-31 15:17:49 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:49 +0800] Transport: RTP/AVP;unicast;client_port=6970-6971
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Received response:
[2017-03-31 15:17:49 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:49 +0800] CSeq: 3
[2017-03-31 15:17:49 +0800] Date: Fri, Mar 31 2017 07:18:17 GMT
[2017-03-31 15:17:49 +0800] Transport: RTP/AVP;unicast;destination=172.17.3.54;source=10.0.10.200;client_port=6970-6971;server_port=6970-6971
[2017-03-31 15:17:49 +0800] Session: 2A4A2DAF;timeout=65
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Sending PLAY to rtsp://10.0.10.200:8557/H264/
[2017-03-31 15:17:49 +0800] PLAY rtsp://10.0.10.200:8557/H264/ RTSP/1.0
[2017-03-31 15:17:49 +0800] CSeq: 4
[2017-03-31 15:17:49 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:49 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:49 +0800] Range: npt=0.000-
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Received response:
[2017-03-31 15:17:49 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:49 +0800] CSeq: 4
[2017-03-31 15:17:49 +0800] Date: Fri, Mar 31 2017 07:18:17 GMT
[2017-03-31 15:17:49 +0800] Range: npt=0.000-
[2017-03-31 15:17:49 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:49 +0800] RTP-Info: url=rtsp://10.0.10.200:8557/H264/track1;seq=5877;rtptime=3937889106,url=rtsp://10.0.10.200:8557/H264/track2;seq=0;rtptime=0
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Capturing RTP data on port 6970
[2017-03-31 15:17:54 +0800] Sending PAUSE to rtsp://10.0.10.200:8557/H264/
[2017-03-31 15:17:54 +0800] PAUSE rtsp://10.0.10.200:8557/H264/ RTSP/1.0
[2017-03-31 15:17:54 +0800] CSeq: 5
[2017-03-31 15:17:54 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:54 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:54 +0800]
[2017-03-31 15:17:54 +0800] Received response:
[2017-03-31 15:17:54 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:54 +0800] CSeq: 5
[2017-03-31 15:17:54 +0800] Date: Fri, Mar 31 2017 07:18:22 GMT
[2017-03-31 15:17:54 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:54 +0800]
[2017-03-31 15:17:56 +0800] Sending TEARDOWN to rtsp://10.0.10.200:8557/H264/
[2017-03-31 15:17:56 +0800] TEARDOWN rtsp://10.0.10.200:8557/H264/ RTSP/1.0
[2017-03-31 15:17:56 +0800] CSeq: 6
[2017-03-31 15:17:56 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:56 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:56 +0800]
[2017-03-31 15:17:57 +0800] Received response:
[2017-03-31 15:17:57 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:57 +0800] CSeq: 6
[2017-03-31 15:17:57 +0800] Date: Fri, Mar 31 2017 07:18:25 GMT

参考文档:https://github.com/turboladen/rtsp

最新文章

  1. 关于在left join的on子句中限制左边表的取值时出现非期望的结果
  2. Connection broken for id 62, my id = 70, error =
  3. jq对象转为dom对象:$(&quot;.div1&quot;)[0] dom对象转为jq对象:$(dom对象)
  4. ASP.Net和新对象之context.Server
  5. Linux系统调用---同步IO: sync、fsync与fdatasync【转】
  6. Linux下CPU占用率高分析方法
  7. 【C++基础】指针好难啊,一点点啃——基本概念
  8. 实现Linux select IO复用C/S服务器代码
  9. Raphael:JS矢量图形库
  10. mysql 建立加密连接
  11. Hacker(15)----嗅探原理
  12. C# SQL文件执行器的功能实现
  13. 鉴客 C# 抓取页面(带认证)
  14. HDU 5176 The Experience of Love 带权并查集
  15. Form提交表单页面不跳转
  16. asp.net mvc5 多语言应用
  17. epoll源码分析
  18. Java案例:超市库存管理系统
  19. 如何自定义 maven中的archetype
  20. 解决 Attempting to destroy the window while drawing!

热门文章

  1. IOS NSNotificationCenter(通知 的使用)监听文本框的文字改变
  2. 【转载】LCT题单
  3. maven操作手册
  4. 2018.5.27 OraclePLSQL编程 if-else练习和循环结构练习
  5. LuceneTest
  6. 使用IP地址方法登录MySQL数据库Can&#39;t connect to MySQL server的原因。mysql -h 192.168.1.104 -P3306 -uroot -p 失败
  7. Zimber 8.8.12卸载后重新安装报错解决办法
  8. java中的访问修饰符 (2013-10-11-163 写的日志迁移
  9. Codeforces Round #461 (Div. 2) B. Magic Forest
  10. 12、python中的函数(高阶函数)