How to detect the bitrate of a live stream in Red5 or Red5 Pro

Sometimes you need to calculate the bitrate (in kbps) of a live stream to restrict the usage or manage to the bill of the user. As of today, there is no direct way to get the bitrate of a live stream in Red5 open source or Red5 Pro. Instead, you can use this old-school sampling technique to estimate the bitrate of a live stream which can be coded in any language for any platform.

The steps involved in evaluating the bitrate cab roughly be written as in the following manner :

  1. On application startup, start a timer which will be running continuously (every 2 seconds), aiding in evaluation of bitrates of all candidate streams taken fro a list.
  2. Detect publish start for a new stream
  3. On publish start add the stream to a list as a candidate for evaluation
  4. For each evaluation cycle inside the timer calculate the current estimated bitrate using bytes-transferred-inwards data
  5. Store the evaluated bitrate sample in a tmp data structure. In the similar way capture about 4 or 6 data samples.
  6. Take the average of all the data samples collected to get a average bitrate
  7. Finally use this average bitrate data to calculate bitrate per second.
  8. On unpublish remove the stream from list of candidates so that we dont get a NullPointerException

The code snippet below demonstrates how to calculate and log the average bitrate of a live stream in Red5.


Detect if the stream being published to Wowza is an SRT stream or not.

The latest version of Wowza adeptly supports SRT ingest. Here is an article from Wowza that explains how to publish an SRT stream from Wirecast and get it into Wowza through Mediacaster. It is a fairly simple step by step to getting started with SRT. But now we are left with the dilemma of how to detect this on the server-side within a module. In other words how to know in a module if the publishing stream is an SRT stream or not. Here is a code snippet from the onPublish method of an IMediaStreamActionNotify implementation that demonstrates how to check if the stream is an SRT stream.

public void onPublish(IMediaStream stream, String arg1, boolean arg2, boolean arg3) {
    getLogger().info(".onPublish => stream " + arg1);
    RTPStream rtpStream = stream.getRTPStream();
    if (rtpStream != null)
            getLogger().info("SRT stream detected => stream name : " + arg1);