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:
- Go to the Amazon Identity and Access Management Dashboard
- Click on “Create individual IAM Users” => “Manage Users”
- Click on “Create New Users”
- Enter the username "red5prostorage" — make sure that the "generate access key for each user" box is checked
- Click “Create” button to create credentials
- Click “Show User Security Credentials” to reveal the access and secret keys generated. It is critical that you make a note of these, as you will not be able to retrieve them from the AWS console if you happen to lose them.
- Click “download Credentials” button to download a csv file with the credentials to your computer. You will not have this option again, so keep this file in a safe place!
- Click “close” to close the window and return to IAM Users screen.
- You should be able to see the user you recently created - “red5prostorage” in the list on the page.
Give the storage account full access to S3:
- Click on the new user you just created (red5prostorage).
- Click on Permissions tab.
- Click on Attach Policy.
- Select the Policy Name - AmazonS3FullAccess, and click on Attach Policy.
- The credentials you created earlier can now be used for S3 specific operations.
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.
Install Red5 Pro Server
Following these instructions, install the Red5 Pro Server.
Modify 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
streams.dir= The base directory from which read from and recorded to. A streams application / scopes are appended to this path.
aws.access.key= Your AWS access key.
aws.secret.access.key= Your AWS secret access key.
aws.bucket.name= The S3 bucket in which files will be stored.
aws.bucket.location= Geographic location of the S3 bucket.
ffmpeg.path= Full path to the FFMpeg executable (Transcoding processor only).
ffmpeg.template= FFMpeg command line to use for transcoding.
max.transcode.minutes= Maximum time in minutes allotted for transcoding to run per file.
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.
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.
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
Change the forceVODRecord value from "false" to "true".
<!-- Force VOD recording --> <property name="forceVODRecord" value="false"/>
This will create, in
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:
- Stream URL or IP - Enter your server IP or URL (if your solution is clustered then enter the Origin IP address).
- Stream Port - enter port if using a different one than the Red5 Pro default 5080.
- Stream Websocket Port - enter port if using a different one than the Red5 Pro default 6262.
- Stream Context - enter if using different webapp than the default live.
- Stream Name - enter the stream name you want to subscribe to (do not incude the m3u8 extension), or leave blank for VOD.
- Subscribe via Red5 Pro Cluster? - check here if your servers are clustered.
- 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.
- Click on the Save button. This will generate the Stream URL and Stream WebSocket URL for the stream you've selected.
- 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.
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.