七种转化RTSP屏显示到web页面的方…
来源:互联网 发布:ppt怎么弄数据展现 编辑:程序博客网 时间:2024/05/23 05:08
7 ways to stream RTSP on the page
In this article we demonstrate 7 technologically different ways todisplay a video stream from an IP camera with RTSP support on a webpage in a browser.
As a rule, browsers do not support RTSP, so the video stream isconverted for a browser using an intermediate server.
Method 1 – RTMP
Browsers do not support the RTMP protocol, but guess who does? Theold faithful Flash Player that works enough well even though itdoes not support all browsers, so it can display the videostream.
The code of the player is built on Action Script 3 and looks asfollows:
var
nc:NetConnection = nc.connect(
"rtmp://192.168.88.59/live"
,obj);
var
subscribeStream:NetStream =
new
NetStream(nc);
subscribeStream.play(
"rtsp://192.168.88.5/live.sdp"
);
In this example:
rtmp://192.168.88.59/live – is the address of the intermediateserver that fetches the RTSP video stream from the camera andconverts it to RTMP.
rtsp://192.168.88.5/live.sdp – is the RTSP address of thecamera.
A little bit superfluous variant of the player on Flex and AS3 isavailable
This method looks as follows:
Method 2 – RTMP wrapped to HTML5
It is hard to find those willing to keep coding on Action Script 3these days. So, there is a method with an HTML wrapping that allowscontrolling the RTMP player from JavaScript. In this variant theflash is loaded to the HTML page only to display picture and playsound.
var
session = Flashphoner.createSession({urlServer:
"wss://192.168.88.59:8443"
});
session.createStream({name:
"rtsp://192.168.88.5/live.sdp"
,display:myVideo}).play();
The full source code of the player is
Method 3 – RTMFP
The RTMFP protocol also works inside the Flash Player. Thedifference from RTMP is that RTMFP works on top of the UDP, so itis much more suitable for low latency broadcasting.
The AS3 code of the player is identical to that of RTMP except forone letter F added in the line of code where the connection to theserver is established.
var
nc:NetConnection = nc.connect(
"rtmfp://192.168.88.59/live"
,obj);
var
subscribeStream:NetStream =
new
NetStream(nc);
subscribeStream.play(
"rtsp://192.168.88.5/live.sdp"
);
Nevertheless, here is a screenshot using RTMFP
Method 4 – RTMFP wrapped to HTML5
This way is identical to method 2 except that during initializationwe set the RTMFP protocol for the underlying Flash (swfobject).
Var session =Flashphoner.createSession({urlServer:
"wss://192.168.88.59:8443"
,flashProto:
"rtmfp"
});
session.createStream({name:
"rtsp://192.168.88.5/live.sdp"
,display:myVideo}).play();
Player picture:
Method 5 – WebRTC
In this case we do not use Flash at all, and the video stream isplayed using means of the browser itself, without using third-partyplugins. This method works both in Chrome and Firefox Androidbrowsers, where Flash is not available. WebRTC results in thelowest latency, less than 0.5 seconds.
The source code of the player is the same:
var
session = Flashphoner.createSession({urlServer:
"wss://192.168.88.59:8443"
});
session.createStream({name:
"rtsp://192.168.88.5/live.sdp"
,display:myVideo}).play();
The script automatically detects WebRTC support, and if ti issupported, the stream is played using WebRTC.
Method 6 – Websockets
WebRTC and Flash do not cover all browsers and platforms. Forinstance, the iOS Safari browser does not support them.
You can deliver a video stream to iOS Safari using Websockettransport (a TCP connection between the browser and the server).Then, the RTSP video stream is channelled through Websockets. Afterthe binary data are received, they can be decoded using JavaScriptand rendered on Canvas HTML5 element.
This is what Websocket player does on the iOS Safari browser. Thecode of the player looks the same:
var
session = Flashphoner.createSession({urlServer:
"wss://192.168.88.59:8443"
});
session.createStream({name:
"rtsp://192.168.88.5/live.sdp"
,display:myVideo}).play();
This is somewhat similar to the Flash-based methods when the swfelement lies under HTML5. Here, we have a JavaScript applicationunder HTML5 that fetches data via Websockets, decodes them andrenders them on Canvas in multiple threads.
Here is how an RTSP stream rendered on Canvas in the iOS Safaribrowser looks like:
Method 7 – HLS
When RTSP is converted to HLS, a video stream is divided tosegments that are happily downloaded from the server and displayedin the HLS player.
As an HLS player we use video.js. The source code of the player canbe downloaded
The player looks as follows:
Method 8 – Android application, WebRTC
The application retrieves the stream from the server via WebRTC. Togoal of the server here is to convert RTSP to WebRTC and feed theresult to the mobile application.
The Java-code of the player for Androidis
SessionOptions sessionOptions =
new
SessionOptions(
"wss://192.168.88.59:8443"
);
Session session =Flashphoner.createSession(sessionOptions);
StreamOptions streamOptions =
new
StreamOptions(
"rtsp://192.168.88.5/live.sdp"
);
Stream playStream =session.createStream(streamOptions);
playStream.play();
A test mobile app of the player can be installedfrom
Here is how RTSP stream playback via WebRTC looks on Asus Androidtablet:
Method 9 – iOS application, WebRTC
Just like its Android brethren, the iOS application fetches a videostream from the server via WebRTC.
The
FPWCSApi2SessionOptions *options = [[FPWCSApi2SessionOptions alloc]init];
options.urlServer = @
"wss://192.168.88.59:8443"
;
FPWCSApi2Session *session = [FPWCSApi2 createSession:optionserror:&error];
FPWCSApi2StreamOptions *options = [[FPWCSApi2StreamOptions alloc]init];
options.name = @
"rtsp://192.168.88.5/live.sdp"
;
FPWCSApi2Stream *stream = [session createStream:optionserror:
nil
];
stream play:&error;
You can download the source code of the player foriOS
And you can install the
Results
Let’s put the results together into a summary table:
For testing the methods we used Web Call Server 5 that is capableof converting an RTSP stream and transmitting it to all nine abovedescribed directions.
References
Web Call Server 5
Flash Streaming
Source
Player
Source
HLS player
Source
Android WebRTC player
Source
iOS WebRTC player
Source
- 七种转化RTSP屏显示到web页面的方…
- Jsp页面常用的显示方
- 跳转到web的页面
- 开平方的七种算法
- 从地址栏输入到页面显示 -深入探究web运行机制
- Web页面实现生成附件显示到下载栏
- [Web]显示客户端页面执行时间的代码
- web页面pdf文件的显示
- web页面json数据的解析显示
- Web静态服务器-显示需要的页面
- 数据库的html内容显示到页面
- 从url到页面的显示
- 在web页面设置横屏显示
- web页面显示时间
- Android_WebView显示Web页面
- 时间的显示转化
- 页面跳转的七种方法
- 〖数学算法〗开平方的七种算法
- 玩游戏的时候怎么没觉得补刀这么难…
- ffmpeg的转码延时测试与设置优化
- 8球胜负(eight)
- 使用ffmpeg对视频进行TS切片
- BiliBili, ACFun… And More!
- 七种转化RTSP屏显示到web页面的方…
- 点球大战(penalty)
- 对Class.forName()用法详解
- mac 安装node环境
- Android App自动化测试: OPEN-STF环境搭建
- [境内法规]中国人民银行关于进一步加强金融机构反洗钱工作的通知—银发[2008]391号
- 【转】xampp集成的mysql,插入中文…
- CentOS7 安装配置Redis数据库
- mac直接terminal中登陆linux