How can I automatically upload the VOD file to my s3 bucket that I am uploading to Ant media server?

Viewed 66

When s3 integration is enabled on Ant media server, recorded VODs are uploading to s3 bucket but when we are uploading any VOD file on server it is not uploading on s3 bucket. Is there any way to do that on the server side?

1 Answers

You can automatically transfer the VoD files with this script to the S3 bucket by following the steps below.

1. Install FFmpeg

apt-get update && apt-get install ffmpeg -y

2. Save the script under /usr/local/antmedia/ and change permission by using chmod command it. (Don't forget to add AWS Access/Secret keys)

You can download the script from the following link or you can find it at the bottom of the page.

https://github.com/muratugureminoglu/Scripts/blob/master/vod-upload-s3.sh

chmod +x /usr/local/antmedia/vod-upload-s3.sh

3. Modify the red5-web.properties file in your webapps as follows.

vim [AMS-DIR]/webapps/your_application/WEB-INF/red5-web.properties

Add or change the following line.

settings.vodUploadFinishScript=/usr/local/antmedia/vod-upload-s3.sh

4. Restart Ant Media Server service.

systemctl restart antmedia

5. Follow the link below to play the uploaded VoD files.

VOD not playing after s3 recording enabled in Ant Media server

That's it.

Script

#!/bin/bash
# 
#  Installation Instructions
#
#  apt-get update && apt-get install ffmpeg -y
#  vim [AMS-DIR]/webapps/applications(LiveApp or etc.)/WEB-INF/red5-web.properties
#  settings.vodUploadFinishScript=/Script-DIR/vod-upload-s3.sh
#  sudo service antmedia restart
#

# Check if AWS CLI is installed
if [ -z `which aws` ]; then
        rm -r aws* > /dev/null 2>&1
        echo "Please wait. AWS Client is installing..."
        curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" > /dev/null 2>&1
        unzip awscliv2.zip > /dev/null 2>&1
        sudo ./aws/install &
        wait $!
        echo "AWS Client installed."
        rm -r aws*
fi

# Delete the uploaded VoD file from local disk
DELETE_LOCAL_FILE="Y"

AWS_ACCESS_KEY=""
AWS_SECRET_KEY=""
AWS_REGION=""
AWS_BUCKET_NAME=""

#AWS Configuration
aws configure set aws_access_key_id $AWS_ACCESS_KEY
aws configure set aws_secret_access_key $AWS_SECRET_KEY
aws configure set region $AWS_REGION
aws configure set output json


tmpfile=$1
mv $tmpfile ${tmpfile%.*}.mp4"_tmp"
ffmpeg -i ${tmpfile%.*}.mp4"_tmp" -c copy -map 0 -movflags +faststart $tmpfile
rm ${tmpfile%.*}.mp4"_tmp"

aws s3 cp $tmpfile s3://$AWS_BUCKET_NAME/streams/ --acl public-read

if [ $? != 0 ]; then
        logger "$tmpfile failed to copy file to S3. "
else
        # Delete the uploaded file
        if [ "$DELETE_LOCAL_FILE" == "Y" ]; then
                aws s3api head-object --bucket $AWS_BUCKET_NAME --key streams/$(basename $tmpfile)
                if [ $? == 0 ];then
                        rm -rf $tmpfile
                        logger "$tmpfile is deleted."
                fi
        fi
fi
Related