- int read, write;
- FILE *pcm = fopen("/Users/liuchan_xin/Desktop/音视频播放与保存例子/ipcamera.wav", "rb");
- FILE *mp3 = fopen("/Users/liuchan_xin/Desktop/file.mp3", "wb");
- int PCM_SIZE = 640;
- int MP3_SIZE = 8192;
- short int pcm_buffer[PCM_SIZE];
- unsigned char mp3_buffer[MP3_SIZE];
- lame_t lame = lame_init();
- lame_set_num_channels(lame,1);
- lame_set_in_samplerate(lame,8000);
- lame_set_brate(lame,8);
- lame_set_mode(lame,3);
- lame_set_quality(lame,2); /* 2=high 5 = medium 7=low */
- lame_init_params(lame);
- do {
- read = fread(pcm_buffer, sizeof(short int), PCM_SIZE, pcm);
- if (read == 0)
- write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);
- else
- {
- write = lame_encode_buffer(lame,
- pcm_buffer, NULL,
- read,mp3_buffer,MP3_SIZE);
- }
- fwrite(mp3_buffer, write, 1, mp3);
- } while (read != 0);
- NSLog(@"save success");
- lame_close(lame);
- fclose(mp3);
- fclose(pcm);
wav文件转mp3 单通道
最新推荐文章于 2023-07-10 15:34:53 发布