Safeguarding Your Live Stream with AI: Ensuring Nudity-Free Content Using Agora and AWS Rekognition in Flutter

Home » Blog » Safeguarding Your Live Stream with AI: Ensuring Nudity-Free Content Using Agora and AWS Rekognition in Flutter



Live streaming has soared in popularity, enabling content creators to engage with their audience in real-time. Yet, as live-streaming platforms proliferate, the imperative to maintain appropriate, nudity-free content looms large. In this blog post, we’ll delve into the potent fusion of Agora, AWS Rekognition, Flutter, and Firebase, unveiling how AI-driven solutions can be your ally in safeguarding live streams from inappropriate content. Join us on this journey to explore innovative solutions that ensure a seamless viewing experience for your audience.

Step 1: Capturing Screenshots and Uploading to AWS S3

Step 1: Capturing Screenshots and Uploading to AWS S3

To begin safeguarding your live stream against nudity, we’ll follow these initial steps:

Understanding the Technology

Let’s start by understanding the core technologies at play:

Amazon Rekognition: As an integral part of Amazon’s AI services, Amazon Rekognition leverages deep learning for image analysis, lifelike text-to-speech conversion, and the creation of intuitive conversational interfaces. It forms the backbone of our content moderation solution.

Implementing a cloud recording process for your live stream involves several key steps:

  1. Get a Resource ID: Before initiating a cloud recording, you must acquire a cloud recording resource by calling the acquire method. This resource ID is essential for marking the recording process.
  2. Start a Cloud Recording: Use the start method to join the channel and start a cloud recording. You’ll receive a recording ID to monitor the current recording process.
  3. Query the Recording Status: Periodically check the recording status using the query method while the recording is in progress.
  4. Stop the Cloud Recording: When your live stream ends, call the stop method to terminate the cloud recording.
  5. Upload the Recording File: Once the recording is complete, the cloud recording service automatically uploads the recording file to your specified third-party cloud storage, in this case, AWS S3.


Before proceeding, make sure you have the following in place:

  • A valid Agora account.
  • An Agora project with an App ID and a temporary token.
  • Access to the internet and any necessary firewall configurations.
  • Third-party cloud storage service enabled (e.g., Amazon S3).
  • An active Video SDK channel with users actively streaming.

For this implementation, we’ll use the Cloud Recording RESTful API to capture screenshots of a video stream in a channel and upload them to AWS S3 storage. You can choose to capture screenshots only, or you can capture screenshots and recordings during the recording process, with Agora charging recording fees for the latter option. We will opt for the “Take screenshots only” approach.

You can organize your screenshots in a structure like this:

Refer to Agora’s official documentation for capturing and uploading screenshots to AWS S3: Agora Cloud Recording – Screen Capture

Step 2: Automating Image Moderation with AWS Lambda and Firebase

Step 2: Automating Image Moderation with AWS Lambda and Firebase

Now that we can capture and upload screenshots of our live stream, the next step is to automatically check these images for potential nudity using AWS Rekognition and update our streaming database through Firebase. Here’s how:

  1. Create an AWS Lambda Function: This Lambda function will interact with the same S3 bucket where your live stream screenshots are stored. It will analyze the content for potential nudity confidence and update your Firebase database accordingly.
  2. Code for Lambda Function:


// AWS Lambda function code

console.log(‘Loading function’);
const aws = require(‘aws-sdk’);
var rekognition = new aws.Rekognition();
const { initializeApp, applicationDefault, cert } = require(‘firebase-admin/app’);
const { getFirestore, Timestamp, FieldValue } = require(‘firebase-admin/firestore’);

const serviceAccount = require(‘./serviceAccountKey.json’);
credential: cert(serviceAccount)
const db = getFirestore();

exports.handler = async (event, context) => {
console.log(‘Received event:’, JSON.stringify(event, null, 2));

// Get the object from the event and show its content type
const bucket = event.Records[0];
const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ‘ ‘));
let userDocId = key.substring(“__uid_s_”)+“__uid_s_”.length,“__uid_e_video_”));//extract the channel id from user image
var params = {
Image: { /* required */
S3Object: {
Bucket: bucket,
MinConfidence: 50
try {
const response = await rekognition.detectModerationLabels(params, function(err, response) {
if (err) {
console.log(err, err.stack); // handle error if an error occurred
} else {

return response;
if(response !== null)
const isNudity= response.ModerationLabels.some((x)=> x.Confidence>70)//check nudity//x.Name === ‘Explicit Nudity’ &&
console.log(‘isNudity’, isNudity);
if (isNudity) {
const docRef = db.collection(‘streaming’).doc(userDocId);
await docRef.set({
‘isNudity’: true,
},{ merge: true});
console.log(`Detected for: ${key}`)

} catch (e) {
console.log(‘error’, e);

This code snippet utilizes the `detectModerationLabels` API to identify content with a confidence level exceeding 70%, signifying potential nudity or explicit content. If such content is detected, the Lambda function updates the Firebase database to actively monitor and potentially stop the live streaming from the front-end side.

For detailed instructions on configuring a trigger for an S3 bucket and deploying a Lambda function, refer to the official AWS documentation: AWS Lambda with Amazon S3 – Example



Shielding your live stream from inappropriate content isn’t just important; it’s essential for creating a safe and enjoyable viewing experience for your audience. The integration of Agora, AWS Rekognition, and Firebase empowers you with a formidable AI-driven solution to detect and promptly address nudity in real time. This comprehensive approach ensures that your live streams not only remain enjoyable but also free from explicit content, safeguarding the integrity of your content and the trust of your audience. Embrace these steps to fortify your live streams, knowing that your audience deserves nothing less than a secure and seamless viewing experience, thanks to the transformative power of AI.