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

RUBY 模拟rtsp消息的更多相关文章

  1. 转:简单的RTSP消息交互过程

    简单的RTSP消息交互过程 C表示RTSP客户端,S表示RTSP服务端 1.   第一步:查询服务器端可用方法 1.C->S:OPTION request       //询问S有哪些方法可用 ...

  2. Ruby Web实时消息后台服务器推送技术---GoEasy

    越来越多的项目需要用到实时消息的推送与接收,怎样用Ruby实现最方便呢?我这里推荐大家使用GoEasy, 它是一款第三方推送服务平台,使用它的API可以轻松搞定实时推送! 浏览器兼容性:GoEasy推 ...

  3. keybd_event跟SendMessage,PostMessage模拟键盘消息的区别 z

    首先你会发现keybd_event函数中是没有窗口句柄作为参数的,好奇的你一定会觉得很奇怪,那是因为,keybd_event是全局模拟按键的,只对前台窗口(即当前的活动窗口)才可以,但是如果模拟的按键 ...

  4. RTSP 消息拼装实例代码

    整理了下之前文章提到的RTSP实例的代码,主要是拼装各类消息字段. 首先,抽取一个公共函数,用来根据消息类型,生成不同的format,供sprintf试用. char * GetRTSPCmd( co ...

  5. C++模拟键盘消息

    实现功能:在现有DLL程序中向特定的EXE窗口中发送模拟键盘的消息 使用API根据窗口标题递归查找特定的窗口句柄,之后模拟调用. 注意:keybd_event函数不能在VS下使用,所以用SendInp ...

  6. java模拟异步消息的发送与回调

      http://kt8668.iteye.com/blog/205739 本文的目的并不是介绍使用的什么技术,而是重点阐述其实现原理. 一. 异步和同步 讲通俗点,异步就是不需要等当前执行的动作完成 ...

  7. android 模拟微信消息 OnItemClickListener()方法 [3]

    在 http://www.cnblogs.com/Seven-cjy/p/6101555.html 是基础上修改 MainActivity.java /winxinmff/src/com/exampl ...

  8. android 模拟微信消息框 BaseAdapter()方法 [2]

    在昨天的微信布局的基础上加内容 http://www.cnblogs.com/Seven-cjy/p/6098024.html 项目下/res/layout下创建一个 listview_layout. ...

  9. 简单的RTSP消息交互过程

    C表示RTSP客户端,S表示RTSP服务端 第一步:查询服务器端可用方法 1. C->S:OPTION request       //询问S有哪些方法可用 2. S->C:OPTION ...

随机推荐

  1. noip模拟赛#23

    T1:n个元素的集合.要求取出k个子集,使得k个子集交集为空集.问有多少中取法. =>推了很久...想的是从k等于2的情况推到k等于3的情况....然后k=2推出来了k=3也推出来了...推了挺 ...

  2. BZOJ3932(主席树上二分+差分

    按时间作为主席树的版本,每个版本的主席树都是一个权值线段树. 差分消去时间影响 对于当前时间版本的主席树查询前K大即可. 树上二分时结束后切记判定l==r的状态(易错 l==r叶子节点可能存在多个值( ...

  3. fast rcnn训练自己数据小结

    1.http://blog.csdn.net/hao529good/article/details/46544163   我用的训练好的模型参数是data/fast_rcnn__models/vgg_ ...

  4. cin对象的一些常用方法使用总结

    >> 最初定义的是右移,当但是出现在 cin >>中的时候这个符号被重载了,变成了一个流操作,在用户通过键盘输入信息的时候,所有内容都会先直接存储在一个叫输入缓冲区的的地方,c ...

  5. Nginx学习记录(二)

    1. 什么是反向代理 正向代理 反向代理: 反向代理服务器决定哪台服务器提供服务. 返回代理服务器不提供服务器.也是请求的转发. 反向代理(Reverse Proxy)方式是指以代理服务器来接受Int ...

  6. java调用摄像头

    http://blog.csdn.net/xing_sky/article/details/43482213 原文地址:http://blog.csdn.net/zajin/article/detai ...

  7. 驾考试题的json代码

    { "statusCode": "000000", "desc": "请求成功", "result" ...

  8. scrapy 圣墟

    # -*- coding: utf-8 -*- import scrapy from sx.items import SxItem class SkSpider(scrapy.Spider): nam ...

  9. 常用的几个JQuery代码片段

    1. 导航菜单背景切换效果 在项目的前端页面里,相对于其它的导航菜单,激活的导航菜单需要设置不同的背景.这种效果实现的方式有很多种,下面是使用JQuery实现的一种方式: //注意:代码需要修饰完善 ...

  10. poj 3259 时光穿梭问题 bellman_ford算法

    题意:有n个空地,有m条双向大路,w条时光隧道单向路.问能否回到过去? 思路:判断是否有负环存在,如果有负环存在那么就可以一直小就可以回到过去了 创建源顶点 V到其他顶点的距离d 初始为INF d[1 ...