Media Gateway enables users to push content to Agora SD-RTN™ using standard streaming protocols such as RTMP and SRT. The channel host automatically publishes this streamed content to the correct channel. Possible use cases are:
Enrich the viewing experience with commentary: Seamlessly inject high-definition video source streams into interactive channels to enhance the viewing experience. Multiple anchors from different locations watch and interact in real-time, adding depth to the media with their commentary.
Low-latency distribution scenarios: Distribute content to viewers in a faster and more stable way than using a Content Deliver Network (CDN). In scenarios such as online auctions and bidding platforms, bidders receive a real-time video feed enabling them to swiftly place their bids.
Recording to live broadcast: Enhance content quality and reduce live production complexity by injecting prerecorded media into a live broadcast. For example, a teacher records aspects of a lesson in advance and adds it to a live classroom. All students and teaching assistants watch the teacher's lecture, and interact in real-time.
Avoid interruptions due to host switching: Background music is played continuously in a chat room without interruptions if the host leaves the channel.
Using Media Gateway RESTful API, you generate a streaming key. This key allows you to push online media streams as live video source streams into Agora channels.
With Media Gateway, you can employ advanced transcoding capabilities on media streams for enhanced distribution. To enable and configure transcoding options, you use the Media Gateway RESTful API. When transcoding is enabled, you can set parameters such as resolution, frame rate, bit rate, and whether to enable video streams with high and low resolutions.
To activate the Media Gateway, contact Agora support. When you activate Media Gateway, you specify your access area to optimize the transmission quality of the media stream.
The Media Gateway RESTful API supports the following interfaces:
|Acquire a stream key. You use the stream key to |
|Set the video and audio transcoding configuration.|
By default, the video stream is pushed directly to the Agora channel without transcoding. If you need to transcode, use this interface to set the relevant parameters.
|Query information about stream keys, such as the bound UID, the bound channel name, and validity.|
|Destroy a stream key.|
To use the Media Gateway RESTful API and obtain the relevant code, refer to the API reference. If you need to push multiple streams to the same channel, use a unique uid to generate each stream key.
The stream key generation method depends on whether you use the Agora domain name or a custom domain name. To use the Agora domain name, create a stream key using the Media Gateway RESTful API.
When using your own domain name for streaming, the stream key can be generated locally. Contact Agora technical support to bind your custom domain name. To generate a stream key locally, you use the following information:
- The App Id of the Agora project from Agora Console.
- The App certificates corresponding to your App Id.
- A channel name.
- The user Id of the anchor in the Agora channel.
- The effective duration (seconds) of the stream keys.
The following Node.js sample code demonstrates how to generate a stream key:
This section shows you how to test Agora Media Gateway using OBS Studio, a free and open-source, cross-platform streaming app. Take the following steps to start streaming using OBS Studio:
Download and install OBS studio.
From the main screen, select Settings and switch to the Stream tab.
Fill in the following information:
Service: From the dropdown list, select
Server: Enter the scheme
rtmp://, followed by the unified Agora domain name, or your own domain name. The unified Agora domain name is
<region>with the code for your geographical region. You also need to append
/liveafter the domain name.
The supported regions and their codes are:
na: North America
ap: Asia, except Mainland China
cn: Mainland China
To use your own domain name, please contact Agora technical support for configuration.
Stream key: A valid stream key, acquired using the Media Gateway RESTful API or generated locally, that corresponds to your server domain name.
Set streaming options to avoid B-frames in source streams:
To avoid compatibility issues with Agora viewer on the web when transcoding is not enabled, and the source stream contains B-frames, use one of the following methods in OBS studio:
In OBS Studio, go to Settings > Output > Encoder Settings, and set the x264 Options to
Add a Tune parameter
In OBS Studio, go to Settings > Output > Encoder Settings, and set the Tune parameter to
Save the configuration and return to the main screen.
Under Sources, press + to add a new source then select Media Source from the menu. Type in a name for your source and Browse to select a video file.
Generate a temporary token in Agora Console for the same channel name you used to generate the stream key but use a different
In your browser, navigate to the Agora web demo and update App ID, Channel, and Token with the values for your temporary token, then click Join.
In OBS Studio, press Start Streaming to begin streaming to your Agora Channel.
You see a video stream displayed in the channel, with the
uidyou used to generate the stream key.
DeleteMedia Gateway RESTful API interfaces to manage your stream.
This section contains information that completes the information in this page, or points you to documentation that explains other aspects to this product.
Refer to the Media Gateway RESTful API for parameter details and to obtain the calling code for your platform.
Media Gateway supports the following media streaming formats and protocols:
- Video codec: H.264, H.265
- Audio codec: AAC, OPUS
- Streaming protocol: RTMP, SRT
- Media format: FLV, MPEG-TS