There are 3 main ways to store videos on [[AWS CloudFront|CloudFront]], discussed in following sections.
## As a standalone file (e.g. mp4)
This is easiest to implement. Downsides:
- Client user has to download whole file before playing
- AWS data transfer bill gets charged for full download even if not watched
## On-demand streaming
This is best practice as it uses only bandwidth for what is watched. Also only get charged for what's downloaded. Drawback is that it's more difficult to implement as it requires preprocessing of the source video file. From the AWS docs:
> You will need to do a little more work in order to implement the second option. First, you use MediaConvert to convert your video files to HLS format (the most widely supported streaming protocol). This will split the video into short segments and will also create a manifest file. Then, you point the CloudFront distribution at the manifest. Finally, to play the live stream, embed the manifest URL in the players that your users will play your live stream with. For example, to play a live stream for which the manifest file is myStream/playlist.m3u8 and the CloudFront distribution is d111111abcdef8.cloudfront.net, you embed the following URL in players: http://d111111abcdef8.cloudfront.net/myStream/playlist.m3u8
More details on implementing Video on Demand is [here](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/on-demand-video.html).
In summary:
1. Upload source mp4 file to S3
2. Run an [[AWS MediaConvert]] job to convert the file to streaming format and generate a manifest file (all output files are also stored in S3)
3. Point Cloudfront distro at S3 bucket
4. (optional) Update DynamoDB record with CloudFront URL of manifest file.
## Live streaming
See [AWS docs](https://aws.amazon.com/cloudfront/streaming/) for more info.
---
## References
- [Streaming video (AWS official docs)](https://aws.amazon.com/cloudfront/streaming/)