How to Record HLS Streamsto S3 in Ant Media Server?

Viewed 137

I want to record all HLS streams/previews to S3 bucket. How can I do that?

1 Answers

There are a couple of ways to upload the HLS files to S3. First solution is writing files to S3(mounting the S3 Bucket) while broadcasting and second solution is writing the files after broadcasting is finished.

Before Starting

If you would like to have full recording of HLS files, you need to do following settings

  1. Set HLS playlist type(settings.hlsPlayListType) to event and settings.deleteHLSFilesOnEnded to false . Edit your /usr/local/antmedia/webapps/{YOUR_APP}/WEB-INF/red5-web.properties for the application and set the following settings
    settings.hlsPlayListType=event
    settings.deleteHLSFilesOnEnded=false
    
  2. Restart the server
    sudo service antmedia restart
    

First Solution: Writing HLS files to S3 while broadcasting (aka. Mount S3 Bucket)

  1. Install s3fs
    sudo apt install s3fs
    
  2. Create access key and secret key from AWS IAM - that has write access to S3 buckets
  3. Write your access and secret key to configuration file
    echo {WRITE_YOUR_ACCESS_KEY_ID}:{WRITE_YOUR_SECRET_ACCESS_KEY} | sudo tee /etc/passwd-s3fs > /dev/null
    sudo chmod 600 /etc/passwd-s3fs
    
  4. Create directory to mount S3
    sudo mkdir /mnt/myS3Bucket
    
  5. Mount S3
    sudo s3fs -o dbglevel=info -o curldbg -o allow_other -o use_cache=/tmp/s3-cache myS3Bucket /mnt/myS3Bucket
    
    Please check the disk if mount is successful. You should see a line similar to below in the output when you run df
    s3fs           274877906944        0 274877906944   0% /mnt/myS3Bucket
    
  6. Link your app's streams directory to your mount directory
    sudo ln -s /mnt/myS3Bucket /usr/local/antmedia/webapps/{YOUR_APP}/streams
    

After that all your streams are directly written to S3 bucket.

Second Solution: Writing the HLS files to S3 after broadcasting is finished

You can do that with Ant Media Server S3 integration. Check this out

antmedia.io

Related