ここに m4a 形式のオーディオがあります。mp3 形式に変換する必要があります。
このために、コードを次のように使用しました
- (void) toMp3{
NSString *m4aFilePath = pathToSave;
NSString *mp3FileName = [NSString stringWithFormat:@"Audio%d",[audioArr count]];
mp3FileName = [mp3FileName stringByAppendingString:@".mp3"];
pathToSave = [NSString stringWithFormat:@"%@/%@", DOCUMENTS_FOLDER, mp3FileName];
NSLog(@"pathToSave :%@",pathToSave);
@try {
int read, write;
FILE *pcm = fopen([cafFilePath cStringUsingEncoding:1], "rb"); //source
fseek(pcm, 4*1024, SEEK_CUR); //skip file header
FILE *mp3 = fopen([pathToSave cStringUsingEncoding:1], "wb"); //output
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);
}
@catch (NSException *exception) {
NSLog(@"%@",[exception description]);
}
@finally {
[self performSelectorOnMainThread:@selector(convertMp3Finish)
withObject:nil
waitUntilDone:YES];
}
}
どうすればm4aからmp3形式に変換できますか.親切に助けてください