Try Live Demo

The live streaming world in its current form is one of the booming businesses out here. Nowadays, there are a lot of ways that we can stream a video to masses of people. 

About WebRTC Technology

WebRTC provides ultra-low latency around 0.5s, which is the go-to of many applications where ultra-low latency is needed. One of the most used cases of WebRTC is online conferences, where latency must be as low as possible for the conference to take place smoothly.

However, things get a little bit complicated when we want to live stream a conference attended by 20 guests from different devices to thousands of people. 

Imagine a situation where you are in an online conference, and there are five guests. When a new guest wants to watch (not participate) this conference, the number of total connections increases by five since every member of the conference needs to send their stream to the new guest.

This might be fine with a single guest. However, when you want to stream your conference to masses of people, for example, on social media, this option quickly becomes impossible.

Merging webrtc live streams

This brings us to our brand new solution, “Stream Merge Tool”

Today, I will show you step by step how you can automatically merge video streams from multiple sources and stream them as a single stream using the Ant Media Server merge tool.

Let’s merge WebRTC conferences with the auto-merge tool. For that you can use the following URL:

https://<antmedia-url>:5443/<application-name>/conference.html

It will show a page similar to this,

Webrtc stream merge tool

One thing to pay attention to is the room id. In our case, it is “room1”.

Let’s say that 3 others are joined the conference and we will see a page something like this:

webrtc conference room ant media server

Now, this is where the magic happens, you can’t simply increase the number of attendees to publish the stream to 10.000 people. For this, we need to merge the streams from all participants and create a single stream and synch the audio and video files from all participants. This way when someone wants to watch the conference, they will connect to a single stream instead of connecting multiple sources and this allows the scaling option to thousands of people.

To merge the streams and publish them as a single stream, we go to the following URL:

https://<antmedia-url>:5443/<application-name>/merge_streams.html

webrtc stream merge

We must give the correct roomId where the conference is happening, and we can decide any streamId as it will be the name of the new merged stream.

Then we can play the merged stream by giving the correct streamId in the following URL:

https://<antmedia-url>:5443/<application-name>/player.html

webrtc stream merge and play

We can also see the stream in the Ant Media Management Panel:

ant media web panel screen

Now the merged stream is publishing from the server and it is ready for thousands of viewers! The merged video can be streamed to any social media or easily recorded as a single video file.

Important Note: This is automatically available for Ant Media Server 2.3 and above. To use this feature for the previous releases, you need to use the two following scripts and add them to your application folder.

https://github.com/ant-media/StreamApp/blob/master/src/main/webapp/merge_streams.html

https://github.com/ant-media/StreamApp/blob/master/src/main/webapp/js/stream_merger.js

Useful Links

You can download native Android and iOS WebRTC SDKs and integrate them into your applications for free!

Great Features for Online Video Platforms: Ant Media Server v2.3.0 is out!

You would want to check Future of Ultra-Low Latency Streaming Market, Video Codecs and Encoding, An Overview of WebRTC Statistics.

About Ant Media Server

Ant Media Server is a real-time streaming software that provides adaptive, ultra-low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is highly scalable both horizontally and vertically. It can run on-premise or on-cloud. Ant Media has a vast client portfolio in 120+ countries that include several industries and sectors such as education, gaming, broadcasting, auctioning, and surveillance. For more information about Ant Media Server, contact us. If you’re looking to build a streaming solution with adaptive bitrate streaming, ultra-low latency, and highly scalable features you can start free trial.

Categories: Tutorial