Take the 2-minute tour ×

I'm looking for a way to encode an mp3 file on the iPhone. I'm writing an app that records an audio clip with the microphone and uploads it to a server. The iPhone SDK has APIs to write out .caf and .aiff, but I didn't find any support for mp3. Since I'm uploading to a server, these uncompressed formats are way too big--hence my interest in mp3.

I took a look at the open source LAME library which is available for Mac OS X. It almost built, but I ran into a link error that baffled me. Does anyone have experience with LAME on OS X? And if so, how hard would it be to adapt it for use on the iPhone?

I just discovered an iPhone app called AudioBoo that records in mp3, so I know it can be done!

Thanks in advance for any leads.


share|improve this question
What's your link error? LAME has been ported to OSX (see macports), so in theory this should work OK unless the iphone subset of OSX doesn't have some of the dependencies. –  frankodwyer Jun 18 '09 at 16:37
Provide us with a build log and maybe we can help you out... I've built FFmpeg several times on Linux and Windows (using Cygwin/MSYS/mingw). –  Niels R. Jun 20 '09 at 19:11
Are you sure AudioBoo doesn't upload the audio to a server? LAME on the iPhone is going to be pretty slow, isn't it? –  Ben Gotow Jun 21 '09 at 14:04
Slightly off topic but I think worth mentioning: if you do your own MP3 encoding you might need to buy a licence/pay royalties. Could you use Ogg Vorbis or something similar instead? –  Stephen Darlington Aug 5 '09 at 13:21
Adding to the chorus: a build log containing at least the failure message is likely required before anyone can help you. –  Steve Madsen Aug 21 '09 at 21:33

6 Answers 6

I guess the linking error happens because of the architecture static library of LAME is not compatible with iphone arm architecture. BUT there is a solution for this... all you have to do is use a simple shell script to build the correct static library for iphone... visit this link for more information...


and FYI do not forget to change the iOS version in the shell script to 4.2 (latest IOS version) then you can use this to build for device or simulator static library...

Edit: I have just attempted to build the static library for LAME and confirmed that it 'works' at least without the frontend command line available for you but i am prettry sure you only use the library anyway.... here is the catch: use this command line to build LAME

./build_for_iphone.sh device --disable-frontend

and it will generate the static library for iphone device. If you still have any problem I can just send the prebuilt static library to you..

share|improve this answer

Beware with using LAME - LAME's GPL-licensed, so its use is only legal if your app is also GPL.

From the 3Gs onwards, hardware-assisted MP4 encoding's available. Check out the iPhoneExtAudioFileConvertTest sample project.

share|improve this answer
Nope, it's licensed under the LGPL. Huge difference. –  houbysoft May 29 '12 at 1:24
No difference on iOS: App Store apps aren't allowed to load dylibs. –  davehayden Jun 10 '12 at 5:58
@davehayden: LGPL does not require dylibs, so it's not that relevant if Apple allows them or not. You can link it statically. Admitted, you then have the hassle that you need to publish your app as precompiled object code to comply with the LGPL. All safe and OK for a commercial closed source project, but additional work. –  Daniel S. Jan 21 at 16:12
Yep, you're right! I'd thought LGPL specifically called out static/dynamic linking, but it just says the end user must be able to modify the code in the library. But providing a .a archive for your app still requires the user to have a $99 developer certificate or a jailbroken device to actually run the app. I'm not totally convinced the FSF would say that counts.. –  davehayden Jan 27 at 22:15

I think you might dig into FFmpeg wich contains the libavcodec library.

FFmpeg is widely used by a lot of encoders/mediaplayers and is fully open source.

FFmpeg is pure C, so you can use the libraries in Objective-C.

share|improve this answer
Thanks for the tip. Looks like FFmpeg uses LAME for mp3 encoding, so I'm back to square one. –  Ed Lau Jun 18 '09 at 5:01

What you are looking for is Audio Toolbox. Part of Core Audio, not a framework for beginners, so be warned.

A three stage rocket:

  1. Create an audio file with MPEG Layer3 format, use the AudioFileCreateWithURL function.
  2. Obtaining the source, you have that one so no prob.
  3. Write data, AudioFileWritePackets is your friend.

Search for the function names in the documentation, and you should find what you need. Hope I have pointed you in the right direction.

share|improve this answer
AudioFileWritePackets writes mp3 encoded packets which the OP does not have. –  Rhythmic Fistman Apr 18 '10 at 0:02
Step 1) doesn't work. AudioFileCreateWithURL refuses to create an mp3 file. Maybe because mp3 packets themselves constitute a valid file. –  Rhythmic Fistman Apr 24 '10 at 17:44
Never mind, I'm always wrong. I think my frames per packet wrong. –  Rhythmic Fistman Apr 24 '10 at 18:19
"Core Audio can read, but not write, MP3 files." — Apple. Direct from the source: developer.apple.com/library/ios/#documentation/MusicAudio/… –  coneybeare Nov 21 '10 at 4:14

To use LAME in your app you should build it from source as the Mac OS binary would not be compatible with the ARM processor inside the iPhone.

However I would recommend the use of Audio Framework as others have mentioned instead of LAME as it's something that comes out of the box and should work without much fiddling.

share|improve this answer

You may want to have a look at the quicktime encoding librearies provided by Apple.

share|improve this answer

Your Answer


