Start Broadcast Streaming using Agora domain
This page shows how to start Broadcast Streaming using the default Agora domain. With a simple API call, you get everything you need to push a live stream and play it back.
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- Enable Broadcast Streaming in Agora Console.
- Install streaming software such as OBS (Open Broadcaster Software) or XSplit Broadcaster.
Project setup
Get an App ID
Agora automatically assigns each project an App ID as a unique identifier.
To copy this App ID, find your project on the Project Management page in Agora Console, and click the copy icon in the App ID column.
Get a Customer ID and Customer Secret
Broadcast Streaming servers use a Customer ID/Customer Secret pair for authentication.
To generate a set of Customer ID and Customer Secret, do the following:
- In Agora Console, click the account name in the top right corner, and click RESTful API from the drop-down list to enter the RESTful API page.
- Click Add a secret, and click OK. A set of Customer ID and Customer Secret is generated.
- Click Download in the Customer Secret column. Read the pop-up window carefully, and save the downloaded
key_and_secret.txt
file in a secure location.
curl -u
command to generate the Authorization
parameter in the HTTP request header. Alternatively, you can use the sample code for other programming languages in Pass the basic HTTP authentication.Implement Broadcast Streaming
Step 1: Create a live stream
To create a live stream, send a request to the Broadcast Streaming endpoint:
-
Copy the following code into your command-line tool:
-
Replace
<Your_App_ID>
,<Your_Customer_ID>
, and<Your_Customer_Secret>
with your values from Agora Console. -
Replace
${region}
with the value for your business region:na
: North America.ap
: Southeast Asia.eu
: Europe.
If the request is successful, the response includes a Stream Key and a Playback ID, which are used in subsequent steps:
- Stream Key: A secret used to configure streaming software.
- Playback ID: A string used to create the playback URL.
The detailed description of the response body fields is as follows:
status
: Whether the request is successful. Possible values include:"success"
: The request is successful. Detailed information is returned indata
."fail"
: The request failed because of invalid arguments."error"
: The request failed because of a server error.
data
: A JSON Object which contains the following fields:id
: The unique identifier of the stream.streamKey
: The Stream Key, a secret used to configure streaming software.playbackIds
: A JSON Array of Playback ID objects. Each Playback ID object contains the following fields:id
: The Playback ID, a string used to create the playback URL.policy
: The playback policy. Possible values include:"public"
: The Playback ID alone can be used to play the live stream."private"
: The Playback ID must be used with a JSON Web Token (JWT) to play the live stream.
transcodings
: A JSON Object which contains the following fields:id
: The unique identifier of the transcoding configuration."default"
stands for the default configuration.standardTemps
: A JSON Array of the standard transcoding templates you want to use. For details about standard transcoding templates, see Transcoding Configuration API Reference.createdAt
: The time (Unix timestamp) when the transcoding configuration is created.
createdAt
: The time (Unix timestamp) when the live stream is created.
Step 2: Push the live stream
Broadcast Streaming supports pushing streams using the RTMP or RTMPS protocol. To push an RTMP or RTMPS stream, you need to configure streaming software. The following example uses OBS:
-
Open OBS, and click the Settings button in the widget list in the bottom right corner.
-
Click Stream in the left navigation menu in the Settings window, and choose Custom... in Service.
-
Fill in the Server and Stream key:
- Server:
rtmps://stream-in.agoramdn.com/live
- Stream key: The
streamKey
that is returned when you create a live stream.
- Server:
-
Click OK to save the settings.
Step 3: Play the live stream
To play the live stream, create an HTTP Live Streaming (HLS) playback URL using the Playback ID returned when you create the live stream:
For each live stream to be played, Broadcast Streaming automatically transcodes the stream into three resolutions. The URLs of these three stream versions are provided in the Master Playlist:
If you want to access the original stream (which is not transcoded), use the following playback URL instead:
Step 4: Stop streaming
Stop the streaming software to disconnect from the Broadcast Streaming servers.
Next steps
After implementing Broadcast Streaming, you can try the following functions.
Use transcoding templates
-
Get a
transcodingsId
by sending the following request:- Replace
<Your_App_ID>
,<Your_Customer_ID>
,<Your_Customer_Secret>
, and${region}
with your values. - Specify the transcoding templates you want to use in
standardTemps
. For details about the supported templates, see Transcoding Configuration API Reference.
If the request is successful, the response looks like this:
- Replace
-
Pass in the
transcodingsId
when creating a live stream: -
When playing the live stream, Broadcast Streaming automatically transcodes the stream using the specified templates. You can find the corresponding URLs in the Master Playlist.