CDN live streaming refers to the process of publishing streams to the CDN (Content Delivery Network), where users can view a live broadcast with a web browser.
You can use transcoding to combine the streams of all hosts in the channel into one stream, or set the audio/video profiles and picture-in-picture layout for the stream to be published to the CDN.
The following figure shows a typical CDN-pushing scenario.
Ensure that you enable the RTMP Converter service before using this function.
- Log in Console, and click in the left navigation menu to go to the Products & Usage page.
- Select a project from the drop-down list in the upper-left corner, and click Duration under RTMP Converter.
- Click Enable RTMP Converter.
- Click Apply to enable the RTMP Converter service and get 500 max concurrent channels.
Now, you can use the function and see the usage statistics.
Agora's CDN publishing solution is based on the following API methods to publish streams to the CDN, inject external audio streams, transcode, and set the output layout.
setLiveTranscoding: Sets the live transcoding configuration.
addPublishStreamUrl: Adds a stream to the CDN.
removePublishStreamUrl: Removes a stream from the CDN.
- The host calls the
setLiveTranscodingmethod to set the transcoding parameters, for example, the canvas settings, after joining a channel. The host still needs to set a 16 × 16 view when only publishing an audio stream to CDN.
- The host adds or removes a URL with the
removePublishStreamUrlmethods after joining the channel.
// CDN transcoding settings. AgoraLiveTranscodingUser *user = [[AgoraLiveTranscodingUser alloc] init]; user.uid = 12345; user.rect = CGRectMake(0, 0, 16, 16); user.audioChannel = 0; AgoraRtcEngineKit *rtcEngine = [AgoraRtcEngineKit sharedEngineWithAppId:@"" delegate:nil]; AgoraLiveTranscoding *transcoding = [[AgoraLiveTranscoding alloc] init]; transcoding.audioSampleRate = AgoraAudioSampleRateType44100; transcoding.audioChannels = 2; transcoding.size = CGSizeMake(16, 16); transcoding.videoFramerate = 15; transcoding.videoCodecProfile = AgoraVideoCodecProfileTypeHigh; transcoding.transcodingUsers = @[user]; [rtcEngine setLiveTranscoding:transcoding];
// Adds a URL to which the host pushes a stream. // Set the transcodingEnabled parameter as YES to enable the transcoding service. Once transcoding is enabled, you nee to set the live transcoding configurations by calling the setLiveTranscoding method. We do not recommend transcoding in the case of a single host. [rtcEngine addPublishStreamUrl:streamUrl transcodingEnabled:YES];
// Removes a URL to which the host pushes a stream. [rtcEngine removePublishStreamUrl:streamUrl];