赞
踩
读前强调:!!!!
iframe有CPU拉满的情况,确实会存在。本编文章纯粹做实践性测试。生产上用还是建议莫参考此做法。可以考虑直接用海康官方的萤石云平台展示。关于cpu拉满,我看issue里面也有很多人反应了。官方的答复是加上-o。可以试试
还可以参考我另外一篇文章,是另外一个方法。
https://github.com/mpromonet/webrtc-streamer/releases
docker方式启动,局域网有的电脑能正常访问8000,有的不能正常访问8000,暂时不知道原因是啥;但exe方式启动,局域网内都能正常访问。
./webrtc-streamer [-H http port] [-S[embeded stun address]] -[v[v]] [url1]...[urln] ./webrtc-streamer [-H http port] [-s[external stun address]] -[v[v]] [url1]...[urln] ./webrtc-streamer -V -v[v[v]] : verbosity -V : print version -H [hostname:]port : HTTP server binding (default 0.0.0.0:8000) -w webroot : path to get files -c sslkeycert : path to private key and certificate for HTTPS -N nbthreads : number of threads for HTTP server -A passwd : password file for HTTP server access -D authDomain : authentication domain for HTTP server access (default:mydomain.com) -S[stun_address] : start embeded STUN server bind to address (default 0.0.0.0:3478) -s[stun_address] : use an external STUN server (default:stun.l.google.com:19302 , -:means no STUN) -t[username:password@]turn_address : use an external TURN relay server (default:disabled) -T[username:password@]turn_address : start embeded TURN server (default:disabled) -a[audio layer] : spefify audio capture layer to use (default:0) -q[filter] : spefify publish filter (default:.*) -o : use null codec (keep frame encoded) -C config.json : load urls from JSON config file -R [Udp port range min:max] : Set the webrtc udp port range (default 0:65535) -n name -u videourl -U audiourl : register a name for a video url and an audio url [url] : url to register in the source list
docker pull mpromonet/webrtc-streamer
这里 -n 设置名称 待会会用到
docker run -p 8000:8000 -it mpromonet/webrtc-streamer -n raspicam -u rtsp://admin:123456@192.168.0.109:554/h264/ch1/main/av_stream
{
"urls":{
"raspicam": {"video": "rtsp://admin:123456@192.168.0.109:554/h264/ch1/main/av_stream"},
}
}
cmd到目录执行命令 webrtc-streamer.exe -C config.json
webrtc-streamer.exe -C config.json
浏览器输入 http://localhost:8000
可以直接看到rstp流对应的画面。
小技巧:可以点击
可以看到实际上这个地址的效果是通过webrtcstreamer.html
来展示的。可以自己去阅读步骤一下载的代码包中的webrtcstreamer.html
源码研究研究下。其实就是利用了video和options的值来展示的。
通过上面分析源码,然后得出如下代码。
其中adapter.min.js、webrtcstreamer.js是步骤1解压目录里面的。
敲黑板了,注意这两者的值。此处的raspicam与上面设置的名称保持一致。
let url = {video: “raspicam”};
let options = “rtptransport=tcp”;
<html> <head> <script src="libs/adapter.min.js" ></script> <script src="webrtcstreamer.js" ></script> <script> let url = {video: "raspicam"}; let options = "rtptransport=tcp"; window.onload = function() { this.webRtcServer = new WebRtcStreamer("video", "http://192.168.0.104:8000"); webRtcServer.connect(url.video, null, options); } window.onbeforeunload = function() { this.webRtcServer.disconnect() } </script> <style> html,body { padding: 0; margin: 0; height: 100%; } </style> </head> <body> <div style="height: 100%"> <video id="video" muted controls style="object-fit:fill; height: 100%; width: 100%"></video> </div> </body> </html>
H264
格式。否则看不了。这个细节很重要。VLC media player
测试rstp视频流能不能正常访问。再用html测试。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。