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
-
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.
Ed Lau : Thanks for the tip. Looks like FFmpeg uses LAME for mp3 encoding, so I'm back to square one. -
What you are looking for is Audio Toolbox. Part of Core Audio, not a framework for beginners, so be warned.
A three stage rocket:
- Create an audio file with MPEG Layer3 format, use the
AudioFileCreateWithURLfunction. - Obtaining the source, you have that one so no prob.
- Write data,
AudioFileWritePacketsis 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.
Rhythmic Fistman : 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. - Create an audio file with MPEG Layer3 format, use the
-
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.
-
You may want to have a look at the quicktime encoding librearies provided by Apple.
0 comments:
Post a Comment