How many viewers can it support? RTMP usually goes to platforms that broadcast to many users. What about with WebRTC, can I have 100 viewers peer to peer? Maybe with TURN relays?
And what is the proper infrastructure to scale WebRTC to thousands of listeners at once?
If you don’t actually need the low latency then you are better off with hls-ll delivered via a CDN.
https://www.digitalsamba.com/blog/p2p-sfu-and-mcu-webrtc-arc...
Personally I think simulcast (sending multiple differently encoded streams) is almost always wrong for many Webrtc uses (especially mobile publishers) but in the OBS case it actually makes a lot more sense.
If you want to know more you're probably best off going through the MDN docs about the WebRTC browser API and learning from that.
>And what is the proper infrastructure to scale WebRTC to thousands of listeners at once?
It looks like a pool of ingestion servers and a CDN for viewers. Ingestion servers handle getting the stream from the streamer and encoding it into whatever formats are needed. The CDN handles distributing this stream to people who want to watch it.
If you've got 100 viewers and can manage to saturate a gigabit uplink (which can be difficult because of routing and other upstream crap) you should be able to send about 9mbps video + overhead, which is pretty close to Twitch's bandwidth cap.
Because consumer ISPs generally don't have great routes between them and sustained gigabit uploads probably don't always work reliably because of overbooking with consumer lines, you'll probably be better off setting up an SFU on a cheap (temporary) cloud server somewhere.
Theoretically: media streams are identified by a 32 bit number, so about 4 billion clients.
Data streams are limited to 65535 endpoints (a signed 16 bit number with a reserved 0).
Not sure why you think that? Maybe on cable modems, because DOCSIS is highly asymmetrical, but on FTTH GPON et al (pretty much the only technology which supports gigabit upload; docsis gigabit upload is extremely rare), there is no reason it couldn't saturate upstream at 1gigabit+. If anything, consumer ISPs are usually way more contended on the downlink side than the upstream side.
Maybe I'm wrong but I'm pretty sure cable modems are still wha the vast majority of consumer households have.
More advanced fiber networks split bandwidth based on frequency ("color") instead of giving each ONT a time slot based on the current network capacity. But basically, if you're uploading at 1Gbps, that is fine until 1.5 more neighbors decide to do the same thing. It's rare. When I worked at Google Fiber we kept an eye on PON utilization and there was never a case where a customer couldn't get the requested bandwidth. We even had customers that maxed out 1Gbps/1Gbps 24/7 in an attempt to get banned or something, but of course we wouldn't ban you for that. We did worry about PON capacity and had some tech ready to go in case we ever needed to switch to truly dedicated per-customer gigabit connections.
At another ISP I worked at, our marketing material described the 1Gbps GPON-based link as "dedicated", but many customers noticed it was shared. It would slow down during peak business hours, and then get fast when other people in the building went home from work. We removed the term "dedicated" from our marketing. A political battle that I paid dearly for, but hey, they still exist and didn't get sued into oblivion by the FTC, so that's nice. (We also sold frequency-multiplexed 10Gbps circuits that really were dedicated... I suppose until our uplink to our ISP was saturated. I think we had 100Gbps transit and that never happened. But yeah, there is no such thing as dedicated unless you are physically plugged into the network that you want to reach. The Internet tries its best.)
An eyeball network will generally have considerably more, and considerably higher bandwidth, peering relationships with content provider networks than with other eyeball networks.
At AVStack we experimented quite a bit with P2P multiparty video calls, it’s certainly possible but as you scale up the number of participants there’s huge variance in quality depending on the combination of ISPs used by the participants, the time of day, network conditions etc.
A glace over Twitch's broadcasting guidelines was not enlightening, but I'm clueless in these matters.
How is this possible?
If you are curious on the 'how' of WebRTC I wrote a Free/Open Source book that goes into the details https://webrtcforthecurious.com/. Happy to answer any particular questions you have.
I added WebRTC support (audio, video, chat) to my already existing application a couple of years ago and felt the technology wasn't exactly ready for primetime. To me, it felt like the out of the box developer experience wasn't exactly great.
I am only saying this because I got to see exactly how much effort is required to get things going. Your work is greatly appreciated
also this is probably only taking California as the whole world, like everyone does.
The numbers are purely illustrative. I don’t know what OPS can actually do but let’s say each OBS server can handle 50 connections that means if we had a two level deep tree, we could handle 2500 participants in a single call.
For my own usage I run WebRTC servers and have them 'replicate' the video traffic. LiveKit did a write up on this with some good graphics https://blog.livekit.io/scaling-webrtc-with-distributed-mesh...
Anyway it’s super exciting stuff! Great work!
It has a docker image so you should be able to run a 'streaming site' with just a few commands :)
For incoming connections and compositing them you need something beyond OBS. Gstreamer is one option.
As I understand webrtc, it describes the connection wrapping and the streams / negotiation, but not the discovery part. Which means it's about as p2p as http - if you add a way to find the endpoint and open sockets, you can make peers talk.
Is there something more in the OBS implementation that makes it more p2p? Am I missing something?
it's not really meant to be a useful tool for making a pure peer-to-peer video service.
I have a chapter on signaling here https://webrtcforthecurious.com/docs/02-signaling/
I have an example of WebRTC without signaling https://github.com/pion/offline-browser-communication. Each side has to agree on things ahead of time. Useful for security cameras/IoT/LAN stuff though!
`localhost` is allowed. Could you reverse port forward the service to localhost? That will get around those restrictions.
Meanwhile I can hack together a poor man's webrtc by sending raw packets over websockets and playback works just fine. I just lose all the real benefits of webrtc (robustness, udp vs tcp, etc.). It feels like it should be possible to work around since I don't access anything on the clients, they just play back a stream from the devices.
But yeah, one way or another, you need a secure context for WebRTC to work. That’s in the spec, and browsers follow it.
Perhaps in your context it really is nonsense, but how is the browser to know that your network/physical layer is secure?
That discovery mechanism can be a decentralized network where any contact is an entrypoint. You connect to the network ~once and from that point onward everything is p2p and no fixed servers are involved or in control.
Usually you'd divide what you're talking about into two different steps. Peer discovery, and peer transport.
Discovery is how you find other peers, sometimes its via DHT, sometimes it's hard-coded, other times just random walk. But just like in WebRTC, (and in TCP), you need to get the address from somewhere out of band, so you can connect, usually something like a centralized directory. But the transport of data, is P2P, just like TCP. So once you've found the peer and connected to it, all data goes directly between you.
Doesn't make it less/more P2P than any other P2P system out there.
https://b.siobud.com might not be always available. So best to host yourself for anything important :)
Excited for you to use it. Send any ideas my way for improvement.
I've been trying it out for a while now (streaming to a self-hosted broadcast-box), and almost everyone who views the stream says that the video will freeze for 1 to 2 seconds every now and again (every few minutes). Audio is uninterrupted. Any hints about how I can debug this?
Here's some speculation: Most users will experience non-libwebrtc WebRTC bugs (like OBS users). 1% of users who experience bugs in OBS WebRTC will report enough telemetry to fix the bug. But 99% of all of OBS's userbase uses Chrome, Edge or Safari, and maybe 50% of those (more than enough) report telemetry. So if their WebRTC bug was hardware / network specific - the bugs that matter - libwebrtc will have observed it and by now, probably fixed it.
Despite telemetry from hundreds of millions of users every day, it still took years for libwebrtc to reach truly robust, flawless stability on all the platforms it deploys on.
It's a complex technology.
chrome://webrtc-internals should tell you the exact reason. My guess is packet loss and then it recovers on the keyframe.
In the next day or two I am gonna open a PR to set NACK buffer properly. Right now it is too small :/
Sorry you are hitting issues. Will try my best to fix it up! Email me [email protected] and would love to make sure we get it working 100%. I bet other users are hitting the same issues and not sharing.
I've always wanted this. Instead of the streamer switching video inputs we could select from the viewer-side which perspective we want. I've also thought about things like NASCAR partnering with Valve/Steam to use their Valve Index for 360-degree views from each car on the track. I don't know why they're not marking VR to people who love NASCAR, it'd be such an odd and likely successful niche. It'd be cool to accept-in multiple video inputs and even patch them together in realtime on the viewer side (unless they're specifically disparate).
* Serverless Streaming - WebRTC is P2P so you can video right into your browser. You don’t have to stand up a server anymore to stream for a small audience.
> Only possible in an ideal world, where NAT doesn't exist, in reality, you need to traverse NAT and it is NOT a serverless process.
* Sub-Second Latency - Create content and interact with viewers instantly. There is something magical about having a real conversation with your viewers.
> Only possible in an ideal world, where machines are very close to each other. In reality, you need expensive world-wide TURN clusters on top-notch infrastructure to ensure <100ms latencies you want.
* Mobility - WebRTC lets you switch networks at any time. Go from WiFi -> Mobile with zero interruptions.
> In fact, an interruption is happening when network conditions change – since you need to negotiate connectivity again. It is not seamless.
[1] https://www.cisco.com/c/en/us/support/docs/ip/network-addres...
I have a DIY WebRTC forwarder for a RTSP stream, that lives on a home server behind a NAT. It has NAT because it lives in a cgroup that's isolated to IoT VLAN, and I haven't originally planned on WebRTC there, hoping I could make it work with restreaming over HTTP or Websockets. The NAT there is of the most common type: nftables' masquerade statement for the appropriate output interface, the usual conntrack allow established,related rule, and rule that allows outbound connections. For whatever reason, WebRTC only worked for me when my viewing device wasn't behind any other NATs.
Now, this is not a proper argument. Being a very lazy ass I haven't bothered with diagnostics so I don't know why it hadn't worked. I was already quite frustrated with various cross-browser JS shenanigans and after checking that STUN was indeed configured but had not worked, I've just punched a couple of port forwards and called it a day.
For whatever reason P2P streaming seem to work somewhat worse in practice than it should've been in theory. Usual computer leprechauns, I guess.
——
Yes <100ms is hard, I don’t think most users are looking for that. 400-600ms is what people can expect and I always see that!
—-
You don’t need to negotiate again with NICER
400-600 ms is certainly not a "real conversation" experience, yet getting close to it. Speaking more realistically, the latencies spread would be much more broad depending on the peers' geography in a true P2P mesh.
If you don't need to negotiate again, how do you know which new socket to send bytes to? Is it some kind of a wizard, this NICER?
Now this is actually HUGE. It means Twitch has far less power as a gateway for greenfield streamers.
Things you're giving up as a greenfield streamer by rolling their own streaming platform:
* The beginning of a follower base on your destination platform (Twitch)
* A "single pane of glass" for viewing your stream, chatting with you and other viewers, and giving you subscription/donation money. This is a deal breaker for a non-negligible number of people, and your follower base might not grow as large or as quickly as you'd like.
* Twitch Prime subscription money.
* Serverless Streaming - WebRTC is P2P so you can video right into your browser. You don’t have to stand up a server anymore to stream for a small audience.
* Sub-Second Latency - Create content and interact with viewers instantly. There is something magical about having a real conversation with your viewers.
* Multitrack Input - Upload your transcodes instead of generating then server side. Give viewers multiple video tracks to see action from all sides.
* Mobility - WebRTC lets you switch networks at any time. Go from WiFi -> Mobile with zero interruptions.
Try it out today with Broadcast Box. A reference server implementation. https://github.com/glimesh/broadcast-box. The PR to add WebRTC to OBS https://github.com/obsproject/obs-studio/pull/7926
-----
So many people went into making this happen. This was a colossal undertaking that different people have working on for over 6 months.
Sergio Murillo - Created WHIP. The only reason this could be added to OBS.
Luke Strickland - Created Broadcast Box. The reference server we developed against
Paul-Louis Ageneau - Creator of libdatachannel. The library used to add WebRTC support to OBS.
Colin Edwards - Started the project to add WebRTC into OBS
John Bradley, tt2468, pkv - Developers who worked on the code itself
RytoEx, tytan652 - Lots of feedback and reviews
-----
Have fun using it! If you have any questions/feedback/improvement ideas I would love to hear.