如何将 caf 转换为 mp3/amr? [英] How to convert caf to mp3/amr?
问题描述
有没有办法将 iphone 记录的 .caf 文件转换为 .mp3 或 amr 文件?因为caf文件需要上传,服务器部分不能使用这种格式.我不熟悉音频处理.这是我的结论:
Is there a way to convert the iphone record .caf files to .mp3 or amr files? Because the caf file need to upload, and server part can't use this format. I am not familiar with audio processing. Here is my conclude :
iphone sdk 没有直接的 api 来执行此操作.我们只能改变编码格式(AAC、IMA、iLBC、ALAC),参见ACAudioFileConvert Demo.但它仍然是一个caf文件,我想知道我是否可以通过这个转换为mp3.
The iphone sdk don't have a direct api to do this. We can only change the encoding format (AAC, IMA, iLBC, ALAC), see ACAudioFileConvert Demo. But it's still a caf file, I want to know if I can convert to mp3 by this.
有些人建议使用 "LAME" api.有人成功在ios中使用它吗?谁能分享一个简单的演示?有人说这可能会导致许可证问题?
Some guys suggest to use "LAME" api. Is anyone successful to use it in ios? Can anyone share a simple demo ? Someone said it may cause a licence issue ?
谁能给我一些建议?真诚感谢!!!
Can anyone give me any advice ? Sincere thanks!!!
推荐答案
很简单:int读,写;
It's quite simple: int read, write;
FILE *pcm = fopen("file.caf", "rb");
FILE *mp3 = fopen("file.mp3", "wb");
const int PCM_SIZE = 8192;
const int MP3_SIZE = 8192;
short int pcm_buffer[PCM_SIZE*2];
unsigned char mp3_buffer[MP3_SIZE];
lame_t lame = lame_init();
lame_set_in_samplerate(lame, 44100);
lame_set_VBR(lame, vbr_default);
lame_init_params(lame);
do {
read = fread(pcm_buffer, 2*sizeof(short int), PCM_SIZE, pcm);
if (read == 0)
write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);
else
write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE);
fwrite(mp3_buffer, write, 1, mp3);
} while (read != 0);
lame_close(lame);
fclose(mp3);
fclose(pcm);
这篇关于如何将 caf 转换为 mp3/amr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!