Using AWS S3 for Video On Demand

The use of the Cloudstorage Plugin requires configuration in both the server and in each application utilizing the plugin features. The plugin configuration consolidates the majority of properties required to access cloud storage on Amazon S3. The server configuration must identify the post-processor implementations to use in conjunction with the FLVWriter. An application which will utilize cloud storage for recording and playback has to contain the bean entry for custom file name generator or it will use the Red5 Pro default location.

Create Security Account

Obtain security credentials for storage account S3 access:

Give the storage account full access to S3:

Set up an S3 Storage Bucket to be Used for VOD

Navigate to S3 Storage on AWS.

Click on the Create Bucket button.

Enter a bucket name and choose the region you wish it to be hosted in. (Note: bucket names must contain only lowercase characters. Also the bucket name cannot include any periods (.) or spaces, otherwise the playback feature will fail). The click on Create.

createbucket

Install Red5 Pro Server

Following these instructions, install the Red5 Pro Server.

Modify Cloudstorage Plugin Properties File

Edit the {red5pro}/conf/cloudstorage-plugin.properties file:

# Cloudstorage Plugin Properties
#
# JetS3t library configuration option info: http://jets3t.s3.amazonaws.com/toolkit/configuration.html
#

# Plugin Services
services=com.red5pro.media.storage.s3.S3Uploader,com.red5pro.media.storage.s3.S3BucketLister

# Path
streams.dir=/tmp/
# Full path to the ffmpeg executable
ffmpeg.path=/usr/bin/ffmpeg

# Time
max.transcode.minutes=5

# FFMpeg command line for transcoding flv to mp4
## add the '-report' parameter after '-y' to get a log for debugging if problems occur
## Variables: 0=replaced with ffmpeg path, 1=input file path, 2=output file path

### LGPL command template
#ffmpeg.template=%s -y -async 1 -i %s -acodec aac -b:a 128k -ar 44100 -strict -2 -vcodec libopenh264 -pix_fmt yuv420p -profile:v baseline -level 3.0 %s

### GPL command template
ffmpeg.template=%s -y -async 1 -i %s -acodec aac -b:a 128k -ar 44100 -strict -2 -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3.0 %s


# AWS Configuration
aws.access.key=YOUR_AWS_ACCESS_KEY
aws.secret.access.key=YOUR_AWS_SECRET_ACCESS_KEY
# Bucket name
aws.bucket.name=red5provod
# Valid locations are: US for United States, EU for Europe, and AS for Asia
aws.bucket.location=US

# Google Storage Configuration
gs.access.key=YOUR_GOOGLE_STORAGE_ACCESS_KEY
gs.secret.access.key=YOUR_GOOGLE_STORAGE_SECRET_ACCESS_KEY
# Bucket name
gs.bucket.name=red5provod

Plugin Properties

Server Configuration

The writer post processors used by FLVWriter are configured in the server's common configuration file: conf/red5-common.xml. The example below displays the configuration with the S3 post-processors (note - this bean exists in the file, you just need to modify & add the writer post processors value):

<bean id="flv.impl" class="org.red5.io.flv.impl.FLV">
  <property name="cache">
    <ref bean="object.cache"/>
  </property>
  <property name="writerPostProcessors">
    <set>
      <value>com.red5pro.media.processor.S3UploaderPostProcessor</value>
    </set>
  </property>
</bean>

This configuration indicates that the S3 upload writerPostProcessor which implements IPostProcessor will be executed after a file is finalized by the FLVWriter.

Application Configuration

Every server application that will utilize S3 for storage must have its configuration file modified to use the FilenameGenerator features. The live webapp (red5pro)/webapps/live/WEB-INF/red5-web.xml now contains this line which can be un-commented:

    <!-- Enable this if you're using S3 storage -->
    <!--
    <bean id="streamFilenameGenerator" class="com.red5pro.media.storage.s3.S3FilenameGenerator"/>
    -->

Red5 server applications use the streamFilenameGenerator bean when specified for locating media files for Playback or Recording; if the bean is not specified in an applications red5-web.xml, the default generator will be used which plays from and records to an applications streams directory.

HLS VOD

By default, Red5 Pro mobile clients record FLVs and HLS files; Flash clients record FLVs only. If you want to record HLS for Flash VOD as well, modify (red5pro)/conf/hlsconfig.xml

Change the forceVODRecord value from "false" to "true".

    <!-- Force VOD recording -->
    <property name="forceVODRecord" value="false"/>

This will create, in (red5pro)/webapps/live/streams, the streamname.m3u8 file and a number of streamname_#.ts files. In addition, if you are copying up to a storage bucket, then in the live directory, there will be a streamname sub-directory which contains the m3u8 and ts files.

Red5 Pro HTML5 HLS Example

You can view the HLS live or VOD stream using our HTML5 example here.

To use this example:

  1. Stream URL or IP - Enter your server IP or URL (if your solution is clustered then enter the Origin IP address).
  2. Stream Port - enter port if using a different one than the Red5 Pro default 5080.
  3. Stream Websocket Port - enter port if using a different one than the Red5 Pro default 6262.
  4. Stream Context - enter if using different webapp than the default live.
  5. Stream Name - enter the stream name you want to subscribe to (do not incude the m3u8 extension), or leave blank for VOD.
  6. Subscribe via Red5 Pro Cluster? - check here if your servers are clustered.
  7. Subscribe to Red5 Pro VOD? - check here to initiate playlists search for your VOD. The Stream Name box will change to a drop-down list of available HLS VOD streams.
  8. Click on the Save button. This will generate the Stream URL and Stream WebSocket URL for the stream you've selected.
  9. Click on the PLAY button that will appear at the top left of the black video preview.

Note that HLS latency is generally between 10 and 12 seconds, so you will not be able to view your live video right away.

S3UploaderPostProcessor

The S3UploaderPostProcessor simply uploads a supplied FLV file to an S3 bucket with a public read ACL and mime type of video/x-flv. For example, a file named stream1471289267434.flv recorded to the application live using a bucket named red5-s3 would be made available at https://s3.amazonaws.com/red5-s3/live/streams/stream1471289267434.flv after the upload is completed.