This project allows upload of HLS based streaming data from the SRS (Simple Realtime Server, https://ossrs.io/) to an S3 based storage. The purpose is to publish a stream in HLS format to a cloud based data store to leverage CDN distribution.
This project implements a NodeJs based webserver that provides a web hook that can be registered with SRS's `on_hls` webhook. Whenever a new video segment is created, this web hook is called and the implementation in this project uploads the `.ts` video segment as well as the `.m3u8` playlist information
to the storage bucket.
To keep the bucket usage limited to a small amount of data, segments before a certain time frame (e.g. 60s) are automatically deleted from the bucket.
1. Create a new website for your domain. The setup of the Domain is not part of this guide. Alternatively you can also register a domain with Cloudflare. Your own domain is
not absolutely necessary but it enabled you to use the CDN.
5. To be able to include the contents in a streaming website, e.g. `zap.stream`, set the CORS settings of the bucket to allow any website to use your stream, i.e. host `*`
7. Create an API key for with **Edit** (read/write) access to your buckets under "Manage API Tokens" and "Create API Token". Note down it's ID and secret.
![](docs/r2token.png)
Now the Cloudflare setup is finished and we can continue to setting up the docker container that transfers the stream data to the bucket.
The directory in the S3/R2 bucket will be created based on the stream key. It is recommended to *change the stream key* for each stream. This prevents issues with some video files being already cached.
* This upload/sync service needs to run on the same machine as SRS, since data is read from the local hard disk. This is the reason it currently runs in the same docker container.