Loading web-font TeX/Math/Italic
1 Star 2 Fork 1

TopsLuo/webrtc-streamer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
8年前
Loading...
README
Unlicense

TravisCI CircleCI

Codacy Badge

Release Download Docker Pulls

Heroku Heroku

WebRTC-streamer

This is a try to stream video sources through WebRTC using simple mechanism.

It embeds a HTTP server that implements API and serve a simple HTML page that use them through AJAX.

The WebRTC signaling is implemented throught HTTP requests:

  • /api/call : send offer and get answer

  • /api/hangup : close a call

  • /api/addIceCandidate : add a candidate

  • /api/getIceCandidate : get the list of candidates

The list of HTTP API is available using /api/help.

Nowdays there is 3 builds on CircleCI :

  • for x86_64 on Ubuntu Xenial
  • for armv7 crosscompiling with gcc-linaro-arm-linux-gnueabihf-raspbian-x64 (this build is running on Raspberry Pi2 and NanoPi NEO)
  • for armv6+vfp crosscompiling with gcc-linaro-arm-linux-gnueabihf-raspbian-x64 (this build is running on Raspberry PiB and should run on a Raspberry Zero)

The webrtc stream name could be :

  • an alias defined using -n argument then the corresponding -u argument will be used to create the capturer
  • an "rtsp://" url that will be openned using an RTSP capturer based on live555
  • an "screen://" url that will be openned by webrtc::DesktopCapturer::CreateScreenCapturer
  • an "window://" url that will be openned by webrtc::DesktopCapturer::CreateWindowCapturer
  • a V4L2 capture device name

Dependencies :

It is based on :

Build

Build WebRTC with H264 support

mkdir ../webrtc
pushd ../webrtc
fetch webrtc
gn gen out/Release --args='is_debug=false use_custom_libcxx=false rtc_use_h264=true ffmpeg_branding="Chrome" rtc_include_tests=false rtc_include_pulse_audio=false use_sysroot=false is_clang=false treat_warnings_as_errors=false'
ninja -C out/Release 
popd

Build live555 to enable RTSP support (optional)

make live555

Build WebRTC Streamer

make WEBRTCROOT=<path to WebRTC> WEBRTCBUILD=<Release or Debug>

where WEBRTCROOT and WEBRTCBUILD indicate how to point to WebRTC :

  • WEBRTCROOT/srcshouldcontainssource(defaultis(pwd)/../webrtc)
  • WEBRTCROOT/src/out/WEBRTCBUILD should contains libraries (default is Release)

Usage

./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)

     	-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)
     	-t[username:password@]turn_address : use an external TURN relay server (default disabled)		

    	-a[audio layer]    : spefify audio capture layer to use (default:3)		

	-n name -u url     : register a name for an url
     	[url]              : url to register in the source list

Arguments of '-H' is forwarded to option listening_ports of civetweb, then it is possible to use the civetweb syntax like '-H8000,9000' or '-H8080r,8443s'.

Example

webrtc-streamer rtsp://217.17.220.110/axis-media/media.amp \
			rtsp://85.255.175.241/h264 \
			rtsp://85.255.175.244/h264 \
			rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov

Screenshot

Live Demo

You can access to the WebRTC stream coming from an RTSP url using webrtcstreamer.html page with the RTSP url as argument, something like:

https://rtsp2webrtc.herokuapp.com/webrtcstreamer.html?rtsp://217.17.220.110/axis-media/media.amp

Embed in a HTML page:

Instead of using the internal HTTP server, it is easy to display a WebRTC stream in a HTML page served by another HTTP server. The URL of the webrtc-streamer to use should be given creating the WebRtcStreamer instance :

var webRtcServer      = new WebRtcStreamer(<video tag>, <webrtc-streamer url>);

A short sample HTML page using webrtc-streamer running locally on port 8000 :

<html>
<head>
<script src="request.min.js" ></script>
<script src="webrtcstreamer.js" ></script>
<script>        
    var webRtcServer      = new WebRtcStreamer("video",location.protocol+"//"+window.location.hostname+":8000");
    window.onload         = function() { webRtcServer.connect("rtsp://pi2.local:8554/unicast") }
    window.onbeforeunload = function() { webRtcServer.disconnect() }
</script>
</head>
<body> 
    <video id="video" />
</body>
</html>

Connect to Janus Gateway Video Room

A simple way to publish WebRTC stream to a Janus Gateway Video Room is to use the JanusVideoRoom interface

    var janus = new JanusVideoRoom(<janus url>, <webrtc-streamer url>)

A short sample to publish WebRTC streams to Janus Video Room could be :

<html>
<head>
<script src="request.min.js" ></script>
<script src="janusvideoroom.js" ></script>
<script>        
	var janus = new JanusVideoRoom("https://janus.conf.meetecho.com/janus", null);
	janus.join(1234, "rtsp://pi2.local:8554/unicast","pi2");
	janus.join(1234, "rtsp://217.17.220.110/axis-media/media.amp","media");	    
</script>
</head>
</html>

Screenshot

Live Demo

This way the communication between Janus API and WebRTC Streamer API is implemented in Javascript running in browser.

The same logic could be implemented in NodeJS using the same JS API :

global.request = require('then-request');
var JanusVideoRoom = require('./html/janusvideoroom.js'); 
var janus = new JanusVideoRoom("http://192.168.0.15:8088/janus", "http://192.168.0.15:8000")
janus.join(1234,"mmal service 16.1","video")

Connect to Jitsi

A simple way to publish WebRTC stream to a Jitsi Video Room is to use the XMPPVideoRoom interface

    var xmpp = new XMPPVideoRoom(<xmpp server url>, <webrtc-streamer url>)

A short sample to publish WebRTC streams to a Jitsi Video Room could be :

<html>
<head>
<script src="libs/strophe.min.js" ></script>
<script src="libs/strophe.muc.min.js" ></script>
<script src="libs/strophe.disco.min.js" ></script>
<script src="libs/strophe.caps.min.js" ></script>
<script src="libs/strophe.jingle.sdp.js"></script>
<script src="libs/jquery-1.12.4.min.js"></script>
<script src="libs/request.min.js" ></script>
<script src="request.min.js" ></script>
<script src="xmppvideoroom.js" ></script>
<script>        
	var xmpp = new XMPPVideoRoom("meet.jit.si", null);
	xmpp.join("testroom", "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov","Bunny");	    
</script>
</head>
</html>

Live Demo

Docker image

You can start the application using the docker image :

    docker run -p 8000:8000 -it mpromonet/webrtc-streamer

You can expose V4L2 devices from your host using :

    docker run --device=/dev/video0 -p 8000:8000 -it mpromonet/webrtc-streamer

The container entry point is the webrtc-streamer application, then you can :

  • get the help using :

      docker run -p 8000:8000 -it mpromonet/webrtc-streamer -h
    
  • run the container registering a RTSP url using :

      docker run -p 8000:8000 -it mpromonet/webrtc-streamer -n raspicam -u rtsp://pi2.local:8554/unicast
    
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to <http://unlicense.org>

简介

WebRTC streamer for V4L2 capture devices and RTSP sources 展开 收起
Unlicense
取消

发行版

暂无发行版

近期动态

4年前创建了仓库
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/TopsLuo/webrtc-streamer.git
git@gitee.com:TopsLuo/webrtc-streamer.git
TopsLuo
webrtc-streamer
webrtc-streamer
master

搜索帮助