What is WebRTC?
WebRTC is a real time video communications protocol. WebRTC allow peer-2-peer communication of audio, video and data right from the browser without requiring any plugins.
WebRTC was designed to work in peer-to-peer manner, where the peers communicating with each other directly can share their audio, video and data.
The WebRTC video streams are very low latency (less than 500ms) and the audio, video and transmitted without any noticeable delay.
WebRTC is a set of protocols and APIs that allow audio, video communication, and also describe bandwidth management, latency and delivery with algorithms for network jitter and packet loss.
Unlike other real-time protocol, WebRTC works over UDP. WebRTC stress over timeliness, in WebRTC the packets must arrive quickly with a very low latency, hence UDP protocol is used.
WebRTC other set of protocols as well, for NAT Traversal, to negoation parameters for video and audio stream, to encrypt the data (in WebRTC the user data is end-to-end encrypted), implement congestion control and flow control etc.
- ICE: Interactive Connectivity Establishment (RFC 5245)
- SDP: Session Description Protocol (RFC 4566)
- DTLS: Datagram Transport Layer Security (RFC 6347)
- SCTP: Stream Control Transport Protocol (RFC 4960)
- SRTP: Secure Real-Time Transport Protocol (RFC 3711)
What is RTMP?
RTMP of Real-Time Messaging Protocol is a communication protocol for streaming audio, video and data over the internet. It was originally developed to used in conjunction with Adobe Flash player.
The RTMP video streams cannot be played in the browser without requiring any plugins, and flash player has been discounted for a long time.
RTMP is no longer being updated and has not support by the browsers and iOS and Android Devices.
RTMP has a noticeable 5-10 second latency/delay between the sender and receiver, that makes it a bad fit for use-cases that require a low delay and high level for interactivity.
Which services use RTMP?
Although RTMP is not supported by web browser and mobile devices natively, it is still very widely used for injection of video stream.
RTMP these days is not used by the end-user to consume the video streams, but by livestreaming and distribution platforms to accept the video streams as input.
It is the most popular ingestion format used by almost all live streaming services like, YouTube Live, Facebook Live, Twitch etc.
What is use-case for WebRTC to RTMP?
There are many uses cases where you want to sent a WebRTC call via RTMP.
Maybe you want to develop a video conferencing application using WebRTC and want the ability to send video of the video conference via RTMP to a Streaming Server that accepts RTMP as input or a Streaming Service like YouTube Live, Facebook Live or Twitch.
There is also a use case of live streaming in ultra low latency via WebRTC to some users/audience who want to view the stream in very low latency and also concurrently live streaming to other services via RTMP, like YouTube Live or your own Streaming Server that accepts RTMP to other audience where delay doesn't matter.
To achieve both the use-cases you can use Metered Video, we have API and SDK to develop highly custom and scalable video call solution that you can add in your application and also stream the call via RTMP.
And you can use Metered Real-Time Live streaming to Live Stream the meeting to thousands to viewers in ultra-low latency and concurrently stream out to 3rd party services via RTMP.
How WebRTC to RTMP would work?
WebRTC and RTMP cannot directly communicate with each other, so you would need some type of solution that would speak both WebRTC and RTMP and would accept the WebRTC stream and would forward to RTMP.
To do this you can build your custom solution or use a service like Metered Video.
As WebRTC is a peer-to-peer protocol, the custom solution would have to connect as a party to a WebRTC call, would need accept the video streams and audio streams of all the other participants in the call, and would need to compose the audio and video streams of all the participants and create a composite stream, and then would need to transmit the composite stream via RTMP protocol.
Metered Video has a built-in capability to stream a WebRTC to RTMP.
With Metered Video, you can stream a video call with multiple participants, and Metered Video will automatically combine the video and audio from all the participants in a single composed video stream and forward it to a RTMP service like YouTube Live, Facebook Live, Twitch etc.
Metered Video also has capabilities to record the stream at the same time, so you can record your WebRTC call and live stream it via RTMP at the same time.
WebRTC was designed to work peer-to-peer, to all the participants in the meeting connect to each other.
This causes problem in scaling a WebRTC call, because if there are 10 participants in a call, then each participant would have to send their video stream to 9 other participants.
This results in load in CPU and bandwidth of each peer, hence p2p WebRTC calls do not scale well above 3 participants, and you need to design custom architecture, where the video streams from all the participants are intercepted by the server and the server forwards the stream to the participants.
Using Metered Video you do not have worry about scale of your WebRTC call, you can have hundreds of participants in your call not worry about scaling.
How to stream WebRTC video call to RTMP?
You can easily stream your WebRTC video call to RTMP, you do this we will do a video call using Metered Embed, with Metered Embed you can Add Video Chat to your website or application with just one line of code.
Pre-requisite
You need to have a Metered Video account, if you don't have an account, signup for a free account from here: https://www.metered.ca -> Signup and Start Building
Step 1: Create a video chat room
Go to your Metered Dashboard and click on the "Create Room" button.
Step 2: Turn on RTMP Out
Now on the create room page, scroll down and "Enable RTMP Out",
Then Below the Enable RTMP Out control there is textbox with name RTMP OUT URL under the textbox enter the RTMP OUT URL for your live stream service.
We also have Guides on how the get the RTMP Out URL for popular live streaming services:
Enable Recording WebRTC Call (optional)
You can also record the Meeting while streaming it out via RTMP.
To enable recording, turn on Record Room and Record Composition buttons.
You can turn on any one or both the options.
Record Room: This option will record the audio and video stream of each participant in the meeting separately. So you will have a separate audio and video file for each participant in the meeting.
Record Composition: This option will combine all the video and audio streams of all the participants in the meeting into a single video file and record it. This recording will be exactly similar to the video stream that will be sent out via RTMP.
Adding Watermark (Optional)
You can also add Watermark to the video call that you are streaming out via RTMP.
Watermark can be any image, it could be your company logo that you want in the video stream.
To add the Watermark scroll to the Watermark on video section, and Enable Watermark.
The click "Choose File" and select an image file that you would like to add as a Watermark.
You can also select the Watermark Position to determine where you want the watermark to appear on the video.
And you can also optionally specify the width, height and X and Y position of the Watermark on the video.
Step 3: Initiating the Video Call
Scroll to the bottom of the Create Room page, and press the Create Room button. After you press the Create Room button you will be taken to the Room detail page, from here you will find the your Room URL.
Clicking the Open Button would launch the Metered Meeting, you can share the Meeting URL with other participants.
The other participants can join the meeting, and this meeting will be recorded and sent via RTMP to the RTMP out URL that you had specified.
How to stream WebRTC Livestream to RTMP
With Metered Real Time Live streaming you can stream to thousands of participants in ultra low latency of less than 300ms using WebRTC.
But if you want to also send this live stream via RTMP along with WebRTC, maybe your use-case is that you want to send some users an ultra low latency livestream via WebRTC and at the same time you want to send the stream to your Facebook Live/Twitch/YouTube Live audience then you need to do the following/
Step 1: Create a WebRTC Live stream
Go to your Metered Dashboard (https://dashboard.metered.ca) if you do not have an account then signup for a free account.
Then click on Live streaming, and click "Start free 14-day trial" and click on "Create Live Stream Room" button.
Step 2: Enable RTMP Out
On the create Live Stream room page, scroll down and turn on "Enable RTMP Out" option.
Specify the RTMP Out URL of the streaming service of your choice, we have guides on how to get the RTMP Out URL of popular streaming services:
Then scroll down and click on "Create Room" button
Recording the Live stream (optional)
If you want you can also record the live stream. In the create live stream room page, scroll up to find the option to Record Room and Record Composition.
The Record Room option will record separate audio and video streams, and the record composition option will
Step 3: Start Live Streaming
After you have created the Live Stream room, you will be taken to the detail page, here you can launch the Broadcast Manager to start your livestream.
Below the "Launch Broadcast Manager" button there will be also link to the Live Stream Viewer URL and information on how to embed the live stream to a webpage.
Step 4: Broadcasting Camera/Screen/File
Click on Launch Broadcast Manager and from there you can broadcast multiple cameras, screen or pre-recorded video file and switch instantly between them,
This stream will be instantly sent to the viewers via the Ultra-Low Latency Player and at the same time also sent via RTMP to your RTMP service whether be it Facebook Live, YouTube Live, Twitch.
Conclusion
In this guide we have gone through the instruction on how you can send a WebRTC video call and WebRTC Live Stream via RTMP out.
To summarize, if you want to stream WebRTC call to RTMP you can use service like Metered Video.
Metered Video, has Metered Embed Video Chat and Metered Video Call SDK.
With Metered Embed you can embed video chat into existing website or application using the pre-built UI.
With Metered Video Call SDK, you can develop your custom video chat solution using the API and SDKs provided by Metered video.
Both the solutions allow streaming out via RTMP and recording.
If you want to Live Stream via WebRTC and also concurrently stream to a RTMP endpoint, then you can use Metered Real-Time Live streaming.
With this you can use the broadcast interface to stream your camera, screen or pre-recorded video file and ultra-low latency via WebRTC and at the same time sent the stream via RTMP to a RTMP server.