hsy75的个人空间 https://blog.eetop.cn/vivilife [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

[o]linux rtmp 的嵌入式实现

已有 8553 次阅读| 2013-6-17 10:50 |个人分类:linux

1 什么是RTMP 协议简介:

RTMP (except RTMFP) is a TCP-based protocol which maintains persistent connections and allows low-latency[低延迟] communication. To deliver streams smoothly and transmit as much information as possible, it splits streams into fragments and their size is negotiated dynamically between the client and server while sometimes it is kept unchanged: the default fragment sizes are 64-bytes for audio data, and 128 bytes for video data and most other data types. Fragments from different streams may then be interleaved, and multiplexed over a single connection. With longer data chunks the protocol thus carries only a one-byte header per fragment, so incurring very little overhead. However, in practice individual fragments are not typically interleaved. Instead, the interleaving and multiplexing is done at the packet level, with RTMP packets across several different active channels being interleaved in such a way as to ensure that each channel meets its bandwidth, latency, and other quality-of-service requirements. Packets interleaved in this fashion are treated as indivisible, and are not interleaved on the fragment level.

The RTMP defines several virtual channels on which packets may be sent and received, and which operate independently of each other. For example, there is a channel for handling RPC requests and responses, a channel for video stream data, a channel for audio stream data, a channel for out-of-band control messages (fragment size negotiation, etc.), and so on. During a typical RTMP session, several channels may be active simultaneously at any given time. When RTMP data is encoded, a packet header is generated. The packet header specifies, amongst other matters, the id of the channel on which it is to be sent, a timestamp of when it was generated (if necessary), and the size of the packet's payload. This header is then followed by the actual payload content of the packet, which is fragmented according to the currently agreed-upon fragment size before it is sent over the connection. The packet header itself is never fragmented, and its size does not count towards the data in the packet's first fragment. In other words, only the actual packet payload (the media data) is subject to fragmentation.

At a higher level, the RTMP encapsulates[封装] MP3 or AAC audio and FLV1 video multimedia streams, and can make remote procedure calls (RPCs) using the Action Message Format. Any RPC services required are made asynchronously, using a single client/server request/response model, such that real-time communication is not required -- 详细见 ref1

RTMP协议是被Flash用于对象、视频、音频的传输。该协议建立在TCP协议或者轮询HTTP协议之上,RTMP协议就像一个用来装数据包的容器,这些数据可以是AMF格式的数据,也可以是FLV中的视/音频数据。一个单一的连接可以通过不同的通道传输多路网络流,这些通道中的包都是按照固定大小的包传输的. --详细见ref0

2 软件实现:Software Implementations

2.1 Client software[edit] 客户端软件
The most widely adopted RTMP client is Adobe Flash Player, which supports playback of audio and video streamed from RTMP servers (when installed as a web browser plug-in).
Client software with only partial support for RTMP includes the open source media player XBMC, which has preliminary support for playing RTMP (but not RTMPE) streams.

The open-source command-line tool rtmpdump is designed to play back or save to disk the full RTMP stream including the RTMPE protocol Adobe uses for encryption. RTMPdump runs on Linux, Android, Solaris, MacOSX, and most other Unix-derived operating systems, as well as Microsoft Windows. Originally supporting all versions of 32-bit Windows including Windows 98, from version 2.2 the software will run only on Windows XP and above (although earlier versions remain fully functional).

A fork of RTMPdump, without the code which Adobe claims violates the DMCA in the USA, has been released as FLVstreamer. This was developed as a direct response to Adobe's attempt in 2008 to suppress RTMPdump. FLVstreamer will save to disk ("download") a stream of audio or video content from any RTMP server, provided RTMPE is not enabled on the stream. It runs on Windows XP and above, but not on earlier versions of Windows.

Development of RTMPdump was restarted in October 2009, outside the United States, at the MPlayer site.[6] The current version features greatly improved functionality, and has been rewritten to take advantage of the benefits of the C programming language. In particular, the main functionality was built into a library (librtmp) which can easily be used by other applications. The RTMPdump developers have also written support for librtmp for MPlayer, FFmpeg, XBMC, cURL, VLC and a number of other open source software projects. Use of librtmp provides these projects with full support of RTMP in all its variants without any additional development effort.

[hsy75案]这段说明了,目前客户端用的比较多的是RTMPdump,其分支,FLVstreamer,主要的功能内置在librtmp中,一半移植到其他的客户端,都要包含librtmp.
必要知名度客户应用,应该包含:gstreamer,Mplayer,FFmpeg,XBMC,cURL,VLC,
-- 详细见ref 1

2.2 Server software[edit] 服务器端
In order to use RTMP, your host or CDN needs to have a dedicated RTMP server installed. There are three major offerings, both supported by JW Player:

1 The Wowza Media Server is today's most widely used solution. It includes support for almost any streaming protocol, including RTMP. 
   Wowza 3 introduced dedicated support for JW6 SMIL manifests (see below)
2 The Adobe Flash Media Server is another great option. Since Flash is developed by Adobe, new RTMP functionalities find their way in FMS first.
flash media server:
在什么情况下需要使用fms呢
1)视频文件超过100MB或超过10分钟,用户有seek需求的时候
2)视频文件不需要被下载的时候,rtmp如果不行,可以试试rtmpe
3)视频流需要多台服务器协同工作的时候,可以用FMS Origin/Edge
3 Red5 Media Server is a Java open source project which delivers a powerful video streaming and multi-user solution to the ©Adobe ©Flash Player and other client technologies.


Some full implementation RTMP servers are:
Adobe Flash Media Server,
Adobe LiveCycle Data Services
Amazon S3 & Amazon Cloudfront can stream using RTMP
haXeVideo is a multithread FLV streaming server entirely written using the haXe programming language.
RealNetworks' Helix Universal Server can support RTMP, RTMPT and RTMPS streaming for live and on-demand content
Mistserver is a lightweight, open-source streaming server with support for RTMP in live, on demand and live replay mode.
Onlinelib VCS Video Communication Server (including iPhone Support)

Erlyvideo[8] has wide functionality: not only file streaming, but restreaming of MPEG-TS or Shoutcast to flash clients using RTMP.
Unreal Media Server supports live RTMP streaming, in real-time and buffered modes.
Wowza Media Server
WebORB Integration Server (RTMP/RTMPT/RTMPS messaging and media streaming available for .NET and Java Enterprise, Community and Cloud editions)
OneTeam Media Server has been announced on ProcessOne.[9]
crtmpserver is a C++ implementation of rtmp server.[10]
FreeSWITCH RTMP media streaming available with mod_rtmp and allow interconnecting with other VoIP protocols (SIP, H.323) etc.
Netris iStream Video Server for services on demand from Netris
FFmpeg
Nginx with RTMP Module

[hsy75] 在实践中,往往比较好的开发方式是建立自己的rtmp调试服务器,这样有利于问题的跟踪和总结,
因为网上的url的地址总是不断的变化的,比较麻烦。

RTMP服务器的搭建:ref - 6

2.3 编译参考:
编译ffmpeg+librtmp过程记录
编译librtmp




RTMPdump 工具:
rtmpdump is a toolkit for RTMP streams. All forms of RTMP are supported, including rtmp://, rtmpt://, rtmpe://, rtmpte://, and rtmps://.这是一个匈牙利人在2009年,Adobe公司还没有公开RTMP协议的情况下对RTMP协议的实现得。 官方网站中只提供了程序源代码和动态链接库(dll),要在开发中方便地使用RTMPDump,还需要自己编译它的静态库(lib)
RTMPDump项目官方网站在:http://rtmpdump.mplayerhq.hu/ 。对RTMP协议的实现在其中librtmp中。
// where we got it ?

4 两种流媒体服务器HTTP和RTMP的性能大致比较:
用HTTP方式:先通过IIS 将FLV下载到本地缓存,然后再通过NetConnection的本地连接来播放这个FLV,这种方法是播放本地的视频,并不是播放服务器的视频。因此在本地缓存里可以找到这个FLV。其优点就是服务器下载完这个FLV,服务器就没有消耗了,节省服务器消耗。其缺点就是FLV会缓存在客户端,对FLV的保密性不好。
此外,对于文件播放的拖动快进操作比较不利,因为如果没有下载好,是无法拖动滴。

用RTMP方式:通过NetConnection连接到FMS/Red5服务器,并实时播放服务器的FLV文件,这种方式可以任意选择视频播放点(SEEK()),并不象HTTP方式需要缓存完整个FLV文件到本地才可以任意选择播放点,其优点就是在本地缓存里是找不到这个FLV文件的。其优点就是FLV不会缓存在客户端,FLV的保密性好,其缺点就是消耗服务器资源,连接始终是实时的。
一句话,HTTP方式是本地播放,RTMP方式是服务器实时播放,因需而定。

5 相关的一些播放器
5.1 mplayer

5.2 wowza media system

5.3 jwplayer

5.4 ckplayer


6 RTMP 的一些比较固定的地址 可用于测试
1 from wowza
rtmp://184.72.239.149/vod/mp4:bigbuckbunny_450.mp4


others
rtmp://live4.cqnews.net:1935/live/TVFLV4

http://www.fufuok.com/rtmp-video-url.html


7 社区
1 maillist for trmpdump


ref:
0 RTMP 协议详悉

1 wiki

Real Time Messaging Protocol



2 实时视频在网页直播--windows下编译librtmp、rtmpdump

3  gstreamer

4 案例
4.1 RTMP协议发送H.264编码及AAC编码的音视频,实现摄像头直播

4.2 nginx搭建flv流媒体服务器[图]

4.3 搭建red5 rtmp服务器

5 gstreamer and gstreamer SDK

SDK

6 RTMP 服务器搭建实例


本帖原创:by huang.makin@gmail.com 请说明出处 谢谢



点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 1

    好友
  • 2

    获赞
  • 14

    评论
  • 3241

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-3-29 12:53 , Processed in 0.013544 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部