Docs / Reference / Video APIs / Live Stream and Live Video Analysis

Live Stream and Live Video Analysis

Introduction

If your application or site supports live streaming, you will probably want to monitor and analyze in real-time the content that is being streamed — to moderate unwanted content, but also to detect AI-generated videos, spot deepfakes or run any other model.

This is possible with Sightengine's Live streaming API. The API is entirely automated — which makes it very fast and scalable — and it is completely customizable, so that you can define your own rules and pick the models you need.

Here are the steps to analyze live streams:

  1. Your back-end submits a live stream to the Sightengine API
  2. Sightengine analyzes the live stream, and creates alerts each time unwanted content is detected
  3. Your back-end receives callbacks (a.k.a. webhooks) to inform you of any unwanted content. You can also poll Sightengine to ask for status updates, moderation progress and results

Get API access credentials

The Sightengine API uses a key pair that consists of an API user id and an API secret for authentication. To get your own API credentials, create an account and go to the API key page to retrieve them.

Pick your Models

Sightengine has a long list of models that you can pick and choose from. A model is a video recognition engine designed for a specific task — spotting unwanted content, detecting AI-generated videos, spotting deepfakes and more.

Here are our most popular models for live streams:

nudity-2.1

Detect all types of nudity and sexual content. Pornography, X-rated nudity, partial nudity, suggestive scenes and poses, lingerie... More

violence

Detect physical violence, threats and more More

offensive

Detect offensive and hateful signs, symbols, flags and gestures. More

weapon

Detect weapons, firearms and threatening knives More

face-analysis

Analyze face quality, obstruction, angle, sunglasses etc More

gore-2.0

Detect horrific imagery including scenes with blood, wounds, self-harm, guts... More

recreational_drug

Detect recreational and medical drugs More

alcohol

Detect wine, beer, cocktails, spirits. More

gambling

Detect gambling, casinos, slot machines... More

tobacco

Detect smoking and tobacco products More

money

Detect displays of money and banknotes More

self-harm

Detect self-harm More

genai

Detect if a video was AI-generated More

The full list of models along with details is available in the Model Reference.

Submit a Live Stream to Sightengine

Once a live stream has started, you need to send the URL of your live-stream to the Sightengine API along with your list of moderation models.

Sightengine supports the following protocols for live video ingestion:

  • HLS also known as HTTP Live streaming, over HTTPS or HTTP
  • RTMP, Real-Time Messaging Protocol, along with its variants RTMPS, RTMPT, RTMPE, RTMPTE and RTMPTS
  • RTSP and RTP, Real Time Streaming Protocol
  • MPEG-DASH MPEG Dynamic Adaptive Streaming over HTTP

Stream URLs can use any port from 1024 upwards. Ports below 1024 are refused, except 80, 443, 554, 322, 81, 88.

Live streams are analyzed for up to 30 minutes by default. On Starter and Pro plans, you can raise this limit to 60 minutes with the max_duration parameter, in seconds (for instance max_duration=3600). Once this duration has been reached, or if the stream ends or stops sending data, the analysis ends and the job gets the finished status. To keep monitoring a stream beyond that point, submit it again. Enterprise plans can get longer limits: contact us.

Live stream analysis is available on the Starter, Pro and Enterprise plans. See pricing for details.

Send it through a POST request to Sightengine, along with the list of models. The callback_url parameter is optional: if you omit it, signed callbacks are sent to the account-level callback URL defined on your dashboard. Callbacks sent to a callback_url are not signed (details).


curl -X POST 'https://api.sightengine.com/1.0/video/check.json' \
    --data-urlencode 'stream_url=https://yourvideo/path' \
    -d 'models=nudity-2.1' \
    -d 'callback_url=https://your.callback.url/path' \
    -d 'api_user={api_user}' \
    -d 'api_secret={api_secret}'


# this example uses requests
import requests
import json

params = {
  'stream_url': 'https://yourvideo/path',
  # specify the models you want to apply
  'models': 'nudity-2.1',
  # specify where you want to receive result callbacks
  'callback_url': 'https://your.callback.url/path',
  'api_user': '{api_user}',
  'api_secret': '{api_secret}'
}
r = requests.post('https://api.sightengine.com/1.0/video/check.json', data=params)

output = json.loads(r.text)


$params = array(
  'stream_url' => 'https://yourvideo/path',
  // specify the models you want to apply
  'models' => 'nudity-2.1',
  // specify where you want to receive result callbacks
  'callback_url' => 'https://your.callback.url/path',
  'api_user' => '{api_user}',
  'api_secret' => '{api_secret}',
);

// this example uses cURL
$ch = curl_init('https://api.sightengine.com/1.0/video/check.json');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);

$output = json_decode($response, true);


// this example uses axios and form-data
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

data = new FormData();
data.append('stream_url', 'https://yourvideo/path');
// specify the models you want to apply
data.append('models', 'nudity-2.1');
// specify where you want to receive result callbacks
data.append('callback_url', 'https://your.callback.url/path');
data.append('api_user', '{api_user}');
data.append('api_secret', '{api_secret}');

axios({
  method: 'post',
  url:'https://api.sightengine.com/1.0/video/check.json',
  data: data,
  headers: data.getHeaders()
})
.then(function (response) {
  // on success: handle response
  console.log(response.data);
})
.catch(function (error) {
  // handle error
  if (error.response) console.log(error.response.data);
  else console.log(error.message);
});

The JSON response contains the media id for your stream. The media id is a string that starts with med_

            
            
{
    "status": "success",
    "request": {
        "id": "req_1ML249NoEZ8j12op9Lipg",
        "timestamp": 1508774201.3177
    },
    "media": {
        "id": "med_1ML2wKmVgucuNPBN6xT33",
        "uri": "https://yourvideo/path"
    },
    "callback": "https://yourcallback/path"
}
            
        

In the above example, med_1ML2wKmVgucuNPBN6xT33 is the media id you should store to monitor the progress of this moderation job.

Next steps

Once Sightengine starts analyzing a live stream, you can retrieve results in realtime through two separate channels: either through callbacks (this is the recommended approach as it is more efficient and faster) or by polling the API.