First of all, thank you so much for clicking. I'm considering the option to convert some files client-side, if possible! I'd like to convert audio to HLS deliverable files mpeg2-ts (.m3u8, .ts), are there any libraries available to Swift at all?
I'm working on an audio application that will require the playback of shared audiophiles, static audio files by the users. I spent some time looking around and see what other streaming apps do and it seems widely adopted and accepted to use the HLS Streaming protocol!
"The HLS protocol chops up MP4 video content into short (10-second) chunks with the .ts file extension (MPEG2 Transport Stream). Next, an HTTP server stores those streams, and HTTP delivers these short clips to viewers on their devices. (HLS will play video encoded with the H.264 or HEVC/H.265 codecs.)" ( https://www.dacast.com/blog/hls-streaming-protocol/ )
Seems great in principle, especially considering server cost, given the file being split into chunks. I'd assume adding a CDN on top of it.
I've found some service providers that provide the whole process from encoding to distribution but might get quite costly (Mux). Alternatively running my own NGINX RTMP (https://www.nginx.com/products/nginx/modules/rtmp-media-streaming/) server seems like a good option.
Encoding the files server-side is an option, but having to queue and having to deal with concurrency server-side is something I'd like to avoid if I find a way to encode it client-side.
While I haven't spent much time yet solving this, I started researching to validate my requirements and goals.
Would appreciate any hints or suggestions!
I don’t have any particular library, but I’d like to suggest that you also expand your search into C & ObjC libraries. I got a few audio encoding parts done that way.
@Lantua thank you so much for looking, you're always helping out!
Ok, I'm going to have a look now!
- I did purchase the C programming and also the understanding and using C pointers last week, just in case
You might consider FFmpeg. It’s an app but you can call it from another app to do a wide variety of tasks, including streaming, It is free to use, and is used by other apps, much like a plugin.
Yeh sure @JohnBlackburne, was mainly checking options for client-side processing.
Wait, maybe I got this wrong. You can use FFmpeg, as a library? I use it as a CLI, and for this particular case would be useful only if doing server-side processing.
@JohnBlackburne ok, thanks! did find a mobile-ffpmeg port (https://github.com/tanersener/mobile-ffmpeg), I'll check the licenses and see if I can use the codecs etc
Can’t say for every case, but insofar for me, importing C libraries has been more about figuring out how the imported functions/objects look (Apple’s Using imported C functions in Swift), and the api contract (
createFoo(...) must be paired with
destroyFoo(...)), rather than the nitty gritty of C itself.
If the api’s shape is not to satisfactory, you can even wrap it in another C function, better yet, another Swift function. You probably don’t need more than rudimentary C in most cases (well, if you consider pointer gymnastic rudimentary).
There are some functions that can’t be imported to Swift. In which case, you might need to wrap it in another function that Swift can palate.
I think that’s about as complex as interop goes, especially in cases like this where you do it data-in-data-out style.
Thank you! Appreciate it @Lantua