This page shows how to start Fusion-CDN Live Streaming (FLS) using the default Agora domain. With a simple API call, you get everything you need to push a live stream and play it back.
Before proceeding, ensure that you meet the following requirements:
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 icon in the App ID column.
FLS servers use a Customer ID/Customer Secret pair for authentication.
To generate a set of Customer ID and Customer Secret, do the following:
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.To create a live stream, send a request to the FLS endpoint:
Copy the following code into your command-line tool:
appid=<Your_App_ID>
key=<Your_Customer_ID>
secret=<Your_Customer_Secret>
curl https://api.agora.io/${region}/v1/projects/${appid}/cfls/live-streams \
-u "${key}:${secret}" \
-X POST
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. Agora recommends setting it to where most of your app users are located:
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:
{
"status": "success",
"data": {
"id": "v2xxxxxxO5",
// Your Stream Key
"streamKey": "M3xxxxxxWb",
"playbackIds": [
{
// Your Playback ID
"id": "vgxxxxxxQy",
"policy": "public"
}
],
"transcodings": {
"id": "default",
"standardTemps": [
"fhd",
"sd1",
"ld"
],
"createdAt": "1640995200"
},
"createdAt": "1650017833"
}
}
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 in data
."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.FLS 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:
rtmps://stream-in.agoramdn.com/live
streamKey
that is returned when you create a live stream.Click OK to save the settings.
To play the live stream, create an HTTP Live Streaming (HLS) playback URL using the Playback ID returned when you create the live stream:
https://stream.agoramdn.com/${playbackId}.m3u8
When you use this playback URL, FLS automatically transcodes the live stream into three resolutions, so that the player can switch to the most appropriate resolution based on the measured network bitrate. The details of these three stream versions are provided in the Multivariant Playlist:
#EXTM3U
#EXT-X-VERSION:6
#EXT-X-STREAM-INF:BANDWIDTH=2150400,CODECS=mp4a.40.2,avc1.640020,RESOLUTION=1920x1080
https://global.manifest.a2.agoramdn.com/S3hLV2o3bUFrYWhwaUpmbWFLWmVaWmtkcVZ1WlB4TUhhQ3NSOmZoZA/rendition.m3u8?token=NjIzNDM2M2ZfYjA2NzEyZWJjMWMxNmEzNjA2NGVkNTcyMmQzYjE4ZTExZDE3YmU3NDM4YzYyNjc4NzU1MjE5MDk0NWJhMmUzYQ%3D%3D
#EXT-X-STREAM-INF:BANDWIDTH=655360,CODECS=mp4a.40.2,avc1.640020,RESOLUTION=640x360
https://global.manifest.a2.agoramdn.com/S3hLV2o3bUFrYWhwaUpmbWFLWmVaWmtkcVZ1WlB4TUhhQ3NSOnNkMQ/rendition.m3u8?token=NjIzNDM2M2ZfZWVlMzZjNGU0MjdiMDgzYTEwZGFjYWFlMGY0YmNhMjk4YzkxODllYTBhOGI3NjJjOWMzNmVkMmE1N2Q5MmMxYw%3D%3D
#EXT-X-STREAM-INF:BANDWIDTH=409600,CODECS=mp4a.40.2,avc1.640020,RESOLUTION=360x240
https://global.manifest.a2.agoramdn.com/S3hLV2o3bUFrYWhwaUpmbWFLWmVaWmtkcVZ1WlB4TUhhQ3NSOmxk/rendition.m3u8?token=NjIzNDM2M2ZfNDc4ZDRlYzk2MzkzMDBkYTA3MDE5NjRlMTg0NmYxMzdjNWI2MGJlNzJlMzA3MmU0MzRlNWU5MDM3MTYzYzM5Yw%3D%3D
If you want to access the original stream (which is not transcoded), use the following playback URL instead:
https://stream.agoramdn.com/${playbackId}_original.m3u8
Stop the streaming software to disconnect from the FLS servers.
After implementing FLS, you can try the following functions.
Get a transcodingsId
by sending the following request:
appid=<Your_App_ID>
key=<Your_Customer_ID>
secret=<Your_Customer_Secret>
curl https://api.agora.io/${region}/v1/projects/${appid}/cfls/live-transcodings\
-u "${key}:${secret}" \
-H "Content-Type: application/json" \
-X POST \
-d '{
"settings": {
"standardTemps": [
# Specify no more than three transcoding templates
"hd",
"sd1",
"ld"
]
}
}'
Replace <Your_App_ID>
, <Your_Customer_ID>
, <Your_Customer_Secret>
, and ${region}
with your values.
Specify the transcoding templates (no more than three) 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:
{
"status": "success",
"data": {
// Your transcodingsId
"id": "zFxxxxxxmk",
"standardTemps": [
"hd",
"sd1",
"ld"
],
"createdAt": "1650018546"
}
}
Pass in the transcodingsId
when creating a live stream:
curl https://api.agora.io/${region}/v1/projects/${appid}/cfls/live-streams \
-u "${key}:${secret}" \
-H "Content-Type: application/json" \
-X POST \
-d '{
"settings":{
"transcodingsId": "zFxxxxxxmk"
}
}'
When playing the live stream, FLS automatically transcodes the stream using the specified templates. You can find the corresponding URLs in the Multivariant Playlist.