# webrtc-streamer **Repository Path**: liujie66/webrtc-streamer ## Basic Information - **Project Name**: webrtc-streamer - **Description**: No description available - **Primary Language**: Unknown - **License**: Unlicense - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-11-13 - **Last Updated**: 2023-11-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # WebRTC-Streamer A picture of a Nano PI NEO Air [![CircleCI](https://img.shields.io/circleci/build/github/mpromonet/webrtc-streamer?label=circleci&logo=circleci)](https://circleci.com/gh/mpromonet/webrtc-streamer) [![CirusCI](https://img.shields.io/cirrus/github/mpromonet/webrtc-streamer?label=cirrusci&logo=cirrusci)](https://cirrus-ci.com/github/mpromonet/webrtc-streamer) [![Snap Status](https://snapcraft.io//webrtc-streamer/badge.svg)](https://snapcraft.io/webrtc-streamer) [![GithubCI](https://img.shields.io/github/actions/workflow/status/mpromonet/webrtc-streamer/cpp-linux.yml?label=C%2FC%2B%2B%20ci%20linux&logo=github)](https://github.com/mpromonet/webrtc-streamer/actions/workflows/cpp-linux.yml) [![GithubCI](https://img.shields.io/github/actions/workflow/status/mpromonet/webrtc-streamer/cpp-windows.yml?label=C%2FC%2B%2B%20ci%20windows&logo=github)](https://github.com/mpromonet/webrtc-streamer/actions/workflows/cpp-windows.yml) [![GithubCI](https://img.shields.io/github/actions/workflow/status/mpromonet/webrtc-streamer/cpp-macos.yml?label=C%2FC%2B%2B%20ci%20macos&logo=github)](https://github.com/mpromonet/webrtc-streamer/actions/workflows/cpp-macos.yml) [![Release](https://img.shields.io/github/release/mpromonet/webrtc-streamer.svg)](https://github.com/mpromonet/webrtc-streamer/releases/latest) [![Download](https://img.shields.io/github/downloads/mpromonet/webrtc-streamer/total.svg)](https://github.com/mpromonet/webrtc-streamer/releases/latest) [![Docker Pulls](https://img.shields.io/docker/pulls/mpromonet/webrtc-streamer.svg)](https://hub.docker.com/r/mpromonet/webrtc-streamer/) [![Demo](https://img.shields.io/badge/okteto-livedemo-green)](https://webrtc-streamer-mpromonet.cloud.okteto.net/) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/mpromonet/webrtc-streamer) Experimentation to stream WebRTC media sources like capture devices, screen capture, mkv files and RMTP/RTSP sources using simple signaling mechanism (see [api](docs/api.md)). ## Artefacts * packages are available from https://github.com/mpromonet/webrtc-streamer/releases/latest * container image are available from https://hub.docker.com/r/mpromonet/webrtc-streamer ## Usage ```roff ./webrtc-streamer [-H http port] [-S[embeded stun address]] -[v[v]] [urls...] ./webrtc-streamer [-H http port] [-s[external stun address]] -[v[v]] [urls...] ./webrtc-streamer -V -v[v[v]] : verbosity -V : print version -C config.json : load urls from JSON config file -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 -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 : start embeded TURN server (default:disabled) -t[username:password@]turn_address : use an external TURN relay server (default:disabled) -R [Udp port range min:max] : Set the webrtc udp port range (default 0:65535) -W webrtc_trials_fields : Set the webrtc trials fields (default:WebRTC-FrameDropper/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) ``` Arguments of '-H' are forwarded to option [`listening_ports`](https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#listening_ports-8080) of civetweb, allowing use of the civetweb syntax like `-H8000,9000` or `-H8080r,8443s`. Using `-o` allows storing compressed frame data from the backend stream using `webrtc::VideoFrameBuffer::Type::kNative`. This hacks the stucture `webrtc::VideoFrameBuffer` storing data in a override of the i420 buffer. This allows forwarding H264 frames from V4L2 device or RTSP stream to WebRTC stream. It uses less CPU, but has less features (resize, codec, and bandwidth are disabled). Options for the WebRTC stream name: - an alias defined using `-n` argument then the corresponding `-u` argument will be used to create the capturer - an "rtsp://" url that will be opened using an RTSP capturer based on live555 - an "file://" url that will be opened using an MKV capturer based on live555 - an "rmtp://" url that will be opened using an RMTP capturer based on librmtp - an "screen://" url that will be opened by `webrtc::DesktopCapturer::CreateScreenCapturer` - an "window://" url that will be opened by `webrtc::DesktopCapturer::CreateWindowCapturer` - an "v4l2://" url that will capture [H264](https://en.wikipedia.org/wiki/Advanced_Video_Coding) frames and store it using webrtc::VideoFrameBuffer::Type::kNative type (not supported on Windows) - an "videocap://" url video capture device name - an "audiocap://" url audio capture device name #### Examples ```sh ./webrtc-streamer -C config.json ``` [![Screenshot](images/snapshot.png)](https://webrtc-streamer-mpromonet.cloud.okteto.net/) [Live Demo](https://webrtc-streamer-mpromonet.cloud.okteto.net/) We can access to the WebRTC stream using [webrtcstreamer.html](https://github.com/mpromonet/webrtc-streamer-html/blob/master/webrtcstreamer.html). For instance: - [webrtcstreamer.html?rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov](https://webrtc-streamer-mpromonet.cloud.okteto.net/webrtcstreamer.html?rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov) - [webrtcstreamer.html?Bunny](https://webrtc-streamer-mpromonet.cloud.okteto.net/webrtcstreamer.html?Bunny) An example displaying grid of WebRTC Streams is available using option `layout=x` [![Screenshot](images/layout2x4.png)](https://webrtc-streamer-mpromonet.cloud.okteto.net/?layout=2x4) [Live Demo](https://webrtc-streamer-mpromonet.cloud.okteto.net/?layout=2x4) ## Using docker image You can start the application using the docker image: ```sh docker run -p 8000:8000 -it mpromonet/webrtc-streamer ``` You can expose V4L2 devices from your host using: ```sh docker run --device=/dev/video0 -p 8000:8000 -it mpromonet/webrtc-streamer ``` The container entry point is the webrtc-streamer application, then you can: - view all commands ```sh docker run -p 8000:8000 -it mpromonet/webrtc-streamer --help ``` - run the container registering a RTSP url: ```sh docker run -p 8000:8000 -it mpromonet/webrtc-streamer -n raspicam -u rtsp://pi2.local:8554/unicast ``` - run the container giving config.json file: ```sh docker run -p 8000:8000 -v $PWD/config.json:/app/config.json mpromonet/webrtc-streamer ``` ## Using embedded STUN/TURN server behind a NAT It is possible to start an embeded [STUN](https://en.wikipedia.org/wiki/STUN) and [TURN](https://en.wikipedia.org/wiki/Traversal_Using_Relays_around_NAT) server and publish its URL: ```sh ./webrtc-streamer -S0.0.0.0:3478 -s$(curl -s ifconfig.me):3478 ./webrtc-streamer -s- -T0.0.0.0:3478 -tturn:turn@$(curl -s ifconfig.me):3478 ./webrtc-streamer -S0.0.0.0:3478 -s$(curl -s ifconfig.me):3478 -T0.0.0.0:3479 -tturn:turn@$(curl -s ifconfig.me):3479 ``` The command `curl -s ifconfig.me` is getting the public IP, it could also given as a static parameter. In order to configure the NAT rules using the upnp feature of the router, it is possible to use [upnpc](https://manpages.debian.org/unstable/miniupnpc/upnpc.1.en.html) like this: ```sh upnpc -r 8000 tcp 3478 tcp 3478 udp ``` Adapting with the HTTP port, STUN port, TURN port. ## HTML Embedding 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](http://htmlpreview.github.io/?https://github.com/mpromonet/webrtc-streamer-html/blob/master/jsdoc/WebRtcStreamer.html) instance: ```js var webRtcServer = new WebRtcStreamer(