Streaming videos using HLS and MPEG-DASH protocols is a simple and cost-effective way to show your video to large audiences. However, this requires the original streams to be in a certain format that browsers do not support natively.
At the same time, WebRTC protocol works in any browser, but it’s not as flexible when streaming to large audiences.
Gcore Video Streaming supports both WebRTC HTTP Ingest Protocol (WHIP) and WebRTC to HLS/DASH converter, giving you the advantages of these protocols.
WebRTC ingest for streaming offers two key advantages over traditional RTMP and SRT protocols:
1. It runs directly in the presenter's browser, so no additional software is needed.
2. WebRTC can reduce stream latency.
By using WebRTC WHIP for ingest, you can convert WebRTC to HLS/DASH playback, which provides the following benefits:
We use a dedicated WebRTC WHIP server to manage WebRTC ingest. This server handles both signaling and video data reception. Such a setup allows you to configure WebRTC on demand and continue to use all system capabilities to set up transcoding and delivery via CDN.
The RTC WHIP server organizes signaling and receives video data. Signaling refers to the communication between WebRTC endpoints that are necessary to initiate and maintain a session. WHIP is an open specification for a simple signaling protocol that starts WebRTC sessions in an outgoing direction, such as streaming from your device.
We use local servers in each region to ensure a minimal route from a user-presenter to the server.
The stream must include at least one video track and one audio track:
If you use OBS or your own WHIP library, use the following video encoding parameters:
Codec H.264 with no B-frames and fast encoding:
Bitrate:
For example, you might have the following settings in OBS:
You can use any libraries to send data via the WebRTC WHIP protocol.
Streams sent via WebRTC are transcoded in the same way as other streams received via RTMP and SRT.
At the output, you can view the streams using any available protocols:
For WebRTC mode, we use a method of constant transcoding with an initial given resolution. This means that if WebRTC in a viewer’s browser reduces the quality or resolution of the master stream (for example, to 360p) due to restrictions on the viewer's device (such as network conditions or CPU consumption), the transcoder will continue to transcode the reduced stream to the initial resolution (for example 1080p ABR).
When the restrictions on the viewer's device are removed, quality will improve again.
For more details about low-latency streaming, check out How low-latency streaming works.
For instructions on how to convert a stream via API, refer to the API documentation.
1. In the Gcore Customer Portal, navigate to Streaming.
2. Open the Live Streaming** page and find a needed live stream. If you don’t have one, create a stream first.
3. Click the stream name to open its settings.
4. In the Quick start in browser section, click Go Live. The broadcast will start automatically.
5. Allow Gcore to access your camera and microphone. In several seconds the HLS/DASH stream will appear in an HTML video player.
You’ll see the result under the Video preview instead of a black area with the “No active streams found” message. This large window of an HTML video player is the transcoded version of the stream in HLS/DASH protocols using adaptive bitrate.
A small window in the top-right corner is from your camera. It shows the stream taken from the webcam.
There are also settings for selecting a camera and microphone if you have more than one option on your device.
We provide a WebRTC WHIP library for working in browsers. It implements the basic system calls and simplifies working with WebRTC:
The latest library version, 0.72.0, is available at https://rtckit.gvideo.io/0.72.0/index.esm.js.
Since WHIP is an open standard, many libraries have been released for it in different languages. You can use our WebRTC WHIP or any other library specified in the WHIP clients section.
Using our library, you can start the conversion with a few lines of code. To go live immediately, create a live stream in the Gcore Streaming dashboard and paste a URL into the example linked below:
1. In the Gcore Customer Portal, open the Live Streaming page.
2. Open the stream settings and copy a WHIP URL from the WebRTC => HLS parameters section.
3. Open WHIP demo app and paste the WHIP URL into the WHIP_ENDPOINT const
.
4. Click the Start button. The steam will be started in the Customer Portal.
You can find the technical reference manual on data types, interfaces, methods, and other components in the gcorevideo/rtckit repository.
To create a new stream, send a POST request to the following endpoint: https://api.gcore.com/streaming/streams
.
Example request:
Example response:
Use the “push_url_whip”
value from the response to start the stream.
Get access and data from the microphone and camera:
Send a local stream to the WHIP server:
Note that if a user stops streaming to the ingester, for example, by closing the browser tab, the stream settings will be terminated. When the user resumes streaming from any browser, the ingester will pick up the stream. However, there will be a brief delay before the ingested stream becomes playable.
If a user tries to stream to the same endpoint where another user is already streaming, the former will get an error message from the media server. The current stream will remain uninterrupted.
After sending the stream from frontend, the stream will start transcoding. In ±2-7 seconds, the HLS and MPEG-DASH versions will be ready for viewing.
The stream can be viewed through the built-in web player or using direct links to the manifests. You can take these links from the API response.
Examples:
Send a GET request to the following endpoint: https://api.gcore.com/streaming/streams/{id}
.
Example request:
Example response:
Update the stream by sending a PATCH request to the following endpoint: https://api.gcore.com/streaming/streams/{id}
.
Example request:
Alternatively, you can delete the stream by sending the DELETE request to https://api.gcore.com/streaming/streams/$id
.
Example request:
Example command to close the stream: webrtc.close()
You can find a detailed description of this version above. To view the full code, inspect the https://stackblitz.com/edit/stackblitz-starters-j2r9ar?file=index.html.
This demo depicts a complete frontend and backend implementation with the Nuxt framework. It’s a fully functional prebuilt version with a demo stream from our demo server.
The implementation includes: stream generation, initialization of WebRTC data in a browser, video transmission from the browser to the server, and displaying the HLS/DASH web player with transcoded broadcast.
We’ve added the demo instance and source code to help you explore the implementation in action:
To start streaming:
1. Select your camera and microphone
2. In the Host section, click Start under the video preview.
3. Click the Watch link.
If you experience issues related to our streaming service, check out the following sections. They outline common problems and recommended resolution steps.
NetworkError
For details, refer to NetworkError class.
The ingestion service is unavailable or is unreachable from the client’s network. The error message includes a description of the error cause.
In such cases, the application should render itself unavailable and report the error to Gcore support. The app should not retry the operation, as the retry logic is already implemented in the SDK.
ServerRequestError
For details, check out ServerRequestError class.
The ingestion server returned an error, which can be identified by inspecting the status
and detail
fields of the error object.
HTTP status code | Explanation | Example |
---|---|---|
400 | The client’s request is wrong. It may be due to the incorrect request parameters sent by the WHIP client. If you see this error with an unintelligible description or with no description at all, contact the Gcore support team. A special case to note is when multiple clients attempt to stream to the same endpoint simultaneously. Check the example for details. |
err.message: Server request failed with status 400 err.status: 400 err.detail: {“error”: “someone is already publishing to the path '1960197_XXX'”} |
403 | The endpoint you are trying to connect to is unreachable. Probable causes:
|
err.message: Server request failed with status 403 err.status: 403 |
500, 502, 503, 504, 5xx (infrequently) | Gcore infrastructure is experiencing pressure or outage. Contact the Gcore support team. The app should render itself unavailable. It should not retry the request. |
err.message: Server request failed with status 504 err.status: 504 |
TimeoutError
For details, check out TimeoutError class.
Some operation has timed out.
Error message | Explanation |
---|---|
Timeout waiting for ICE candidates | Cause 1. Incorrectly configured ICE servers. The default configuration (when no ICE servers are specified) is to fetch a list of them from the WHIP endpoint. Cause 2. ICE servers fetched from the WHIP endpoint are unreachable from your client’s location. This is very unlikely to happen. In both cases, start by checking the ICE servers your WebRTC uses as described in the Network troubleshooting section. If that doesn’t work, contact the Gcore support team. The client app should render itself unavailable due to network conditions as an explanation. |
Other types of errors are described in our SDK docs. End-users should not encounter these errors, and there is no way to handle them in a real application apart from reporting the error occurrence.
Some SDK methods might also throw browser’s native exceptions, such as WebrtcStreaming.openSourceStream and the methods of the MediaDevicesHelper throw getUserMedia-originated exceptions. The application should handle them accordingly.
Sometimes, users use external or plug-in cameras and microphones, and these devices can be disconnected at any time. For example:
If a camera or microphone is accidentally disconnected, you need to track such cases programmatically. Enable the mediaDevicesAutoSwitch
option and subscribe to the event:
The new algorithm ensures uninterrupted broadcasting by prompting the browser to switch to another available camera or microphone if the current device becomes unavailable.
When such a situation occurs, you will know which device was disconnected and which one was connected instead. This will allow you to visualize (if necessary) the new connected device in your interface.
Chrome is really good at working with WebRTC because it has a built-in tool to help developers see how things are working.
Chrome v87+ has a special page called chrome://webrtc-internals where you can check your WebRTC calls:
1. Open a new Chrome tab and navigate to chrome://webrtc-internals while you're in a WebRTC call. On this page, you can view detailed information about the video and audio streams, connection setup, and more.
2. Use the provided information to find potential problems. For instance, when videos won't play, calls won't connect, or videos are slow.
One of the parameters you can monitor in Stats graphs for candidate-pair:
You can also follow the following parameters from the Stats graphs for outbound-rtp:
For example, consider how unevenly frames are sent from the browser in the following screenshot:
If a stream in the player constantly stops, is interrupted, or has poor quality, the issue is likely related to slow transmission of the original stream from a presenter via WebRTC.
WebRTC is very demanding of the quality of internet connection from client to server. At the same time, standard implementations take into account many parameters on a local device, which can cause slower transmission of data or even stop it altogether until conditions are improved.
To diagnose such situations:
1. Use the VideoResolutionChangeDetector plugin. It allows you to show a message about bad network conditions on a viewer’s device.
2. Use Chrome’s WebRTC debug tool that’s available via this link: chrome:\webrtc-internals.
Network congestion, occurring when resource demand surpasses capacity, leads to packet loss, increased latency, and jitter, hindering real-time communication, with congestion control algorithms optimizing performance by regulating data packet flow. You can read how WebRTC uses Transport Wide Congestion Control (TWCC) to control it in thearticle about TWCC.
The available bitrate is calculated in the availableOutgoingBitrate parameter, which indicates the available outbound capacity of the network connection. The higher the value, the more bandwidth you can assume is available for outgoing data. The value is reported in bits per second and is computed over a 1-second interval.
The most likely scenario for quality degradation occurs here when the channel width becomes insufficient to send good resolution.
However, sometimes the connection is even worse when packets are lost. In this case, the server starts sending NACK (Negative Acknowledgement) packets. You can read more about this issue in the NACK overview article.
More and more data start to be resent, which leads to increased latency or gaps in frames. In this case, the transcoder doesn’t receive frames on time, causing the video to interrupt or stop altogether. You can monitor and debug this issue in Chrome’s webrtc-internals tool:
What to do in such situations:
If you experience problems with timeout waiting for an ICE candidate, check your ICE server configuration.
ICE servers used by the WHIP client can be configured explicitly using the iceServers configuration option. Otherwise, they are fetched from Gcore’s media server in the response to a session initiation request.
In the case of the latter, check what the server returns in the Link
headers. For example:
You can also inspect the servers using chrome://webrtc-internals or an alternative tool:
After you verify your server configuration, use the Trickle ICE app to test the servers.
Add a STUN or TURN server and check how it works. If everything functions correctly, the results will show:
If you don't see these results, your STUN or TURN server may be misconfigured, or there is an outage.
The Gcore support team will help you handle that. In the request, include the results of your ICE connectivity check to help us resolve the issue quickly.
Was this article helpful?
Explore the Streaming Platform by Gcore