|
| 1 | +# Summary |
| 2 | + |
| 3 | +Add Simulcast support to WebRTC output. |
| 4 | + |
| 5 | +Simulcast is a WebRTC protocol feature that allows a uploader to send layers of one track. This is built into the protocol so every WebRTC |
| 6 | +ingest already understands this. These layers can be different resolutions, bitrates and even codecs. |
| 7 | + |
| 8 | +# Motivation |
| 9 | + |
| 10 | +Live streaming services offer videos at multiple bitrates and resolutions. This is needed to support the wide variety of connections that users will have. |
| 11 | +Today streaming services decode the incoming video, modify and then re-encode to generate these different quality levels. This has some draw backs that Simulcast |
| 12 | +will fix or improve. |
| 13 | + |
| 14 | +* **Generation Loss** - Decoding and re-encoding videos causes generation loss. Simulcast means encodes come from the source video which will be higher quality. |
| 15 | + |
| 16 | +* **Higher Quality Encodes** - Streamers with dedicated hardware can provide higher quality encodes. Streaming services at scale are optimizing for cost. |
| 17 | + |
| 18 | +* **Lower Latency** - Removing the additional encoding/decoding allows video to be delivered to users faster. |
| 19 | + |
| 20 | +* **Reduce server complexity** - Users find it difficult to setup RTMP->HLS with transcodes. With Simulcast setting up a streaming server becomes dramatically easier. |
| 21 | + |
| 22 | +# Design |
| 23 | + |
| 24 | +## When WHIP is selected service provide a 'Use Simulcast' checkbox |
| 25 | + |
| 26 | +When users select `WHIP` for their service a checkbox will appear below `Ignore streaming service setting recommendiations`. |
| 27 | + |
| 28 | +This checkbox will say `Use Simulcast`. This will be unchecked by default. |
| 29 | + |
| 30 | +## Create multiple encoders with the requested settings. |
| 31 | + |
| 32 | +A new member will be added to the `BasicOutputHandler` class. This new member `std::vector<OBSEncoder> simulcastEncoders` will contain |
| 33 | +the encoders. |
| 34 | + |
| 35 | +`BasicOutputHandler` will query if `UseSimulcast` is enabled. If enabled it will create two additional encoders `simulcast_0` and `simulcast_1`. |
| 36 | +The three encoders will be like the following. |
| 37 | + |
| 38 | +* `simple_video_stream` - Full Resolution, Full Bitrate |
| 39 | +* `simulcast_0` 50% Resolution of `simple_video_stream`, 50% bitrate of `simple_video_stream` |
| 40 | +* `simulcast_0` 25% Resolution of `simple_video_stream`, 25% bitrate of `simple_video_stream` |
| 41 | + |
| 42 | +## Configure PeerConnection in `obs_output_info.start` |
| 43 | + |
| 44 | +`WHIPOutput::Start` will use `obs_output_get_video_encoder2` to query how many encoders exist. |
| 45 | + |
| 46 | +If 3 encoders exist we will enable Simulcast and the layers will have RIDs of `h` (high), `m` (medium) and `l` (low). |
| 47 | +RIDs are used in the WebRTC protocol to give labels to a stream of video. |
| 48 | + |
| 49 | +# Proposed UX |
| 50 | + |
| 51 | +## Stream Page |
| 52 | + |
| 53 | +When users select `WHIP` for their service a checkbox will appear below `Ignore streaming service setting recommendiations`. |
| 54 | + |
| 55 | +This checkbox will say `Use Simulcast`. This will be unchecked by default. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +## Simple Output Mode |
| 60 | + |
| 61 | +No changes will be made. |
| 62 | + |
| 63 | +## Advanced Output Mode |
| 64 | + |
| 65 | +No changes will be made. |
| 66 | + |
| 67 | +# Alternatives |
| 68 | + |
| 69 | +## Do not implement Simulcast |
| 70 | + |
| 71 | +We could require users to install additional software to use Simulcast. |
| 72 | + |
| 73 | +## Advanced UIs |
| 74 | + |
| 75 | +This would require a large amount of UI work. I also wasn't able to find agreement on how this should work among the WebRTC service providers. |
| 76 | +The simple mode I was able to find consensus quickly. |
| 77 | + |
| 78 | +# Drawbacks |
| 79 | + |
| 80 | +## Additional Complexity |
| 81 | + |
| 82 | +Simulcast will add additional code to the OBS code base. If this feature is unused it would be extra burden on the project for no value. |
| 83 | + |
| 84 | +## More Compute/Network Usage |
| 85 | + |
| 86 | +Simulcast will require extra compute and network. If users encounter hardware/network overusage they will need to reduce bitrate/resolution. |
| 87 | + |
| 88 | +In the future I would like to write a dynamic simulcast feature. The WebRTC protocol allows layers to be disabled/enabled at anytime. We could detect network |
| 89 | +overusage and disable layers to ensure the streamer has the best experience possible. We would then re-enable them when the network and/or hardware recovers. |
| 90 | + |
| 91 | +I develop and use OBS on a T420 (a laptop from 2011). When streaming using WebRTC and using x264 I see ~6% CPU usage in OBS. With Simulcast enabled I see ~8%. I can gather |
| 92 | +more fine performance information if that helps. |
| 93 | + |
| 94 | +# Additional Information |
| 95 | + |
| 96 | +Implementation: |
| 97 | +* [PR](https://github.com/obsproject/obs-studio/pull/9165) |
0 commit comments