像我儿子一样永远保持好奇和梦想

[o]linux rtmp 的嵌入式实现

上一篇 / 下一篇  2013-06-17 10:50:58 / 个人分类: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.

;uj2~ }0z6]4i0

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.

(Ue)G]%{J M6j$yU0

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

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

2 软件实现:Software Implementations
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台M tC3U4?0g_%v*P1W
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.
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台7of:G(F*cL
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).
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台4j&^)c0cV
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.
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台q4GVbq2H
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.
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台6M&qv(T#A+U@'M@]-M
[hsy75案]这段说明了,目前客户端用的比较多的是RTMPdump,其分支,FLVstreamer,主要的功能内置在librtmp中,一半移植到其他的客户端,都要包含librtmp.
必要知名度客户应用,应该包含:gstreamer,Mplayer,FFmpeg,XBMC,cURL,VLC,
-- 详细见ref 1

.EUz(V2A(Uh0
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:

{4A6VI sq9K0
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.
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台Re^)V)VH'f

jIKXH~ zN M0
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)

6J4d%a f.xt)u#ZMK0
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

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

y)k6usi0
RTMP服务器的搭建:ref - 6

S6A2_ o"H]"d*T2X0
2.3 编译参考:
编译ffmpeg+librtmp过程记录
编译librtmp

hS8S/ayAZY0
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台s8A| d \-L]g
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台 Xn'lU`2Laj

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项目官方网站在:#rtmpdump.mplayerhq.hu/ 。对RTMP协议的实现在其中librtmp中。
// where we got it ?

4 两种流媒体服务器HTTP和RTMP的性能大致比较:
用HTTP方式:先通过IIS 将FLV下载到本地缓存,然后再通过NetConnection的本地连接来播放这个FLV,这种方法是播放本地的视频,并不是播放服务器的视频。因此在本地缓存里可以找到这个FLV。其优点就是服务器下载完这个FLV,服务器就没有消耗了,节省服务器消耗。其缺点就是FLV会缓存在客户端,对FLV的保密性不好。
此外,对于文件播放的拖动快进操作比较不利,因为如果没有下载好,是无法拖动滴。
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台;c;Jh9cX,B8K
用RTMP方式:通过NetConnection连接到FMS/Red5服务器,并实时播放服务器的FLV文件,这种方式可以任意选择视频播放点(SEEK()),并不象HTTP方式需要缓存完整个FLV文件到本地才可以任意选择播放点,其优点就是在本地缓存里是找不到这个FLV文件的。其优点就是FLV不会缓存在客户端,FLV的保密性好,其缺点就是消耗服务器资源,连接始终是实时的。
一句话,HTTP方式是本地播放,RTMP方式是服务器实时播放,因需而定。

5 相关的一些播放器
5.1 mplayer

;G'|t P*DK$A0
5.2 wowza media system

:fr/p yc0
5.3 jwplayer
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台 a(@^-h zlD
5.4 ckplayer

5H7T\,t$iQ"J$W.W(A0

6 RTMP 的一些比较固定的地址 可用于测试
1 from wowza
rtmp://184.72.239.149/vod/mp4:bigbuckbunny_450.mp4
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台"d+Mqah_Z `3T

9g-xDK h9Z{0
others
rtmp://live4.cqnews.net:1935/live/TVFLV4
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台F)R Bpb ^D"WB
#www.fufuok.com/rtmp-video-url.html
/ae0U$[3RR@1Hl0龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台8buA|*A*`T

7 社区
1 maillist for trmpdump

'@ h*rStoj0

ref:
0 RTMP 协议详悉
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台Q-N3L1lN
1 wiki

Real Time Messaging Protocol

龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台/S1U/T ]~_{

JQT\C[L?|?s0
2 实时视频在网页直播--windows下编译librtmp、rtmpdump
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台d krB*ku1a
3  gstreamer

'X }%HU oxl G7wp2?u0
4 案例
4.1 RTMP协议发送H.264编码及AAC编码的音视频,实现摄像头直播
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台]1@&N5|:J/a!h"D
4.2 nginx搭建flv流媒体服务器[图]

XU%|m){TzHw0
4.3 搭建red5 rtmp服务器
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台-TE#GB*iD;UT
5 gstreamer and gstreamer SDK

}%b!vb'h(I.~^S0
SDK

c B!vc/gd'Y*cM0
6 RTMP 服务器搭建实例
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台u't"gy DO{+K

本帖原创:by huang.makin@gmail.com 请说明出处 谢谢
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台r~^q_ P i!A.y
龙8国际_龙8国际下载_龙8国际娱乐官方网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台c0AG'|(d0X+m4ed g'`Y

TAG: embedmediaplay linux Linux LINUX RTMP

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar