We would like to support serving Ogg Opus on as many phones as reasonably possible.
Based on Wikipedia and our experimentation, we have found:
- Android 5.0+ supports Ogg Opus in Matroska (.mkv,.mka) or WebM (.webm) container format
- Android 7.0+ supports Ogg Opus in Ogg (.ogg) container format (with .opus as an alias)
- Android 10+ supports Ogg Opus in Ogg (.opus) container format
- iOS 11+ supports Ogg Opus in Core Audio Format (.caf) container format
Android documentation states that .ogg and .mkv is supported from 5.0+, but experimentation proves otherwise.
We would like to use AWS S3 to store the audio in some base format (like .mkv) which would be served nativity to Android. For requests from iOS, we would like to redirect those to the AWS Lambda function that would take the base format and repackage the audio stream into the .caf container format. It shouldn't need any transcoding since the codec (Ogg Opus) is the same in both cases.
Any suggestions on how implement an AWS Lambda? We would prefer to use Python, but open to using the other supported languages.
Update:
- I was looking at Pydub based on finding this article: Simple Audio Processing in Python With Pydub, but directly using ffmpeg might be better for this.
- The conversion is simple enough to use
ffmpegandopusenc(from opus-tools) so the .webm file will be store in S3.
ffmpeg -i foo.mp3 foo.wav
opusenc --bitrate 16 --hard-cbr foo.wav foo.opus
ffmpeg -i foo.opus -acodec copy -f webm foo.webm
- The conversion from .webm to .caf can easily be done by ffmpeg as well.
ffmpeg -i foo.webm -acodec copy -f caf foo.caf
- I have found a ffmpeg layer for AWS Lambda.
So the question is: how to setup a Lambda that either returns the .webm file stored in S3 or does this conversion via the lambda layer? Should the returned format be based on http headers (i.e. ACCEPT) or file extension?