views:

1047

answers:

4

Hello. 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.

--Ed

A: 

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.

Niels R.
Thanks for the tip. Looks like FFmpeg uses LAME for mp3 encoding, so I'm back to square one.
Ed Lau
+3  A: 

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.

PeyloW
AudioFileWritePackets writes mp3 encoded packets which the OP does not have.
Rhythmic Fistman
Step 1) doesn't work. AudioFileCreateWithURL refuses to create an mp3 file. Maybe because mp3 packets themselves constitute a valid file.
Rhythmic Fistman
Never mind, I'm always wrong. I think my frames per packet wrong.
Rhythmic Fistman
A: 

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.

Niax
A: 

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

LarsOn