Skip to main content
Version: 2.0.x

RTMP Livestream - iOS

RTMP is a widely used protocol for live streaming video content from VideoSDK to platforms like YouTube, Twitch, Facebook, and others.

To initiate live streaming from VideoSDK to platforms supporting RTMP ingestion, you simply need to provide the platform-specific stream key and stream URL. This enables VideoSDK to connect to the platform's RTMP server and transmit the live video stream.

Furthermore, VideoSDK offers flexibility in configuring livestream layouts. You can achieve this by either selecting different prebuilt layouts in the configuration or by providing your custom template for livestreaming, catering to your specific layout preferences.

This guide will provide an overview of how to implement starting and stopping RTMP livestreaming with VideoSDK.

startLivestream()​

startLivestream() can be used to start a RTMP livestream of the meeting which can be accessed from the Meeting class. This method accepts two parameters:

  • outputs: This parameter accepts a list of LivestreamOutput objects which contains the RTMP url and streamKey of the platforms you want to start the livestream.
class MeetingViewController {

private let platformUrl = "<url-of-the-platform>"
private let privateKey = "<private-key>"

// button to start livestream
@IBAction func startLiveStreamButtonTapped(_ sender: Any) {
self.meeting?.startLivestream(outputs: LivestreamOutput(url: platformUrl, streamKey: privateKey))
}
}

stopLivestream()​

  • stopLivestream() is used to stop the meeting livestream which can be accessed from the Meeting class.

Example​

class MeetingViewController {
// button to stop livestream
@IBAction func startLiveStreamButtonTapped(_ sender: Any) {
self.meeting?.stopLivestream()
}
}

Event associated with Livestream​

  • onLivestreamStateChanged - Whenever meeting livestream state changes, then onLivestreamStateChanged event will trigger.
extension MeetingViewController: MeetingEventListener {
// rtmp-event
func onLivestreamStateChanged(state: LiveStreamState) {
switch(state) {
case .LIVESTREAM_STARTING:
print("livestream starting")

case .LIVESTREAM_STARTED:
print("livestream started")

case .LIVESTREAM_STOPPING:
print("livestream stoping")

case .LIVESTREAM_STOPPED:
print("livestream stopped")
}
}
}

Custom Template​

With VideoSDK, you have the option to employ your own custom-designed layout template for RRTMP livestreaming. To use a custom template, follow this guide to create and set up the template. Once the template is configured, you can initiate recording using the REST API, specifying the templateURL parameter.

API Reference​

The API references for all the methods utilised in this guide are provided below.

Got a Question? Ask us on discord