Stream with SRT

Secure Reliable Transport (SRT) is a cutting-edge protocol designed for low-latency, secure, and reliable live streaming—perfect for broadcasters who prioritize quality and stability. FastPix provides seamless integration of SRT, making it easy to set up and stream content with confidence.


In this guide, we’ll walk you through the setup process for SRT with FastPix, from obtaining your stream details to configuring your encoder and playback.


DEVELOPMENT TIP

SRT is particularly effective when streaming over long distances or across different geographical regions, as it handles network jitter and packet loss much better than traditional protocols.



Step 1: Get an API Access Token

After signing up with FastPix, all you now need is to generate your API access token. FastPix live streaming API utilizes a token key pair comprising a Token ID and Secret Key for authentication. Navigate to Settings and create a new Access Token in the Access Token settings within your Organization settings dashboard.


Step 1: Get an API Access Token

Access Tokens play a crucial role in FastPix, allowing you to securely interact with the platform. Once you click on Generate new token, a pop-up will appear with input fields to create your new Access Token.



Understanding workspace

Workspaces act as parent containers for Access Tokens, Signing Keys, and other elements in FastPix. When you create an Access Token, it is associated with a specific Workspace. For now, let’s focus on the Development workspace, which is ideal for testing and experimentation.


Access token permissions

Access Tokens come with different permissions, regulating the actions and extent of modifications they can perform. As you follow this guide, ensure that your Access Token has both FastPix Video Read and Write permissions. This ensures that you can read existing videos and upload new ones seamlessly.

To keep track of your Access Tokens within your application or project, you can assign them any name, like “Test”. This helps in managing and identifying them easily.

When you’re ready, proceed by clicking the ‘Generate access token’ button. This will create a new Access Token ID and Secret Key for you.



With your newly generated Access Token ID and Secret Key, you’re now set to start your first live stream with FastPix. Remember, proper management of your Access Tokens is crucial for the smooth operation of your application.


IMPORTANT

To keep the Access Token information (Secret Key) for future use, download an workspace file (.env) that stores these details. FastPix doesn’t store the exact Secret Key.


It's important to note that FastPix only stores a secret hash, not the Secret Key itself. If the Secret Key is lost, FastPix cannot retrieve it, necessitating the creation of a new Access Token. Also, make sure to keep your Secret Key safe and avoid exposing it, which might cause a security breach on your account.


Step 2: Create a live stream

To create a new live stream with FastPix, use the below API reference:

POST request to the create a new stream  endpoint.

The username and password that you would use in the POST request can be replaced with your own access token details (Access Token ID and Secret Key) generated from step 1.


curl -X POST https://v1.fastpix.io/live/streams \ 
		--user {Access token ID}:{Secret Key} \ 
     -H 'content-type: application/json' \ 
     -d ' 
{ 
  "playbackSettings": { 
    "accessPolicy": "public" 
  }, 
  "inputMediaSettings": { 
    "maxResolution": "1080p", 
    "reconnectWindow": 60, 
    "mediaPolicy": "public", 
    "metadata": { 
      "livestream_name": "fastpix_livestream" 
    }
  } 
} 
' 

Let’s talk about the request parameters

accessPolicy: Determines if access to the streamed content is kept private or available to all.
Possible values: public or private

maxResolution: Max resolution can be used to control the maximum resolution your media is encoded, stored, and streamed at. Accepts only 1080p, 720p, 480p resolutions and by default it’s set to 1080p.

reconnectWindow: It mainly works when any network issue occurs. The Reconnect Window determines how long the system waits (in seconds) before declaring a live stream as over; due to a disconnect. If not specified, it defaults to 60 seconds.

mediaPolicy: This flag determines the access policy (public/private) for media content created once the live stream has concluded. It specifies how the recorded stream will be handled in terms of availability, permissions, and visibility. Based on the flag's configuration, the media can either be made publicly accessible, restricted to certain users, or archived for internal use. This ensures proper control over the distribution and access of content after the live event has ended.

metadata: Arbitrary user-supplied metadata that will be included in the stream details and related webhooks. This can be used to store your own ID for a video along with the livestream. You can have maximum of 255 characters and upto 10 entries are allowed.



Step 3: Obtain your SRT details in response

You'll receive a SRT URL, Stream Id, and SRT Secret Key in the response.


{
  "success": true,
  "data": {
    "streamId": "fa7f8c0950ea48ebcc5ef9de8c23deaa",
    "streamKey": "3dc5d7641f918baa083a5c52a5bd9cbckfa7f8c0950ea48ebcc5ef9de8c23deaa",
    "srtSecret": "c51739512d0088d98a46925c9b74c73akfa7f8c0950ea48ebcc5ef9de8c23deaa",
    "trial": false,
    "status": "idle",
    "maxResolution": "1080p",
    "maxDuration": 43200,
    "createdAt": "2024-10-15T08:48:31.551351Z",
    "reconnectWindow": 60,
    "enableRecording": true,
    "mediaPolicy": "public",
    "metadata": {
      "livestream_name": "fastpix_livestream"
    },
    "playbackIds": [
      {
        "id": "4e43ec52-4775-4f68-a3ff-a57d8a59bba8",
        "accessPolicy": "public"
      }
    ],
    "srtPlaybackResponse": {
      "srtPlaybackStreamId": "playfa7f8c0950ea48ebcc5ef9de8c23deaa",
      "srtPlaybackSecret": "490e707dd4d165c9e38d261b252f9457kfa7f8c0950ea48ebcc5ef9de8c23deaa"
    }
  }
}

Here, srtSecret is the SRT Secret Key (passphrase) used in relation to the SRT protocol for secure live stream broadcasting. This key ensures encrypted transmission of media over the SRT connection, safeguarding the stream from unauthorized access or tampering.

From the API response you would also need the streamId which is a unique identifier assigned to the stream once it is created.


Playback for SRT stream is different compared to RTMPS streams. To playback your SRT stream you will need to use the below parameters from the response:

  • SrtPlaybackStreamId: A unique identifier used to reference and manage a specific SRT (Secure Reliable Transport) playback stream.

  • SrtPlaybackSecret: A secret key used to authenticate and secure access to the SRT playback stream.

Here're other parameters explained from the response:

streamKey: A stream key is a string of characters generated by FastPix when you create a live stream event. This string acts like a unique identifier or password, which is necessary to link your broadcasting software (like OBS) with FastPix. Please note, this is not required for SRT. streamKey is only valid when you want to stream with RTMPS.

trial: The flag indicates whether the organization you logged into is subscribed to either the enterprise plan or the test plan. The system automatically fetches the organization’s plan status and assigns a value based on this subscription.


PLEASE NOTE

PATCH and Simulcast functionalities won’t work for test streams (i.e. when provided true).


maxDuration: This setting defines the maximum time limit for which a customer can conduct a live stream. Once the live stream reaches this time limit, it will automatically stop. This feature is particularly useful for managing resources and ensuring that streams adhere to the plan's restrictions.

  • Depending on the organization's plan, the system retrieves a maxDuration value.
  • For organizations with a test plan, the maximum duration is 300 seconds (5mins).
  • For those with an Pay as you go plan, the maximum duration is 43,200 seconds (12 hours).

status: It gives you the current live stream status.

  • idle indicates that no live stream is currently in progress (the stream hasn't started yet).
  • preparing signifies that the stream is in the preprocessing phase, preparing to transition to the active state.
  • active means that the live stream is ongoing (the video is currently being streamed).
  • disabled means that streaming has been stopped, and no further streams can be published.

📘

PLEASE NOTE

Once the stream ends then automatically the status gets updated from active to idle and again if the stream starts then it changes to active. This happens till the stream duration is within the limits.

  • The status gets updated to disabled if the duration limit reaches.
  • The stream will no longer be accessible after it is disabled.

createdAt: It displays the UTC date-time when the live stream is created.


enableRecording: This value indicates whether the live stream is being recorded, allowing it to be saved and accessed later. By default, the system will return true in the response, meaning that all live streams will be recorded automatically.

Recording live streams is beneficial for creating archived content, allowing users to replay the stream later, or providing access to those who missed the live event.

playbackId:It is an array of playback ids for a live stream. playbackId in FastPix's Live Stream API work just like those for a video media. They allow you to do things like play live stream , grab thumbnails from a video, or make timeline hover previews with your player.



Step 4: Start broadcasting

To start live streaming, you or your users need software capable of pushing a SRT stream. This software will be configured using the Stream Key obtained earlier, along with FastPix's SRT server URL: srt://live.fastpix.io:778

The above URL is the standard entry point to stream SRT live with FastPix. This is compatible with almost every streaming applications and services.

You’ll need to construct the this URL by appending the necessary parameters to the URL. The format will be:

srt://live.fastpix.io:778?passphrase=<SRT Secret Key>&streamid=<Stream Id> 

Replace <SRT Secret Key> and <Stream Id> with the values from your API response. You can also find this information on the FastPix Dashboard.


Step 5: Configure your encoder

Once you have the constructed the SRT server URL, configure your streaming encoder in your broadcasting software. Let’s take an example using an open source broadcasting software like OBS Studio  :

  1. Open OBS Studio.
  2. Navigate to Settings > Stream.
  3. Set the Service to “Custom”.
  4. In the  Server field , paste the constructed SRT Server URL (e.g., srt://live.fastpix.io:778?passphrase=<SRTSecretKey>&streamid=<streamId>).
  5. In the passphrase field, paste the SRT Secret Key  you received from FastPix.
  6. Save the settings and start streaming!

OBS streaming

DEVELOPMENT TIP

Always test your stream before going live! This ensures everything is configured correctly and helps avoid any last-minute issues.


Step 6: Playback SRT streams

Playback of SRT streams is more complex compared to other protocols. But you can playback your SRT streams by first constructing the playback URL in the below format. You can also find this URL on the live stream detail page.

srt://live.fastpix.io:778?streamid=<playbackStreamId>&passphrase=<srtPlaybackSecret>

From the API response, use the values provided to you under srtPlaybackResponse to:

  • Replace {playbackStreamId} with "play" followed by your streamId.
  • Replace {srtPlaybackSecret} with the passphrase from your stream response.

Integrate into product

If you are a developer integrating SRT playback into your application, FFmpeg is a powerful solution. It allows you to handle real-time streaming efficiently and can be customized to fit your application's requirements.

Use the following command to play the stream:

ffplay -analyzeduration 1 -fflags -nobuffer -probesize 32 -sync ext '<SRT_PLAYBACK_URL>'

FFPlay is a command-line player built on FFmpeg, which supports SRT playback.

Ensure FFmpeg is installed on your system. Replace <SRT_PLAYBACK_URL> with your actual SRT playback URL.


View or test SRT streams

If you only need to view the stream without integration, VLC Media Player is a simpler alternative that supports SRT playback. Just open VLC, go to Media → Open Network Stream, and enter your SRT playback URL to start watching.


PLEASE NOTE

The live stream detail page in the dashboard shows a FastPix player configuration. When used, it displays an HLS stream when the SRT stream is triggered.


Step 7: Simulcast SRT streams to social platforms

Simulcasting allows you to broadcast your SRT stream to multiple platforms (e.g., YouTube, Twitch, Facebook) simultaneously. Using FastPix, you can send a primary SRT stream, which converts it to RTMPS streams for compatibility with third-party platforms that require RTMPS.


  1. Create a livestream and create multiple simulcast targets for it. You can refer this guide.

  1. Configure your broadcasting software (for example, OBS) by providing the FastPix SRT URL
    (e.g., srt://live.fastpix.io:778?streamid=<StreamID>&passphrase=<Passphrase>) and the Stream Key in the OBS via Settings > Stream > Service, and set the Service to Custom.

  1. In OBS, click Start Streaming, the primary SRT stream will be sent to FastPix, which processes it and pushes RTMPS streams to the configured platforms (YouTube, Twitch, Facebook).

PLEASE NOTE

Platform Compatibility: YouTube, Twitch, and Facebook require RTMP(S) ingestion. FastPix converts the SRT stream to RTMP(S) for these platforms.


Tips for optimal streaming

To ensure your live stream runs smoothly and reliably, here are a few tips:

  • Low Latency: SRT is optimized for low-latency streaming. However, network stability is key. Always prefer using a wired connection over wireless for better performance.
  • Adjust parameters: Configure your encoder’s bitrate and resolution to match your audience’s expectations. Higher bitrate and resolution can improve quality but require more bandwidth.
  • Monitor your stream: The FastPix Dashboard provides detailed monitoring for your livestream. Keep an eye on your stream’s connection stability, viewer statistics, and any performance alerts.

Troubleshooting common issues

If you run into issues while using SRT with FastPix, here are a few troubleshooting steps to try:

  • Connection errors: Double-check that the SRT URL, Stream Key, and Passphrase are entered correctly. Even a small typo can break the connection.
  • Low-quality stream: If the stream quality is poor, try adjusting your encoder’s bitrate or resolution settings for better video performance.
  • Playback issues: Verify that your playback URL includes the correct stream ID and passphrase. Test the URL in a supported media player.

If the issues persist, don’t hesitate to reach out to FastPix Support for further assistance.