How to convert media to HSL mpeg2-ts (.m3u8, .ts)?

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 (RTMP Media Streaming Module | NGINX) 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!

Thank you!

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 haven't tried to do any FFI in Swift/XCode, but did check some articles and seems easy to follow for a "hello world", I do get a bit scared if I have to spend the time re-learning C*, as I'm currently unemployed and this current project I've already jumped into Swift, along with other tech :) So, I thought if I'll invest some time, I'd have to stick with Rust, because I mainly work as a UI Dev with Javascript/Typescript and webassembly+rust is a thing (unfortunately, come a long way from Actionscript back in the days, then LAMP, then javascript etc).

  • 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.
Thanks!

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 (GitHub - tanersener/mobile-ffmpeg: FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.), I'll check the licenses and see if I can use the codecs etc

Thank you!

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