FFMPEG Streaming πŸ“½οΈ

This guide explains how to use FFmpeg or FFplay to stream WAN video from Rhombus cameras. It includes authentication requirements and example commands.

🚧

Prerequisites

  • FFmpeg installed on your machine.
    • You can download and install the official FFmpeg here.
  • Valid API key and Federated Session Token.
    • Get your API Key here

Getting Started


Step 1: Obtaining a Federated Session Token

The federated session token is required for authentication when streaming WAN video. You can retrieve this token by hitting the following endpoint:

Endpoint: [api/org/generateFederatedSessionToken]

Description: This endpoint generates a federated session token login for the organization

Parameters:

  • durationSec (required): Total duration for the session in seconds. e.g. 24 hours -> 86400

Example Body Request:

{
  "durationSec":86400
}

Successful Example Response:

{
  "federatedSessionToken": "XXXXXXXXXXXXX"
}

Test here πŸ‘‰ /generateFederatedSessionToken πŸ‘ˆ



Step 2: Retrieving the WAN Media URI

To stream video from a camera, you will need the WAN media URI. You can retrieve it by hitting this endpoint:

Endpoint: [api/camera/getMediaUris]

Description: This endpoint gets the media URI for a camera in order to retrieve footage

Parameters:

  • cameraUuid (required): Camera UUID to get the necessary URIs for streaming

Example Body Request:

{
    "cameraUuid": "XXXXXXXXXXXXXXXX"
}

Successful Example Response:

{
  "error": false,
  "lanCheckUrls": [
    "https://IP_ADDRESS.lan.rhombussystems.com:PORT/XXXXXXXXXXXXXXXX/"
  ],
  "lanLiveH264Uris": [
    "wss://IP_ADDRESS.lan.rhombussystems.com:PORT/XXXXXXXXXXXXXXXX/ws"
  ],
  "lanLiveM3u8Uris": [
    "https://IP_ADDRESS.lan.rhombussystems.com:PORT/XXXXXXXXXXXXXXXX/live/live.m3u8"
  ],
  "lanLiveMpdUris": [
    "https://IP_ADDRESS.lan.rhombussystems.com:PORT/XXXXXXXXXXXXXXXX/live/live.mpd"
  ],
  "lanVodM3u8UrisTemplates": [
    "https://IP_ADDRESS.lan.rhombussystems.com:PORT/XXXXXXXXXXXXXXXX/store/{START_TIME}_{DURATION}/clip.m3u8"
  ],
  "lanVodMpdUrisTemplates": [
    "https://IP_ADDRESS.lan.rhombussystems.com:PORT/XXXXXXXXXXXXXXXX/store/{START_TIME}_{DURATION}/clip.mpd"
  ],
  "wanLiveH264Uri": "wss://IP_ADDRESS.dash-internal.rhombussystems.com:PORT/api/h264/live/XXXXXXXXXXXXXXXX/ws",
  "wanLiveM3u8Uri": "https://IP_ADDRESS.dash.rhombussystems.com:PORT/dash/api/outbound/XXXXXXXXXXXXXXXX/SESSION/time/live-v2/file.m3u8",
  "wanLiveMpdUri": "https://IP_ADDRESS.dash.rhombussystems.com:PORT/dash/api/outbound/XXXXXXXXXXXXXXXX/SESSION/time/live-v2/file.mpd",
  "wanVodM3u8UriTemplate": "https://IP_ADDRESS.dash.rhombussystems.com:PORT/dash/api/outbound/XXXXXXXXXXXXXXXX/SESSION/{START_TIME}/{DURATION}/vod/file.m3u8",
  "wanVodMpdUriTemplate": "https://IP_ADDRESS.dash.rhombussystems.com:PORT/dash/api/outbound/XXXXXXXXXXXXXXXX/SESSION/{START_TIME}/{DURATION}/vod/file.mpd"
}

Test here πŸ‘‰ /getMediaUrisπŸ‘ˆ


Step 3: Streaming with FFMPEG & FFPLAY

We can now use FFmpeg to stream and save WAN video to a local file.

Here is an example command:

ffmpeg -headers $'x-auth-scheme: api-token\r\nx-auth-apikey: YOUR_API_KEY\r\nCookie: RSESSIONID=RFT:YOUR_FEDERATED_SESSION_TOKEN' \
-i "https://IP.dash.rhombussystems.com:PORT/dash/api/outbound/CAMERA_UUID/SESSION/time/live-v2/file.m3u8" \
-c copy output.mp4

Breaking down the command:

  • The -headers option adds our required HTTP headers to the request.
    • x-auth-scheme - specifies the authentication scheme
    • x-auth-apikey - your Rhombus API key
    • RSESSIONID=RFT- your Federated Session Token
  • - i - specifies the input, we will be using the WAN media URI
  • -c copy- copies the video stream without re-encoding it
  • output.mp4 - the output file where the video stream will be saved

If you want to play the stream directly, you can use FFplay which is simpler than FFmpeg!

Example command:

ffplay -headers $'x-auth-scheme: api-token\r\nx-auth-apikey: YOUR_API_KEY\r\nCookie: RSESSIONID=RFT:YOUR_FEDERATED_SESSION_TOKEN' \
-i "https://IP.dash.rhombussystems.com:PORT/dash/api/outbound/CAMERA_UUID/SESSION/time/live-v2/file.m3u8"

Breaking down the command:

  • The -headers option adds our required HTTP headers to the request.
    • x-auth-scheme - specifies the authentication scheme
    • x-auth-apikey - your Rhombus API key
    • RSESSIONID=RFT- your Federated Session Token
  • - i - specifies the input, we will be using the WAN media URI

This works similarly to the FFmpeg command, but instead of saving the stream to a file, it plays the video in real-time.


πŸ“˜

Important Notes

  • Ensure you have the valid API token and session tokens.
  • Make sure the x-auth-apikey and RSESSIONID are replaced with your own credentials.
  • The federated session token has an expiration time, so you may need to regenerate it periodically.
    • For continuous streaming or automation, consider implementing a method to refresh the federated session token as needed.
  • These commands are in bash, please update header notation as needed per language syntax.

By following the steps outlined above, you can use FFmpeg and FFplay to stream WAN video from a Rhombus camera.


What's Next