Skip to main content
Version: 2.x.x

RTMP Livestream - Flutter

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 Room object. This method accepts three parameters:

  • 1. outputs: This parameter accepts an array of objects which contains the RTMP url and streamKey of the platforms you want to start the livestream.

  • 2. config (optional): This parameter will define how the livestream layout should look like.

  • 3. transcription (optional): This parameter lets you start post transcription for the recording.

 var outputs = [
{
url: "rtmp://a.rtmp.youtube.com/live2",
streamKey: "<STREAM_KEY>",
},
{
url: "rtmps://",
streamKey: "<STREAM_KEY>",
},
];
Map<String, dynamic> config = {
// Layout Configuration
layout: {
type: "GRID", // "SPOTLIGHT" | "SIDEBAR", Default : "GRID"
priority: "SPEAKER", // "PIN", Default : "SPEAKER"
gridSize: 4, // MAX : 4
},

// Theme of livestream
theme: "DARK", // "LIGHT" | "DEFAULT"
};

// Post Transcription Configuration
Map<String, dynamic> transcription = {
"enabled": true, // Enables post transcription
"summary": {
"enabled": true, // Enables summary generation
// Guides summary generation
"prompt":
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary",
}
};

room.startLivestream(outputs, config: config, transcription: transcription);

stopLivestream()​

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

Example​

import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class LivestreamScreen extends StatefulWidget {
...
}

class _LivestreamScreenState extends State<LivestreamScreen> {
late Room _room;

@override
void initState() {
...
}

@override
Widget build(BuildContext context) {
return Column(
children:[
ElevatedButton(
onPressed:(){
var outputs = [
{
url: "rtmp://a.rtmp.youtube.com/live2",
streamKey: "<STREAM_KEY>",
},
{
url: "rtmps://",
streamKey: "<STREAM_KEY>",
},
];
var liveStreamConfig = {
'layout': {
'type': 'GRID',
'priority': 'SPEAKER',
'gridSize': 4,
},
'theme': "LIGHT",
};
room.startLivestream(outputs, config: livestreamConfig);
},
child: const Text("Start Livestream"),
),
ElevatedButton(
onPressed:(){
_room.stopLivestream();
},
child: const Text("Stop Livestream"),
),
]
);
}
}

Event associated with Livestream​

  • livestreamStateChanged - Whenever meeting livestream state changes, then livestreamStateChanged event will trigger.
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class LivestreamScreen extends StatefulWidget {
...
}

class _LivestreamScreenState extends State<LivestreamScreen> {
late Room room;

@override
void initState() {
...

setupRoomEventListener();
}

@override
Widget build(BuildContext context) {
return YourLivestreamScreenWidget();
}

void setupRoomEventListener() {
room.on(Events.livestreamStateChanged, (String status) {
//Status can be :: LIVESTREAM_STARTING
//Status can be :: LIVESTREAM_STARTED
//Status can be :: LIVESTREAM_STOPPING
//Status can be :: LIVESTREAM_STOPPED
log("Meeting Livestream status : $status");
});
}
}

API Reference​

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

Got a Question? Ask us on discord