A basic audio player that demonstrates the use of ffmpeg together with AVAudioEngine ... written in Swift.
- Demuxing an audio file into streams - audio and image (cover art).
- Reading packets from an audio stream, and using a codec to decode the packets into PCM samples.
- Extracting metadata (artist/album, cover art, etc).
- Converting between different PCM sample formats (resampling).
- Constructing audio buffers with the PCM samples, and scheduling them for playback.
- Upmixing/downmixing from mono/surround audio to stereo.
- Seeking within a stream - by frame or byte position.
- Building a packet table when no duration or bit rate info is available, to compute duration and enable seeking.
To help anyone who wants to get started with ffmpeg / AVAudioEngine but is having a hard time finding (or making sense of) documentation, tutorials, or concrete implementations out there. Take this project as a starting point or quick start guide, if nothing else.
I myself am still learning audio programming and ffmpeg, so I am simply passing on some of what I have learned.
Tip - To get the most out of this project, I recommend that you follow targodan's tutorial as you play with my demo app.
-
targodan's ffmpeg decoding guide. Related code sample here. This tutorial is, hands down, the best one out there!
-
A detailed tutorial on the basics of ffmpeg by leandromoreira.
-
An outdated but pretty detailed ffmpeg tutorial that others have recommended.
-
A brief tutorial Ebook on ffmpeg decoding, in PDF format.
-
rollmind's Swift/ffmpeg demo app (somewhat outdated, but still helpful)
-
Another Swift player implementation by rollmind
-
Sunlubo's Swift wrapper for ffmpeg
-
For a more full-fledged ffmpeg and AVAudioEngine setup, I point you to my other (far bigger) project: Aural Player
-
A Swift ffmpeg wrapper library (that I'm not sure I understand but it should be mentioned).