r/iOSProgramming • • 4d ago

Library SwiftExoPlayer – userspace media player for Apple platforms

https://github.com/tvrrp/SEPlayer

I’ve been working on SEPlayer, a framework for building media players with almost all playback logic running entirely in userspace. Only decoding, video rendering, and audio playback are handled by the system.

One of the main goals is extensibility. Unlike AVPlayer, thanks to Dependency Injection SEPlayer allows you to change every part of the pipeline . And implement your own demuxer, use different renderers, or replace the ABR algorithm, much like ExoPlayer.

I’ve spent two years researching and experimenting with different playback pipelines. Initially, I followed ExoPlayer’s approach, but its high-frequency timer-based pipeline isn’t particularly power-efficient.
I think I’ve finally found a better solution: an event-driven pipeline that only does work when necessary.
The project is still in alpha, and there’s a lot left to implement.

Currently supported:
Progressive MP4, fMP4, and MPEG-TS playback
HLS

Planned:
MPEG-DASH
Additional containers and formats, including Matroska, AVI, MP3, and raw AAC streams
More stability improvements, error handling, and tests

There’s still a long way to go, but I wanted to share what I’ve been working on.
I’d be interested in hearing feedback, especially from anyone who’s worked on media playback pipelines or video players.

0 Upvotes

5 comments sorted by

1

u/AlexCrypto222 4d ago
The event-driven pipeline instead of ExoPlayer's timer loop is a really interesting choice. Did you measure the power difference, e.g. with Instruments' energy log on a long HLS session?

Also curious about the software AV1 decoding you mentioned in your follow-up: would that be dav1d?
Since everything else is pure Swift and SPM, I wonder how you'd ship a C decoder like that: as an
optional trait, a prebuilt binary target, or outside the package entirely.

1

u/tvrrp 3d ago

I didn’t have an HLS implementation back then, and I don’t really remember the exact measurements I took. I also only tested with short videos.
But on an iPhone 6s, the old pipeline couldn’t keep up with six simultaneous videos playing from local storage. Now, six simultaneous HLS live streams are no problem.
I also managed to get 4.5 hours of continuous HLS live playback with a single stream on that iPhone 6s, which is great. I still need to compare it with AVPlayer, but I think the results will be pretty similar.
As for decoders, it doesn’t really matter. Just ship yours as a separate package. Maybe in the future I’ll turn that into a package trait.
You can already implement your own custom renderer and add it to the factory. In the future, I want to make AVFVideoRenderer generic over the decoder, so you’d only need to implement the requirements of a specific decoder protocol.

0

u/tvrrp 3d ago

I did two 1-hour playback runs of a BBC HLS VOD stream on an iPhone 15 Pro with 88% battery health. The total battery drain was 18%.
Sadly, I can’t attach the profiling run here, but the Power Profiler shows 9.4%/hr. Most of the work was done in the kernel, mediaplaybackd, and perfpowermetricsd.
It’s still going to be impossible to match AVPlayer’s power efficiency due to the IPC overhead of transferring media buffers to mediaplaybackd, but I think these results are pretty great.

The same stream played continuously for 4 hours on an iPhone 6s, with the battery dropping from 95% to 2%.

1

u/AlexCrypto222 3d ago

Thanks for actually measuring it! 9.4%/hr with the work sitting in mediaplaybackd rather than your process is a good sign for the pipeline itself. For a baseline, an AVPlayer run of the same BBC stream on the same phone, same brightness and network, would make the IPC cost visible as one number. Apple's own "20 hours of streamed video" is lab conditions, so it isn't really comparable.

0

u/tvrrp 4d ago

I wanted to share a bit more about why I started SEPlayer.

My main motivation was the bugs and limitations I kept running into with AVPlayer.
At the time, we were trying to build a TikTok-style short-video feed with extremely fast startup times. The problem was that AVPlayer's default buffering behavior prioritizes avoiding stalls, which makes sense for long-form content, but isn't necessarily the right trade-off for short videos.

Meanwhile, our Android team was able to implement a custom buffering strategy to prioritize faster startup. Simply because ExoPlayer gave them that level of control. On iOS, we couldn't do the same.

Even collecting basic network metrics was a challenge. For example, time to first byte (TTFB) is an incredibly useful metric for understanding CDN performance, but back then, we couldn't reliably obtain it through AVPlayer.

Many major companies, including YouTube, Meta, and TikTok, have invested in their own playback infrastructure. But there were very few public examples showing how to build a native media playback pipeline on Apple platforms.

So I started with a simple question: Is it even possible?

What APIs would I need? Could I use the system's decoders and renderers while implementing everything else myself?

After a couple of months of experimenting, I realized I was already building a video player.

Of course, there are amazing projects like VLC and FFmpeg. But I wasn't looking for another ready-made player or a collection of media-processing libraries. I wanted a framework specifically designed for building custom media playback experiences.

That's what I want SEPlayer to become.

First, a public example of how to build a media playback pipeline using Apple's native APIs. Something other developers can learn from, experiment with, and build upon.

And eventually, something like ExoPlayer, but for Apple platforms.

I want developers to have the freedom to make their own trade-offs instead of being limited to the decisions made by AVPlayer.

For example:
- Prioritize startup time over buffering for short-form content.
- Collect detailed playback and network metrics to understand how their players actually perform.
- Support custom MP4 boxes, different containers, or formats that AVPlayer doesn't support.
- Experiment with alternative decoding pipelines, such as software AV1 decoding, to reduce bandwidth usage and CDN costs.
- Replace individual components of the pipeline without having to rewrite the entire player.

Ultimately, I don't think every company should have to build its own media player from scratch just to get more control over the playback experience.

There's still a huge amount of work ahead, but that's the direction I want to take this project.

And if nothing else, I hope SEPlayer can serve as a useful reference for anyone curious about how media playback actually works under the hood on Apple platforms.